struct File { }Methods
Open a file. mode: "r", "w", "a", "rb", "wb", etc. Returns a file handle, or null on failure.
Close a file handle opened by File::open. Returns 0 on success.
close(), ignoring the result
Read at most buf.len bytes into buf. Returns bytes actually read (0 = EOF), or -1 when an error stopped it before any byte was read.
Read a single character. Returns -1 on EOF/error.
Read a line (up to buf.len-1 characters) into buf, NUL-terminated. Returns buf, or null at EOF/error (or when buf is empty).
Write buf. Returns bytes actually written (fewer than buf.len on an error part-way), or -1 when an error stopped it before any byte.
Write a single character. Returns c on success, -1 on error.
Write a string (no newline). Returns non-negative on success.
Seek to byte offset from whence (0=SEEK_SET, 1=SEEK_CUR, 2=SEEK_END).
Return current file position, or -1 on error.
Rewind to start of file.
Return non-zero if the last operation hit EOF.
Return non-zero if the file has an error indicator set.
Flush buffered writes. Returns 0 on success.
Return the size of the file in bytes, or -1 on error. (Seeks to end, reads position, seeks back.)
Appends the whole contents of the file at 'path' to 'out' (binary; 'out' stays NUL-terminated). 1 on success, 0 if it can't be opened or a read fails ('out' then holds whatever was read).
Creates or truncates the file at 'path' and writes 'data' to it. 1 when every byte was written and the file closed cleanly.