cmd: build local package graphs
This commit is contained in:
21
lib/os/os.ww
21
lib/os/os.ww
@@ -855,6 +855,27 @@ export fn stat(out: *filestat, path: str) (void | oserror) = {
|
||||
fillfilestat(out, &k);
|
||||
};
|
||||
|
||||
// samefile reports whether two existing paths resolve to the same kernel
|
||||
// object. It follows terminal symlinks, like stat(2), and compares both the
|
||||
// device and inode kept in the native stat record. Package loading uses this
|
||||
// narrow primitive to intern directories by identity without exposing a
|
||||
// platform-specific canonical pathname policy.
|
||||
export fn samefile(a: str, b: str) bool = {
|
||||
let ap: *u8 = kpath(a);
|
||||
if (ap == nil: *u8) { return false; };
|
||||
let ak: kstat;
|
||||
let ar: i64 = syscall4(nr.NEWFSTATAT,
|
||||
AT_FDCWD: i64, ap: i64, (&ak): i64, 0i64);
|
||||
if (ar < 0) { return false; };
|
||||
let bp: *u8 = kpath(b);
|
||||
if (bp == nil: *u8) { return false; };
|
||||
let bk: kstat;
|
||||
let br: i64 = syscall4(nr.NEWFSTATAT,
|
||||
AT_FDCWD: i64, bp: i64, (&bk): i64, 0i64);
|
||||
if (br < 0) { return false; };
|
||||
return ak.dev == bk.dev && ak.ino == bk.ino;
|
||||
};
|
||||
|
||||
// lstat — like [[stat]] but does NOT follow a terminal symlink.
|
||||
// Mirrors Hare's sys::lstat (ref/hare/sys/+linux/stat.ha:57).
|
||||
export fn lstat(out: *filestat, path: str) (void | oserror) = {
|
||||
|
||||
Reference in New Issue
Block a user