19#error "port/posix is host-only and must never be compiled or linked into target firmware."
34typedef enum : uint32_t {
62 if (error_number == 0) {
65 if (error_number == EAGAIN
66#
if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
67 || error_number == EWOULDBLOCK
72 if (error_number == EBADF) {
75 if (error_number == ENOSPC || error_number == EDQUOT) {
78 if (error_number == EACCES || error_number == EPERM) {
81 if (error_number == EFBIG || error_number == EOVERFLOW) {
84 if (error_number == EINVAL) {
87 if (error_number == EPIPE || error_number == EIO) {
120 const uint8_t* bytes,
123 uint32_t* interrupts,
125 void* writer_context)
127 int error_number = 0;
128 const int64_t result = writer(writer_context, fd, &bytes[*done], length - *done, &error_number);
130 if (error_number == EINTR) {
139 if ((result == 0) || ((uint64_t)result > (uint64_t)(length - *done))) {
142 *done += (uint32_t)result;
147 const uint8_t* bytes,
149 uint32_t* out_written,
151 void* writer_context)
153 if ((bytes ==
nullptr) || (out_written ==
nullptr) || (writer ==
nullptr)) {
158 uint32_t interrupts = 0U;
160 while (done < length) {
201 const ssize_t result =
write(fd, bytes, (
size_t)length);
202 *out_errno = (result < 0) ? errno : 0;
203 return (int64_t)result;
251 if ((stream ==
nullptr) || (state ==
nullptr)) {
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_LOOP_BOUND(ceiling)
NASA Power-of-10 Rule 2: bind ONE loop to a compile-time ceiling.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_retry_limit
Retry budget exhausted – operation still failing after all attempts.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_would_block
Non-blocking operation would have blocked.
@ k_ra8_fail
Generic unspecified failure.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_access_denied
Operation refused because the target is protected against it.
@ k_ra8_err_protocol_error
Protocol-level error (e.g.
@ k_ra8_err_comm_error
Generic communication error (use a more specific code when possible).
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
static ra8_err_t internal_native_write(void *file_ctx, const void *buf, uint32_t bytes)
Write a native ra8_fs stream.
struct ra8_io_stream_iface ra8_io_stream_iface_t
Public implementer contract for ra8_io byte-stream backends.
ra8_err_t ra8_io_stream_bind(ra8_io_stream_t *stream, const ra8_io_stream_iface_t *iface, void *context)
Bind a backend vtable and caller-owned state into a stream handle.
static int64_t internal_native_write(void *context, int fd, const uint8_t *bytes, uint32_t length, int *out_errno)
Invoke the native POSIX descriptor-write primitive once.
ra8_err_t priv_ra8_io_stream_posix_write_loop(int fd, const uint8_t *bytes, uint32_t length, uint32_t *out_written, ra8_io_stream_posix_write_fn_t writer, void *writer_context)
Complete one descriptor write through an injected raw primitive.
static ra8_err_t internal_write_loop_step(int fd, const uint8_t *bytes, uint32_t length, uint32_t *done, uint32_t *interrupts, ra8_io_stream_posix_write_fn_t writer, void *writer_context)
Perform one write attempt within the bounded retry loop.
ra8_io_stream_posix_const_t
POSIX descriptor-write retry limits.
@ k_posix_write_interrupt_limit
Maximum interrupted attempts.
ra8_err_t ra8_io_stream_posix_init(ra8_io_stream_t *stream, ra8_io_stream_posix_state_t *state, int fd)
Bind a borrowed writable descriptor as a byte-stream sink.
static const ra8_io_stream_iface_t s_posix_stream_iface
Immutable borrowed-descriptor stream backend.
static ra8_err_t internal_map_errno(int error_number)
Map one descriptor-write errno value to the canonical vocabulary.
static ra8_err_t internal_posix_write(void *context, const uint8_t *bytes, uint32_t length, uint32_t *out_written)
Stream-backend callback for one borrowed POSIX descriptor.
Borrowed raw-descriptor backend for the portable byte-stream facade.
Private exact-write engine for the POSIX stream adapter.
int64_t(* ra8_io_stream_posix_write_fn_t)(void *context, int fd, const uint8_t *bytes, uint32_t length, int *out_errno)
Injected descriptor-write primitive used by the exact-write loop.
Caller-owned state retained by one POSIX stream binding.
int fd
Borrowed writable descriptor; never closed by the adapter.
Caller-allocated byte-stream handle binding a sink to its context.