15#define _POSIX_C_SOURCE (200809L)
36#define O_DIRECTORY (0)
45typedef enum : uint32_t {
54 if (text ==
nullptr) {
58 const size_t length =
strlen(text);
59 while (offset < length) {
60 const ssize_t put =
write(STDERR_FILENO, &text[offset], length - offset);
61 if (put < 0 && errno == EINTR) {
67 offset += (size_t)put;
92 }
while (value != 0U);
93 for (
size_t i = 0U; i < digits; ++i) {
94 out[i] = reverse[digits - i - 1U];
127 if (offset > (uint64_t)INT64_MAX || length > ((uint64_t)INT64_MAX - offset)) {
131 while (done < length) {
132 size_t request = length - done;
133 if (request > (
size_t)SSIZE_MAX) {
134 request = (size_t)SSIZE_MAX;
136 const ssize_t put = pwrite(fd, &bytes[done], request, (off_t)(offset + done));
137 if (put < 0 && errno == EINTR) {
168 const size_t length =
strlen(path);
172 size_t slash = length;
173 while (slash > 0U && path[slash - 1U] !=
'/') {
176 const size_t leaf_bytes = length - slash;
180 (void)
memcpy(leaf, &path[slash], leaf_bytes);
181 leaf[leaf_bytes] =
'\0';
182 if (
strcmp(leaf,
".") == 0 ||
strcmp(leaf,
"..") == 0) {
186 (void)
memcpy(parent,
".", 2U);
187 }
else if (slash == 1U) {
188 (void)
memcpy(parent,
"/", 2U);
190 (void)
memcpy(parent, path, slash - 1U);
191 parent[slash - 1U] =
'\0';
215 static const char s_prefix[] =
".reader_vmem.tmp.";
217 size_t offset =
sizeof(
s_prefix) - 1U;
219 const uint64_t values[2] = {process, attempt};
220 for (
size_t field = 0U; field < 2U; ++field) {
225 (void)
memcpy(&out[offset], number, digits);
227 out[offset++] = (field == 0U) ?
'.' :
'\0';
234 if (path ==
nullptr || trace ==
nullptr) {
237 *trace = (
rv_trace_t){.directory_fd = -1, .trace_fd = -1};
254 if (trace->
trace_fd >= 0 || errno != EEXIST) {
270 line[length++] =
' ';
273 (void)
memcpy(&line[length], number, frame_digits);
274 length += frame_digits;
275 line[length++] =
'\n';
278 if (trace !=
nullptr) {
293 const bool file_synced = fsync(trace->
trace_fd) == 0;
294 const bool file_closed = close(trace->
trace_fd) == 0;
296 if (!file_synced || !file_closed) {
314 if (trace ==
nullptr) {
#define O_DIRECTORY
No-op directory-open fallback for hosts lacking the flag.
static bool internal_pwrite_exact(int fd, uint64_t offset, const uint8_t *bytes, size_t length)
Write an exact positioned range to a regular descriptor.
#define O_NOFOLLOW
Zero fallback paired with explicit no-follow metadata validation.
#define O_CLOEXEC
Zero fallback when the host lacks close-on-exec open flags.
host_limit_t
Fixed I/O, naming, and formatting bounds.
@ k_host_temp_attempts
Exclusive-create retry bound.
@ k_host_decimal_base
Decimal conversion radix.
@ k_host_decimal_digits
Maximum uint64_t digits.
@ k_host_create_mode
Hosted output creation mode.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
int renameat(int old_dir_fd, const char *old_path, int new_dir_fd, const char *new_path)
Rename one directory-relative path to another atomically.
int strcmp(const char *s1, const char *s2)
Compare two null-terminated strings.
size_t strlen(const char *s)
Calculate string length.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
static const uint8_t s_prefix[k_ra8_net_provision_prefix_bytes]
Exact protocol prefix, including the first field separator.
static RA8_INTERNAL size_t internal_decimal(uint64_t value, char out[k_host_decimal_digits+1U])
Encode one unsigned value into a caller's fixed buffer.
bool priv_rv_trace_reference(rv_trace_t *trace, uint32_t object_id, uint32_t frame)
Append one exact object/frame reference to a trace transaction.
void priv_rv_diag_u64(uint64_t value)
Write one unsigned decimal diagnostic without stdio.
static RA8_INTERNAL bool internal_split_path(const char *path, char parent[k_rv_host_path_cap], char leaf[k_rv_host_name_cap])
Split a bounded output path into parent and leaf.
void priv_rv_diag(const char *text)
Write one best-effort diagnostic fragment to standard error.
static RA8_INTERNAL bool internal_temp_name(char out[k_rv_host_name_cap], uint64_t process, uint32_t attempt)
Build one hidden sibling-temporary leaf.
bool priv_rv_trace_begin(const char *path, rv_trace_t *trace)
Begin one unpublished same-directory trace transaction.
static RA8_INTERNAL bool internal_pwrite_exact(int fd, uint64_t offset, const uint8_t *bytes, size_t length)
Write an exact positioned byte range.
void priv_rv_trace_abort(rv_trace_t *trace)
Close and unlink an unpublished trace.
bool priv_rv_trace_commit(rv_trace_t *trace)
Durably and atomically publish a complete trace.
Private host sink and caller-owned workspace contracts for reader_vmem.
@ k_rv_host_path_cap
Hosted path capacity.
@ k_rv_host_name_cap
Hosted leaf capacity.
Caller-owned atomic trace-publication state.
int trace_fd
Temporary trace handle.
int directory_fd
Parent directory handle.
char temp_name[k_rv_host_name_cap]
Temporary leaf.
bool temp_exists
Temp cleanup guard.
bool io_failed
Sticky exact-I/O fault.
char final_name[k_rv_host_name_cap]
Destination leaf.
uint64_t offset
Next trace byte offset.