ww: enforce internal package visibility

This commit is contained in:
2026-08-13 15:37:51 +09:00
parent af0f56dfe5
commit 9a5dbac84f
4 changed files with 378 additions and 25 deletions

View File

@@ -46,6 +46,7 @@ type nr = enum i64 {
RMDIR = 84,
UNLINK = 87,
SYMLINK = 88,
READLINK = 89,
SETPGID = 109,
GETDENTS64 = 217,
NEWFSTATAT = 262,
@@ -132,7 +133,7 @@ export def SFD_NONBLOCK: i32 = O_NONBLOCK;
export def SFD_CLOEXEC: i32 = O_CLOEXEC;
fn kpath(p: str) *u8 = {
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
if (p.len + 1 > PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
let i: i32 = 0;
for (i < p.len) { pathbuf[i] = p[i]; i += 1; };
pathbuf[p.len] = 0u8;
@@ -347,7 +348,7 @@ export fn rmdir(path: str) i32 = {
export fn rename(oldpath: str, newpath: str) i32 = {
let p: *u8 = kpath(oldpath);
if (p == nil: *u8) { return -36i32; };
if (newpath.len + 1 >= PATH_MAX) { return -36i32; };
if (newpath.len + 1 > PATH_MAX) { return -36i32; };
let i: i32 = 0;
for (i < newpath.len) { pathbuf2[i] = newpath[i]; i += 1; };
pathbuf2[newpath.len] = 0u8;
@@ -364,13 +365,21 @@ export fn rename(oldpath: str, newpath: str) i32 = {
export fn symlink(target: str, path: str) i32 = {
let p: *u8 = kpath(target);
if (p == nil: *u8) { return -36i32; };
if (path.len + 1 >= PATH_MAX) { return -36i32; };
if (path.len + 1 > PATH_MAX) { return -36i32; };
let i: i32 = 0;
for (i < path.len) { pathbuf2[i] = path[i]; i += 1; };
pathbuf2[path.len] = 0u8;
return syscall2(nr.SYMLINK, p: i64, (&pathbuf2[0]): i64): i32;
};
// readlink — read a symlink target without appending NUL. The caller owns the
// buffer and uses the returned byte count, matching readlink(2).
export fn readlink(path: str, buf: *u8, n: u64) i64 = {
let p: *u8 = kpath(path);
if (p == nil: *u8) { return -36i64; };
return syscall3(nr.READLINK, p: i64, buf: i64, n: i64);
};
// mkdirs — recursive mkdir. Creates `path` and any non-existent
// parent directories with the given mode. EEXIST is silently
// accepted (matches Hare's `errors::exists` skip in os::mkdirs);