wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
fio.h File Reference

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.

Detailed Description

Whole-file read via raw Linux syscalls (openat/read/close).

No libc.

Macro Definition Documentation

◆ WIRED_FIO_ETOOBIG

#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.

Function Documentation

◆ wired_fio_append()

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.

Parameters
pathNUL-terminated file path, resolved relative to the cwd
databytes to append
Returns
bytes written (== data.n) on success; a negative -errno when openat/write fails

◆ wired_fio_close()

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).

Parameters
fddescriptor to close

◆ wired_fio_mkdir()

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).

Parameters
pathNUL-terminated directory path, resolved relative to the cwd
Returns
0 on success or when the path already exists; a negative -errno otherwise (e.g. a missing parent directory)

◆ wired_fio_open()

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.

Parameters
pathNUL-terminated file path, resolved relative to the cwd
Returns
an open file descriptor (>= 0) on success, a negative -errno otherwise

◆ wired_fio_pread()

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).

Parameters
fddescriptor from wired_fio_open
bufdestination buffer view
offbyte offset to read from
Returns
bytes read (0 at EOF, < buf.n only at EOF) on success; a negative -errno when the read fails

◆ wired_fio_read()

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.

Parameters
pathNUL-terminated file path, resolved relative to the cwd
bufdestination buffer view
Returns
total bytes read (>= 0) on success; a negative -errno when openat/read fails; WIRED_FIO_ETOOBIG when buf is full but the file still has unread bytes

◆ wired_fio_read_span()

wired_span wired_fio_read_span ( const char * path,
wired_mspan buf )

wired_fio_read returning the bytes read as a view into buf.

Parameters
pathNUL-terminated file path
bufdestination; the file must fit
Returns
view of the contents; n = 0 on any error (missing, too large)

◆ wired_fio_size()

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.

Parameters
pathNUL-terminated file path, resolved relative to the cwd
Returns
total byte count (>= 0) on success, a negative -errno otherwise

◆ wired_fio_write_new()

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.

Parameters
pathNUL-terminated file path, resolved relative to the cwd
databytes to write
Returns
0 on success; a negative -errno when openat/write fails