std/ffi/libc/fs
libc filesystem via the ISO C <stdio.h> FILE* API — universal
across Linux / macOS / Windows. Unlike the POSIX open + O_*
layer (whose flag values differ per OS), the stdio layer is
standardised: fopen takes a portable mode string ("rb"/"wb"/
"ab"/"r+b"…) and each platform's libc maps it to its own native
open flags internally. remove / rename are ISO C too.
All bindings use @link(symbol = …) to resolve directly against libc —
no Rust wrapper. Path / content arguments are Axle string
(marshalled as a NUL-terminated i8*); read buffers are raw ptr.
Use binary modes ("rb"/"wb"/"ab") for byte-exact I/O — text mode
would translate "\n" ↔ "\r\n" on Windows.
Reference: https://en.cppreference.com/w/c/io
Free functions
| Type | Method and description |
|---|---|
| fopen(path : string, mode : string) : ptr Open path with the libc fopen mode string ("rb"/"wb"/"ab"/"r+b"…)and return its FILE* stream, or NULL on failure. |
| fclose(stream : ptr) : i32 Flush and close the FILE* stream. Returns 0 on success, EOF on error. |
| fflush(stream : ptr) : i32 Flush buffered writes of stream to the OS. Returns 0 on success, EOF on error. |
| fread(buf : ptr, size : i64, count : i64, stream : ptr) : i64 Read up to count items of size bytes each from stream into buf. |
| fwrite(buf : ptr, size : i64, count : i64, stream : ptr) : i64 Write count items of size bytes each from buf to stream. |
| fputs(s : string, stream : ptr) : i32 Write the string s (without its terminating NUL) to stream. |
| fgetc(stream : ptr) : i32 Read one byte from stream as an unsigned value widened to i32. |
| ungetc(c : i32, stream : ptr) : i32 Push the low byte of c back onto stream so the next fgetcreturns it. At most one byte of pushback is guaranteed. |
| fputc(c : i32, stream : ptr) : i32 Write the low byte of c to stream. |
| fseek(stream : ptr, off : i64, whence : i32) : i32 Reposition stream to off bytes relative to whence( SEEK_SET / SEEK_CUR / SEEK_END). Returns 0 on success, non-zero on error. |
| ftell(stream : ptr) : i64 Current byte offset of stream from its start, or -1 on error. |
| feof(stream : ptr) : i32 Non-zero once stream's end-of-file indicator is set (after a readpast the end), 0 otherwise. |
| remove(path : string) : i32 Delete the file at path. Returns 0 on success, non-zero on error. |
| rename(old_path : string, new_path : string) : i32 Rename / move old_path to new_path. Returns 0 on success, non-zero on error. |
| SEEK_SET() : i32 fseek origin: offset measured from the start of the stream. |
| SEEK_CUR() : i32 fseek origin: offset measured from the current position. |
| SEEK_END() : i32 fseek origin: offset measured from the end of the stream. |
| EOF() : i32 fgetc / EOF sentinel. |
Method detail
#fopen
Open path with the libc fopen mode string ("rb"/"wb"/"ab"/"r+b"…)
and return its FILE* stream, or NULL on failure.
mode prefer binary ("rb"/"wb"/"ab") for byte-exact I/O.#fclose
Flush and close the FILE* stream. Returns 0 on success, EOF on error.
#fflush
Flush buffered writes of stream to the OS. Returns 0 on success, EOF on error.
#fread
Read up to count items of size bytes each from stream into buf.
< count at EOF or on error).#fwrite
Write count items of size bytes each from buf to stream.
< count on error).#fputs
Write the string s (without its terminating NUL) to stream.
EOF on error.#fgetc
Read one byte from stream as an unsigned value widened to i32.
EOF at end of stream / on error.#ungetc
Push the low byte of c back onto stream so the next fgetc
returns it. At most one byte of pushback is guaranteed.
c byte value to push back (its low 8 bits)stream open FILE* the byte is pushed back ontoEOF on error.#fputc
Write the low byte of c to stream.
EOF on error.#fseek
Reposition stream to off bytes relative to whence
(SEEK_SET / SEEK_CUR / SEEK_END). Returns 0 on success, non-zero on error.
#ftell
Current byte offset of stream from its start, or -1 on error.
#feof
Non-zero once stream's end-of-file indicator is set (after a read
past the end), 0 otherwise.
#remove
Delete the file at path. Returns 0 on success, non-zero on error.
#rename
Rename / move old_path to new_path. Returns 0 on success, non-zero on error.
#SEEK_SET
fseek origin: offset measured from the start of the stream.
#SEEK_CUR
fseek origin: offset measured from the current position.
#SEEK_END
fseek origin: offset measured from the end of the stream.
#EOF
fgetc / EOF sentinel.