Axle v0.14.1
Package

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

TypeMethod and description
ptr
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.
i32
fclose(stream : ptr) : i32 Flush and close the FILE* stream. Returns 0 on success, EOF on error.
i32
fflush(stream : ptr) : i32 Flush buffered writes of stream to the OS. Returns 0 on success, EOF on error.
i64
fread(buf : ptr, size : i64, count : i64, stream : ptr) : i64 Read up to count items of size bytes each from stream into buf.
i64
fwrite(buf : ptr, size : i64, count : i64, stream : ptr) : i64 Write count items of size bytes each from buf to stream.
i32
fputs(s : string, stream : ptr) : i32 Write the string s (without its terminating NUL) to stream.
i32
fgetc(stream : ptr) : i32 Read one byte from stream as an unsigned value widened to i32.
i32
ungetc(c : i32, stream : ptr) : i32 Push the low byte of c back onto stream so the next fgetc
returns it. At most one byte of pushback is guaranteed.
i32
fputc(c : i32, stream : ptr) : i32 Write the low byte of c to stream.
i32
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.
i64
ftell(stream : ptr) : i64 Current byte offset of stream from its start, or -1 on error.
i32
feof(stream : ptr) : i32 Non-zero once stream's end-of-file indicator is set (after a read
past the end), 0 otherwise.
i32
remove(path : string) : i32 Delete the file at path. Returns 0 on success, non-zero on error.
i32
rename(old_path : string, new_path : string) : i32 Rename / move old_path to new_path. Returns 0 on success, non-zero on error.
i32
SEEK_SET() : i32 fseek origin: offset measured from the start of the stream.
i32
SEEK_CUR() : i32 fseek origin: offset measured from the current position.
i32
SEEK_END() : i32 fseek origin: offset measured from the end of the stream.
i32
EOF() : i32 fgetc / EOF sentinel.

Method detail

#fopen

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.

Parameters
mode prefer binary ("rb"/"wb"/"ab") for byte-exact I/O.

#fclose

fclose(stream : ptr) : i32

Flush and close the FILE* stream. Returns 0 on success, EOF on error.

#fflush

fflush(stream : ptr) : i32

Flush buffered writes of stream to the OS. Returns 0 on success, EOF on error.

#fread

fread(buf : ptr, size : i64, count : i64, stream : ptr) : i64

Read up to count items of size bytes each from stream into buf.

Returns number of complete items read (< count at EOF or on error).

#fwrite

fwrite(buf : ptr, size : i64, count : i64, stream : ptr) : i64

Write count items of size bytes each from buf to stream.

Returns number of complete items written (< count on error).

#fputs

fputs(s : string, stream : ptr) : i32

Write the string s (without its terminating NUL) to stream.

Returns non-negative on success, EOF on error.

#fgetc

fgetc(stream : ptr) : i32

Read one byte from stream as an unsigned value widened to i32.

Returns the byte read, or EOF at end of stream / on error.

#ungetc

ungetc(c : i32, stream : ptr) : i32

Push the low byte of c back onto stream so the next fgetc
returns it. At most one byte of pushback is guaranteed.

Parameters
c byte value to push back (its low 8 bits)
stream open FILE* the byte is pushed back onto
Returns the byte pushed back, or EOF on error.

#fputc

fputc(c : i32, stream : ptr) : i32

Write the low byte of c to stream.

Returns the byte written, or EOF on error.

#fseek

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

ftell(stream : ptr) : i64

Current byte offset of stream from its start, or -1 on error.

#feof

feof(stream : ptr) : i32

Non-zero once stream's end-of-file indicator is set (after a read
past the end), 0 otherwise.

#remove

remove(path : string) : i32

Delete the file at path. Returns 0 on success, non-zero on error.

#rename

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

SEEK_SET() : i32

fseek origin: offset measured from the start of the stream.

#SEEK_CUR

SEEK_CUR() : i32

fseek origin: offset measured from the current position.

#SEEK_END

SEEK_END() : i32

fseek origin: offset measured from the end of the stream.

#EOF

EOF() : i32

fgetc / EOF sentinel.