stat.ha (1740B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 export fn mkdev(major: u32, minor: u32) dev_t = 5 ((major: u64 & 0xFFFFF000) << 32) | 6 ((major: u64 & 0x00000FFF) << 8) | 7 ((minor: u64 & 0xFFFFFF00) << 12) | 8 (minor: u64 & 0x000000FF); 9 10 fn fstatat_statx( 11 dirfd: int, 12 path: path, 13 flags: int, 14 mask: uint, 15 statbuf: *stx, 16 ) (void | errno) = { 17 let path = kpath(path)?; 18 wrap_return(syscall5(SYS_statx, 19 dirfd: u64, path: uintptr: u64, flags: u64, 20 mask: u64, statbuf: uintptr: u64))?; 21 return; 22 }; 23 24 export fn fstatat( 25 dirfd: int, 26 path: path, 27 statbuf: *st, 28 flags: int, 29 ) (errno | void) = { 30 let path = kpath(path)?; 31 let statxbuf = stx { ... }; 32 fstatat_statx(dirfd, path, flags, STATX_BASIC_STATS, &statxbuf)?; 33 statbuf.dev = mkdev(statxbuf.dev_major, statxbuf.dev_minor); 34 statbuf.ino = statxbuf.ino; 35 statbuf.mode = statxbuf.mode; 36 statbuf.nlink = statxbuf.nlink; 37 statbuf.uid = statxbuf.uid; 38 statbuf.gid = statxbuf.gid; 39 statbuf.rdev = mkdev(statxbuf.dev_major, statxbuf.dev_minor); 40 statbuf.sz = statxbuf.sz; 41 statbuf.blksz = statxbuf.blksize; 42 statbuf.blocks = statxbuf.blocks; 43 statbuf.atime.tv_sec = statxbuf.atime.tv_sec; 44 statbuf.atime.tv_nsec = statxbuf.atime.tv_nsec: i64; 45 statbuf.mtime.tv_sec = statxbuf.mtime.tv_sec; 46 statbuf.mtime.tv_nsec = statxbuf.mtime.tv_nsec: i64; 47 statbuf.ctime.tv_sec = statxbuf.ctime.tv_sec; 48 statbuf.ctime.tv_nsec = statxbuf.ctime.tv_nsec: i64; 49 }; 50 51 export fn stat(path: path, statbuf: *st) (errno | void) = 52 fstatat(AT_FDCWD, path, statbuf, 0); 53 54 export fn fstat(fd: int, statbuf: *st) (errno | void) = 55 fstatat(fd, "", statbuf, AT_EMPTY_PATH); 56 57 export fn lstat(path: path, statbuf: *st) (errno | void) = 58 fstatat(AT_FDCWD, path, statbuf, AT_SYMLINK_NOFOLLOW);