std1.0.0-beta-7 SafeC docs

std :: io_file

Struct std::File

#include <std/io_file.h> source

struct File { }

Methods

§static ?&File open(const &char path, const &char mode)source · definition

Open a file. mode: "r", "w", "a", "rb", "wb", etc. Returns a file handle, or null on failure.

§int close() consumesource · definition

Close a file handle opened by File::open. Returns 0 on success.

§void drop()source · definition

close(), ignoring the result

§long long read([]unsigned char buf)source · definition

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.

§int getc()source · definition

Read a single character. Returns -1 on EOF/error.

§?&char gets([]char buf)source · definition

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

§long long write([]const unsigned char buf)source · definition

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.

§int putc(int c)source · definition

Write a single character. Returns c on success, -1 on error.

§int puts(const &char s)source · definition

Write a string (no newline). Returns non-negative on success.

§int seek(long long offset, int whence)source · definition

Seek to byte offset from whence (0=SEEK_SET, 1=SEEK_CUR, 2=SEEK_END).

§long long tell()source · definition

Return current file position, or -1 on error.

§void rewind()source · definition

Rewind to start of file.

§int eof()source · definition

Return non-zero if the last operation hit EOF.

§int error()source · definition

Return non-zero if the file has an error indicator set.

§int flush()source · definition

Flush buffered writes. Returns 0 on success.

§long long size()source · definition

Return the size of the file in bytes, or -1 on error. (Seeks to end, reads position, seeks back.)

§static int read_to_string(const &char path, &String out)source · definition

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

§static int write_bytes(const &char path, []const unsigned char data)source · definition

Creates or truncates the file at 'path' and writes 'data' to it. 1 when every byte was written and the file closed cleanly.