lib: add temp + os.mkdir/rmdir/EXCL

temp mirrors Hare's temp: file, named, dir. file() routes through
named() and discards the path (no O_TMPFILE yet). Path randomizer
uses inline SplitMix64 seeded from getpid + O_EXCL retry (Hare uses
crypto::random which we don't ship). named() takes out-pointers for
fd + path — return shape gated on tasks #5 and #11. Caller closes
and removes; no defer in ww.

os gains mkdir, rmdir, flag.EXCL — straight ports of ref/hare/os.
selfhost combined files cascade; 995_self_rebuild byte-identity
holds.
This commit is contained in:
2026-05-13 17:18:59 +09:00
parent fda8c2f636
commit fbe0df4e68
9 changed files with 617 additions and 0 deletions

View File

@@ -36,6 +36,8 @@ type nr = enum i64 {
EXECVE = 59,
EXIT = 60,
WAIT4 = 61,
MKDIR = 83,
RMDIR = 84,
UNLINK = 87,
GETCWD = 79,
GETDENTS64 = 217,
@@ -49,6 +51,7 @@ export type flag = enum i32 {
WRONLY = 1,
RDWR = 2,
CREATE = 64, // 0x40
EXCL = 128, // 0x80 — pair with CREATE to fail on existing path
TRUNC = 512, // 0x200
};
@@ -178,6 +181,19 @@ export fn remove(path: *u8) i32 = {
return syscall1(nr.UNLINK, path: i64): i32;
};
// mkdir — mkdir(2). Path must be NUL-terminated. Mode is the unix
// permission bitset (e.g. 0o700). Returns 0 on success, negative
// errno otherwise. Hare name (os::mkdir).
export fn mkdir(path: *u8, mode: i32) i32 = {
return syscall2(nr.MKDIR, path: i64, mode: i64): i32;
};
// rmdir — rmdir(2). Path must be NUL-terminated. Returns 0 on
// success, negative errno otherwise. Hare name (os::rmdir).
export fn rmdir(path: *u8) i32 = {
return syscall1(nr.RMDIR, path: i64): i32;
};
// getpid(2). Used by the driver to mint unique scratch paths.
export fn getpid() i32 = {
return syscall0(nr.GETPID): i32;