std.fs [core] std.fs.IoErrors pub error IoErrors = {not_found, denied, io} — The row fourteen signatures below carry, named once ([type.err.alias]). std.fs.File pub struct File { fd: int, } — An open file: the host descriptor this process may read from or write to, according to how it was opened. std.fs.read_text pub fn read_text(path: str) -> str ! {not_found, denied, io, utf8} — The whole contents of the file at path, decoded as UTF-8. std.fs.write_text pub fn write_text(path: str, text: str) -> () ! IoErrors — Write text to path, replacing whatever was there and creating the file if it does not exist. std.fs.append_text pub fn append_text(path: str, text: str) -> () ! IoErrors — Append text to the end of the file at path, creating it when it is absent. std.fs.read_bytes pub fn read_bytes(path: str) -> List[byte] ! IoErrors — The whole contents of the file at path, as bytes — no decode, no utf8 row, nothing refused for being data. std.fs.write_bytes pub fn write_bytes(path: str, b: List[byte]) -> () ! {not_found, denied, invalid, io} — Write b to path as bytes, replacing whatever was there and creating the file if it does not exist. std.fs.exists pub fn exists(path: str) -> bool — Does something exist at path? std.fs.is_file pub fn is_file(path: str) -> bool — Is there a regular FILE at path? std.fs.is_dir pub fn is_dir(path: str) -> bool — Is there a DIRECTORY at path? std.fs.size pub fn size(path: str) -> int ! IoErrors — The size of the file at path, in BYTES. std.fs.modified_ms pub fn modified_ms(path: str) -> int ! IoErrors — When the file at path was last modified, in MILLISECONDS from the Unix epoch — negative before it. std.fs.remove pub fn remove(path: str) -> () ! IoErrors — Remove the file at path. std.fs.copy_file pub fn copy_file(from: str, to: str) -> () ! IoErrors — Copy the BYTES of from to to, replacing to if it exists. std.fs.move_file pub fn move_file(from: str, to: str) -> () ! IoErrors — Move the file at from to to. std.fs.read_dir pub fn read_dir(path: str) -> List[str] ! {not_found, denied, utf8, io} — The entry NAMES directly inside the directory at path, SORTED. std.fs.create_dir pub fn create_dir(path: str) -> () ! {exists, not_found, denied, io} — Create ONE directory at path. std.fs.create_dir_all pub fn create_dir_all(path: str) -> () ! {denied, io} — Create the directory at path and every missing parent of it. std.fs.remove_dir pub fn remove_dir(path: str) -> () ! IoErrors — Remove the EMPTY directory at path. std.fs.remove_dir_all pub fn remove_dir_all(path: str) -> () ! IoErrors — Remove the directory at path and EVERYTHING inside it. std.fs.open pub fn open(path: str) -> File ! IoErrors — Open the file at path for READING and return its handle. std.fs.open_append pub fn open_append(path: str) -> File ! IoErrors — Open the file at path for APPENDING and return its handle, creating the file when it is absent. std.fs.create pub fn create(path: str) -> File ! {denied, io} — Create (or truncate) the file at path for WRITING and return its handle. std.fs.create_new pub fn create_new(path: str) -> File ! {exists, not_found, denied, io} — Create a NEW file at path, open for reading and writing, and fail if anything is already there: the EXCLUSIVE create, the one atomicity every tier-1 host promises ([os.fs.open]'s mode 4). std.fs.create_new_with_mode pub fn create_new_with_mode(path: str, mode: int) -> File ! { exists, not_found, denied, invalid, unsupported, io, } — create_new, with the permission bits the file has from its first instant: mode less the process's umask (env.umask), never wider for a moment — an atomic save's temporary file with the target's bits, before it is renamed over the target. std.fs.read pub fn read(mut f: File, max: int) -> str ! {eof, io, utf8} — Read up to max bytes from f, decoded as UTF-8, advancing the file's position. std.fs.read_chunk pub fn read_chunk(mut f: File, max: int) -> List[byte] ! {eof, io} — Read up to max BYTES from f, advancing the file's position — no decode, no utf8 row, no boundary to land inside. std.fs.write pub fn write(mut f: File, text: str) -> () ! {io} — Write text to f at its current position, advancing it. std.fs.write_chunk pub fn write_chunk(mut f: File, b: List[byte]) -> () ! {invalid, io} — Write the bytes b to f at its current position, advancing it. std.fs.copy_chunk pub fn copy_chunk(mut src: File, mut dst: File, max: int) -> int ! {eof, io} — One copy the host makes: at most max bytes from src's position to dst's, both advancing, and how many moved. std.fs.close pub fn close(take f: File) -> () ! {io} — Close f, consuming it. std.fs.Stat pub struct Stat { kind: int, size: int, modified_ms: int, } — What one metadata read on an open handle answers: a kind, a size and a modification time. std.fs.fstat pub fn fstat(mut f: File) -> Stat ! IoErrors — One metadata read on the open handle f. std.fs.Info pub struct Info { kind: int, size: int, modified_ms: int, have: int, mode: int, nlink: int, uid: int, gid: int, blocks: int, dev: int, ino: int, rdev: int, atime_s: int, atime_ns: int, mtime_s: int, mtime_ns: int, ctime_s: int, ctime_ns: int, btime_s: int, btime_ns: int, } — The full stat record of one path: what ls -l shows. std.fs.stat pub fn stat(path: str) -> Info ! IoErrors — The record of path, FOLLOWING a final symbolic link: what the link names. std.fs.lstat pub fn lstat(path: str) -> Info ! IoErrors — The record of path ITSELF, a symbolic link included: a link is kind 3, its size the length of its target, its times its own. std.fs.answered pub fn answered(info: Info, word: int) -> bool — Whether the host answered word word of info (Info's table); false for a word outside 0..20. std.fs.FileSystem pub struct FileSystem { have: int, block_size: int, fragment_size: int, blocks: int, free: int, available: int, files: int, free_files: int, name_max: int, flags: int, type_number: int, id: int, } — The record of a file system, what df and stat -f print: the twelve words statfs answers, named, with have saying which of them the host answered. std.fs.file_system pub fn file_system(words: List[int]) -> FileSystem — The FileSystem of statfs's words in their order, words[0] being have. std.fs.has_answer pub fn has_answer(v: FileSystem, word: int) -> bool — Whether the host answered word word of v (FileSystem's table); false for a word outside 0..12. std.fs.statfs pub fn statfs(path: str) -> FileSystem ! IoErrors — The record of the file system that holds what path names, a final symbolic link followed: what df and stat -f print, from one host call (statfs(2); macOS adds a pathconf for name_max). std.fs.read_link pub fn read_link(path: str) -> List[byte] ! {not_found, denied, invalid, io} — The target a symbolic link stores, as the host stored it: bytes, verbatim — a name need not be UTF-8 (str_from_utf8 when it is). std.fs.realpath pub fn realpath(path: str) -> str ! {io, not_found} — s248 ([os.fs.realpath]): the canonical name of path — absolute, every symbolic link followed, every . and .. taken (a .. AFTER the link before it, so l/.. is the parent of the link's TARGET), and no trailing slash: what realpath(3) resolves. std.fs.Entry pub struct Entry { kind: int, name: List[byte], } — One directory entry: its own kind (Info's codes; a link is 3, never what it names; 2 when the host gave none) and its name's bytes. std.fs.entries pub fn entries(path: str) -> List[Entry] ! IoErrors — The entries of the directory path in the order the host keeps them — NOT sorted — without . and .., each with its own kind. std.fs.stdin pub fn stdin() -> File — The process's standard input, as a File. std.fs.stdout pub fn stdout() -> File — The process's standard output, as a File — stdin's doc in every respect, for descriptor 1. std.fs.stderr pub fn stderr() -> File — The process's standard error, as a File — stdin's doc in every respect, for descriptor 2. std.fs.seek pub fn seek(mut f: File, off: int) -> int ! {invalid, io, unseekable} — Move f's position to byte off from the START of the file, and answer it. std.fs.seek_by pub fn seek_by(mut f: File, delta: int) -> int ! {invalid, io, unseekable} — Move f's position by delta bytes from where it is, and answer the new position from the start. std.fs.seek_end pub fn seek_end(mut f: File, off: int) -> int ! {invalid, io, unseekable} — Move f's position to off bytes from the END of the file — zero is the end, negative is before it — and answer it from the start. std.fs.tell pub fn tell(mut f: File) -> int ! {io, unseekable} — f's position, from the start of the file, without moving it. std.fs.read_at pub fn read_at(mut f: File, off: int, max: int) -> List[byte] ! {eof, invalid, io, unseekable} — Up to max bytes of f starting at byte off, leaving f's own position exactly where it was. std.fs.join pub fn join(base: str, name: str) -> str — base and name joined with a single /. std.fs.parent pub fn parent(path: str) -> str ! {none} — Everything in path before its last /. std.fs.file_name pub fn file_name(path: str) -> str ! {none} — The last segment of path — everything after its last /. std.fs.set_mode pub fn set_mode(path: str, mode: int) -> () ! {not_found, denied, invalid, unsupported, io} — Set the permission bits of what is at path to exactly mode. std.fs.create_private pub fn create_private(path: str) -> File ! {exists, not_found, denied, unsupported, io} — Create a NEW file at path that only its owner can read or write, open for reading and writing. std.fs.create_with_mode pub fn create_with_mode(path: str, mode: int) -> File ! { not_found, denied, invalid, unsupported, io, } — create, with the permission bits the file gets if this call creates it: mode less the process's umask (env.umask). std.fs.create_dir_mode pub fn create_dir_mode(path: str, mode: int) -> () ! { exists, not_found, denied, invalid, unsupported, io, } — create_dir, with the directory's permission bits: mode less the process's umask. std.fs.symlink pub fn symlink(target: str, path: str) -> () ! { exists, not_found, denied, invalid, unsupported, io, } — Make path a symbolic link whose target is target, stored verbatim. std.fs.link pub fn link(existing: str, path: str) -> () ! {exists, not_found, denied, cross_device, io} — Make path a second name of the file existing names. std.fs.Time pub struct Time { s: int, ns: int, } — One time set_times writes: a moment, "now", or "leave it". std.fs.time pub fn time(s: int, ns: int) -> Time — The moment s seconds and ns nanoseconds from the Unix epoch. std.fs.time_now pub fn time_now() -> Time — "Now": the HOST's clock at the set_times call, not a clock this program read ([os.fs.times]'s -1). std.fs.time_keep pub fn time_keep() -> Time — "Leave this time as it is" ([os.fs.times]'s -2): how one time is set and the other kept, with no read in between. std.fs.set_times pub fn set_times(path: str, atime: Time, mtime: Time) -> () ! {not_found, denied, invalid, io} — Set the access time and the modification time of what is at path, following a final symbolic link. std.fs.set_link_times pub fn set_link_times(path: str, atime: Time, mtime: Time) -> () ! { not_found, denied, invalid, io, } — set_times on path ITSELF: a final symbolic link's own times, its target's left alone (touch -h). std.fs.owner_keep pub fn owner_keep() -> int — The word set_owner and its kin read as "leave this id as it is". std.fs.set_owner pub fn set_owner(path: str, uid: int, gid: int) -> () ! { not_found, denied, invalid, unsupported, io, } — Set the owner and the group of what is at path, following a final symbolic link — chown. std.fs.set_link_owner pub fn set_link_owner(path: str, uid: int, gid: int) -> () ! { not_found, denied, invalid, unsupported, io, } — set_owner on path ITSELF: a final symbolic link's own owner and group, its target's left alone (chown -h). std.fs.set_file_owner pub fn set_file_owner(mut f: File, uid: int, gid: int) -> () ! {denied, invalid, unsupported, io} — Set the owner and the group of the file behind f — fchown. std.fs.set_file_mode pub fn set_file_mode(mut f: File, mode: int) -> () ! {denied, invalid, io, unsupported} — Set the permission bits of the file behind f to exactly mode: fchmod, the handle form of set_mode. std.fs.truncate pub fn truncate(mut f: File, len: int) -> () ! {invalid, io} — Make the file behind f exactly len bytes long. std.fs.sync pub fn sync(mut f: File) -> () ! {io} — s248 ([os.fs.sync]): put f's bytes and metadata on the disk before answering — fsync(2) on linux, F_FULLFSYNC on macOS (whose fsync leaves them in the drive's cache), FlushFileBuffers on windows. std.fs.sync_dir pub fn sync_dir(path: str) -> () ! {denied, invalid, io, not_found, unsupported} — s248 ([os.fs.sync]): put the directory path's entries on the disk, so that a creation, a rename or a removal in it survives a crash — the last call of sync's atomic save. std.fs.NOFOLLOW pub const NOFOLLOW: int = 16 — The flag that makes open_mode refuse a final symbolic link ([os.fs.open.nofollow], wolf 0.2.35): bit 16, added to any of the six modes — fs.open_mode(path, 3 + fs.NOFOLLOW). std.fs.DIRECTORY pub const DIRECTORY: int = 32 — The flag that makes an open refuse anything but a directory ([os.fs.open.directory], wolf 0.2.37): bit 32, added to read mode 0 or 5 of open_mode or open_at. std.fs.open_mode pub fn open_mode(path: str, mode: int) -> File ! {not_found, denied, exists, invalid, io} — Open path in one of [os.fs.open]'s six modes, by number — the moded open the named ones above are spellings of, and the only one that reaches modes 3 and 5 and the NOFOLLOW and DIRECTORY flags: - 0 read (open), 1 write, creating and truncating (create), 2 append, creating (open_append); - 3 read and write, creating, NOT truncating — an editor's in-place save, a journal reopened; - 4 the exclusive create (create_new); - 5 read without parking: a fifo or a device with no writer answers at once, a regular file is unaffected (a static-file server's open, before fstat classifies the handle). std.fs.open_dir pub fn open_dir(path: str) -> File ! {not_found, denied, invalid, io} — A held directory: path opened read-only as a directory, a final symbolic link refused (open_mode(path, DIRECTORY + NOFOLLOW)), for the …_at calls, which look a name up in the directory the handle holds whatever its path has become. std.fs.open_dir_at pub fn open_dir_at(dir: File, name: str) -> File ! {denied, invalid, io, not_found, unsupported} — The directory name in the held directory dir, opened the way open_dir opens a path: read-only, a directory or refused, a link refused. std.fs.open_at pub fn open_at(dir: File, name: str, mode: int, perm: int) -> File ! { denied, exists, invalid, io, not_found, unsupported, } — name in the held directory dir, opened in one of open_mode's six modes with its flags, a file the call creates getting perm less the umask from its first instant: openat(2), the open relative to a directory the program holds. std.fs.stat_at pub fn stat_at(dir: File, name: str) -> Info ! {denied, invalid, io, not_found, unsupported} — The record of name in the held directory dir, a final link followed: stat's twenty words as an Info, from one host call relative to the handle (statx(2) on linux, fstatat(2) elsewhere), so the record is of the name in that directory whatever its path is by now. std.fs.lstat_at pub fn lstat_at(dir: File, name: str) -> Info ! {denied, invalid, io, not_found, unsupported} — The record of name ITSELF in the held directory dir, a link included (kind 3, its own size and times): lstat relative to the handle, the question a walk asks of each entry before it opens one. std.fs.remove_at pub fn remove_at(dir: File, name: str) -> () ! {denied, invalid, io, not_found, unsupported} — Remove the name name from the held directory dir: a file, a link (never what it names) or a fifo, remove relative to the handle. std.fs.remove_dir_at pub fn remove_dir_at(dir: File, name: str) -> () ! {denied, invalid, io, not_found, unsupported} — Remove the EMPTY directory name from the held directory dir: remove_dir relative to the handle. std.fs.create_dir_at pub fn create_dir_at(dir: File, name: str, mode: int) -> () ! { denied, exists, invalid, io, not_found, unsupported, } — Make the directory name in the held directory dir, its permission bits mode less the umask from its first instant: create_dir_mode relative to the handle, one level. std.fs.symlink_at pub fn symlink_at(target: str, dir: File, name: str) -> () ! { denied, exists, invalid, io, not_found, unsupported, } — Make name in the held directory dir a symbolic link whose target is target, stored verbatim, never resolved or checked: symlink relative to the handle, the target first as there. std.fs.link_at pub fn link_at(src_dir: File, src: str, dst_dir: File, dst: str) -> () ! { cross_device, denied, exists, invalid, io, not_found, unsupported, } — Make dst in the held directory dst_dir a second name of the file src names in the held directory src_dir, a final link in src linked ITSELF (link's rule, on every host). std.fs.link_followed_at pub fn link_followed_at(src_dir: File, src: str, dst_dir: File, dst: str) -> () ! { cross_device, denied, exists, invalid, io, not_found, unsupported, } — link_at with a final link in src FOLLOWED: the new name is a second name of what the link names (AT_SYMLINK_FOLLOW). std.fs.entries_at pub fn entries_at(mut dir: File) -> List[Entry] ! {denied, invalid, io, not_found, unsupported} — The entries of the held directory dir, in entries' shape: the host's order (not sorted), no . or .., each entry its own kind and its name's bytes, a name that is not UTF-8 listed like any other. std.fs.access pub fn access(path: str, mode: int) -> () ! {denied, invalid, io, not_found, unsupported} — s254 ([os.fs.access], wolf 0.2.35): may this process do what mode asks of path, by its REAL user and group ids — access(2), a final link followed. std.fs.fstat_record pub fn fstat_record(mut f: File) -> Info ! {io} — s254 ([os.fs.fstat.record], wolf 0.2.35; ruling asked R-sc72-1): the full record of the file f HOLDS, stat's twenty words as an Info, from one metadata read on the handle (fstat(2), statx(2) on linux) — its identity (dev, ino), link count, mode, owner and nanosecond times with no path walked between the open and the question. std.fs.LOCK_SHARED pub const LOCK_SHARED: int = 1 — lock's kind 1: a shared lock, any number of which may be held at once through different opens of one file ([os.fs.lock]). std.fs.LOCK_EXCLUSIVE pub const LOCK_EXCLUSIVE: int = 2 — lock's kind 2: an exclusive lock, which no other open of the file may hold beside it, shared or exclusive ([os.fs.lock]). std.fs.lock pub fn lock(mut f: File, kind: int) -> () ! {busy, invalid, io, unsupported} — s254 ([os.fs.lock], wolf 0.2.35): an advisory lock on the file behind f, LOCK_SHARED or LOCK_EXCLUSIVE, tried once and never waited for — a conflicting lock held through ANOTHER OPEN of the file is busy (a program polls with its own deadline; a wait in the kernel would park a worker where a kill cannot reach it). std.fs.unlock pub fn unlock(mut f: File) -> () ! {io, unsupported} — s254 ([os.fs.lock], wolf 0.2.35): release the lock f's open file holds. A handle that holds none is ok on every host. std.fs.mkfifo pub fn mkfifo(path: str, perm: int) -> () ! {denied, exists, invalid, io, not_found, unsupported} — s254 ([os.fs.mkfifo], wolf 0.2.35): make a fifo named path, mkfifo(3), its permission bits perm less the process's umask (create_dir_mode's rule). std.fs.set_nonblock pub fn set_nonblock(mut f: File, on: bool) -> () ! {invalid, io, unsupported} — s254 ([os.fs.nonblock], wolf 0.2.35): set (on) or clear the non-blocking flag on the open file behind f (O_NONBLOCK). std.fs.write_some pub fn write_some(mut f: File, b: List[byte]) -> int ! {busy, invalid, io} — s254 ([os.fs.nonblock], wolf 0.2.35): ONE write of b to f, and how many bytes the host took — all of them or a first part; at least 1 for a non-empty list, 0 for an empty one (the handle still checked). std.fs.adopt pub fn adopt(fd: int) -> File ! {invalid, io, unsupported} — s253 ([os.proc.adopt], wolf 0.2.35): a descriptor this process INHERITED, as a File that owns it — prog 5>out, a supervisor's pipe, the ready descriptor a test driver hands its child. std.fs.read_into pub fn read_into(mut f: File, mut buf: List[byte], max: int) -> int ! {eof, io} — #94: read up to max bytes from f INTO buf, whose contents become the bytes read and whose storage is kept (List.reset, then a push per byte), and answer how many — C's read(2) shape, for a loop that must not grow: an editor's key reader, a pipe pump.