|
wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
|
Whole-file read via raw Linux syscalls (openat/read/close). More...
Go to the source code of this file.
Macros | |
| #define | WIRED_FIO_ETOOBIG (-27) |
| wired_fio_read result when buf filled up but the file holds more bytes. | |
Functions | |
| ssz | wired_fio_read (const char *path, wired_mspan buf) |
| Read the whole file at path into buf. | |
| wired_span | wired_fio_read_span (const char *path, wired_mspan buf) |
| wired_fio_read returning the bytes read as a view into buf. | |
| ssz | wired_fio_append (const char *path, wired_span data) |
| Append data to the file at path, creating it (mode 0600) if it does not exist. | |
| ssz | wired_fio_open (const char *path) |
| Open path for reading (openat(AT_FDCWD, path, O_RDONLY)), leaving the descriptor open for repeated wired_fio_pread calls. | |
| ssz | wired_fio_size (const char *path) |
| The file's total size in bytes (via newfstatat's st_size), without disturbing any open descriptor's read position. | |
| ssz | wired_fio_pread (i64 fd, wired_mspan buf, u64 off) |
| Read up to buf.n bytes from fd starting at byte offset off (pread64: does not move any shared file position, so concurrent rounds over the same fd never race each other). | |
| i64 | wired_fio_mkdir (const char *path) |
| Create the directory at path (mkdirat(AT_FDCWD, path, 0755)). | |
| i64 | wired_fio_write_new (const char *path, wired_span data) |
| Replace the file at path with data. | |
| void | wired_fio_close (i64 fd) |
| Close a descriptor from wired_fio_open. | |
Whole-file read via raw Linux syscalls (openat/read/close).
No libc.
| #define WIRED_FIO_ETOOBIG (-27) |
wired_fio_read result when buf filled up but the file holds more bytes.
Chosen as -EFBIG (27) so it stays in the negative -errno result space.
| ssz wired_fio_append | ( | const char * | path, |
| wired_span | data ) |
Append data to the file at path, creating it (mode 0600) if it does not exist.
Opens with openat(AT_FDCWD, path, O_WRONLY|O_CREAT|O_APPEND, 0600), writes the whole span, and closes the descriptor. Intended for streaming output (e.g. qlog/keylog) where each call adds one record.
| path | NUL-terminated file path, resolved relative to the cwd |
| data | bytes to append |
| void wired_fio_close | ( | i64 | fd | ) |
Close a descriptor from wired_fio_open.
Idempotent misuse (already closed, negative fd) is the caller's responsibility to avoid; this simply issues close(2).
| fd | descriptor to close |
| i64 wired_fio_mkdir | ( | const char * | path | ) |
Create the directory at path (mkdirat(AT_FDCWD, path, 0755)).
A path that already exists (EEXIST) counts as success, so repeated calls are harmless. Mode 0755 keeps the directory readable by other uids (e.g. a runner outside the container inspecting the results).
| path | NUL-terminated directory path, resolved relative to the cwd |
| ssz wired_fio_open | ( | const char * | path | ) |
Open path for reading (openat(AT_FDCWD, path, O_RDONLY)), leaving the descriptor open for repeated wired_fio_pread calls.
Pairs with wired_fio_close. Intended for streaming a file too large for one buffer: the caller reads it round by round instead of via wired_fio_read's single whole-file call.
| path | NUL-terminated file path, resolved relative to the cwd |
| ssz wired_fio_pread | ( | i64 | fd, |
| wired_mspan | buf, | ||
| u64 | off ) |
Read up to buf.n bytes from fd starting at byte offset off (pread64: does not move any shared file position, so concurrent rounds over the same fd never race each other).
| fd | descriptor from wired_fio_open |
| buf | destination buffer view |
| off | byte offset to read from |
| ssz wired_fio_read | ( | const char * | path, |
| wired_mspan | buf ) |
Read the whole file at path into buf.
Opens with openat(AT_FDCWD, path, O_RDONLY), reads until end of file, and closes the descriptor.
| path | NUL-terminated file path, resolved relative to the cwd |
| buf | destination buffer view |
| wired_span wired_fio_read_span | ( | const char * | path, |
| wired_mspan | buf ) |
wired_fio_read returning the bytes read as a view into buf.
| path | NUL-terminated file path |
| buf | destination; the file must fit |
| ssz wired_fio_size | ( | const char * | path | ) |
The file's total size in bytes (via newfstatat's st_size), without disturbing any open descriptor's read position.
| path | NUL-terminated file path, resolved relative to the cwd |
| i64 wired_fio_write_new | ( | const char * | path, |
| wired_span | data ) |
Replace the file at path with data.
Opens with openat(AT_FDCWD, path, O_WRONLY|O_CREAT|O_TRUNC, 0644), writes the whole span (looping past short writes), and closes the descriptor. Any previous content is discarded. Mode 0644 keeps the file readable by other uids.
| path | NUL-terminated file path, resolved relative to the cwd |
| data | bytes to write |