From f79146abebfb35f1740cfaf119944b4d4aeb51fa Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sat, 30 May 2026 01:45:21 -0700 Subject: [PATCH] fill out more things --- sys_darwin.zig | 194 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) diff --git a/sys_darwin.zig b/sys_darwin.zig index afe9abda79c3f0ae255a7a162dcd7d332054e062..318666ea4271e20eae6f42d6ec2588ccf9719a3f 100644 --- a/sys_darwin.zig +++ b/sys_darwin.zig @@ -269,6 +269,16 @@ pub const libc = struct { pub extern fn close(fildes: c_int) c_int; pub extern fn read(fd: c_int, buf: [*]u8, count: usize) isize; pub extern fn clock_gettime(clock_id: clockid_t, tp: *struct_timespec) c_int; + pub extern fn fcntl(fd: c_int, cmd: c_int, ...) c_int; + pub extern fn mkdirat(fd: c_int, path: [*:0]const u8, mode: mode_t) c_int; + pub extern fn fstatat(fd: c_int, noalias path: [*:0]const u8, noalias buf: *struct_stat, flag: c_int) c_int; + pub extern fn getdirentries(fd: c_int, buf: [*]u8, nbytes: c_int, basep: *c_long) c_int; + pub extern fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) c_int; + pub extern fn write(fd: c_int, buf: *const anyopaque, n: usize) isize; + pub extern fn writev(fd: c_int, iovec: [*]const struct_iovec, count: c_int) isize; + pub extern fn isatty(fd: c_int) c_int; + pub extern fn lseek(fd: c_int, offset: off_t, whence: c_int) off_t; + pub extern fn getcwd(buf: [*]u8, size: usize) ?[*:0]u8; }; pub const natural_t = c_uint; @@ -297,6 +307,10 @@ pub const time_t = c_ulong; pub const struct_timespec = extern struct { sec: time_t, nsec: c_long }; pub const struct_stat = extern struct { dev: dev_t, mode: mode_t, nlink: nlink_t, ino: ino_t, uid: uid_t, gid: gid_t, rdev: dev_t, atimespec: struct_timespec, mtimespec: struct_timespec, ctimespec: struct_timespec, birthtimespec: struct_timespec, size: off_t, blocks: blkcnt_t, blksize: blksize_t, flags: u32, gen: u32, lspare: i32, qspare: [2]i64 }; pub const struct_iovec = extern struct { base: [*]u8, len: usize }; +pub const struct_dirent = extern struct { ino: u64, seekoff: u64, reclen: u16, namlen: u16, type: DT, name: [PATH_MAX]u8 }; + +pub const PATH_MAX = 1024; +pub const NAME_MAX = 255; pub const O = struct { pub const RDONLY = 0x0000; @@ -338,12 +352,147 @@ pub const CLOCK = struct { pub const THREAD_CPUTIME_ID = 16; }; +pub const AT = struct { + pub const FDCWD = -2; + pub const EACCESS = 0x0010; + pub const SYMLINK_NOFOLLOW = 0x0020; + pub const SYMLINK_FOLLOW = 0x0040; + pub const REMOVEDIR = 0x0080; + pub const REALDEV = 0x0200; + pub const FDONLY = 0x0400; + pub const SYMLINK_NOFOLLOW_ANY = 0x0800; + pub const RESOLVE_BENEATH = 0x2000; + pub const NODELETEBUSY = 0x4000; + pub const UNIQUE = 0x8000; +}; + +pub const F = struct { + pub const DUPFD = 0; + pub const GETFD = 1; + pub const SETFD = 2; + pub const GETFL = 3; + pub const SETFL = 4; + pub const GETOWN = 5; + pub const SETOWN = 6; + pub const GETLK = 7; + pub const SETLK = 8; + pub const SETLKW = 9; + pub const SETLKWTIMEOUT = 10; + pub const FLUSH_DATA = 40; + pub const CHKCLEAN = 41; + pub const PREALLOCATE = 42; + pub const SETSIZE = 43; + pub const RDADVISE = 44; + pub const RDAHEAD = 45; + pub const NOCACHE = 48; + pub const LOG2PHYS = 49; + pub const GETPATH = 50; + pub const FULLFSYNC = 51; + pub const PATHPKG_CHECK = 52; + pub const FREEZE_FS = 53; + pub const THAW_FS = 54; + pub const GLOBAL_NOCACHE = 55; + pub const ADDSIGS = 59; + pub const ADDFILESIGS = 61; + pub const NODIRECT = 62; + pub const GETPROTECTIONCLASS = 63; + pub const SETPROTECTIONCLASS = 64; + pub const LOG2PHYS_EXT = 65; + pub const GETLKPID = 66; + pub const SETBACKINGSTORE = 70; + pub const GETPATH_MTMINFO = 71; + pub const GETCODEDIR = 72; + pub const SETNOSIGPIPE = 73; + pub const GETNOSIGPIPE = 74; + pub const TRANSCODEKEY = 75; + pub const SINGLE_WRITER = 76; + pub const GETPROTECTIONLEVEL = 77; + pub const FINDSIGS = 78; + pub const ADDFILESIGS_FOR_DYLD_SIM = 83; + pub const BARRIERFSYNC = 85; + pub const OFD_SETLK = 90; + pub const OFD_SETLKW = 91; + pub const OFD_GETLK = 92; + pub const OFD_SETLKWTIMEOUT = 93; + pub const ADDFILESIGS_RETURN = 97; + pub const CHECK_LV = 98; + pub const PUNCHHOLE = 99; + pub const TRIM_ACTIVE_FILE = 100; + pub const SPECULATIVE_READ = 101; + pub const GETPATH_NOFIRMLINK = 102; + pub const ADDFILESIGS_INFO = 103; + pub const ADDFILESUPPL = 104; + pub const GETSIGSINFO = 105; + pub const SETLEASE = 106; + pub const GETLEASE = 107; + pub const TRANSFEREXTENTS = 110; + pub const ATTRIBUTION_TAG = 111; + pub const NOCACHE_EXT = 112; + pub const ADDSIGS_MAIN_BINARY = 113; +}; + +pub const DT = enum(u8) { + UNKNOWN = 0, + FIFO = 1, + CHR = 2, + DIR = 4, + BLK = 6, + REG = 8, + LNK = 10, + SOCK = 12, + WHT = 14, +}; + +pub const S = struct { + pub const IFMT = 0o170000; + pub const IFIFO = 0o010000; + pub const IFCHR = 0o020000; + pub const IFDIR = 0o040000; + pub const IFBLK = 0o060000; + pub const IFREG = 0o100000; + pub const IFLNK = 0o120000; + pub const IFSOCK = 0o140000; + pub const IFWHT = 0o160000; + pub const IRWXU = 0o000700; + pub const IRUSR = 0o000400; + pub const IWUSR = 0o000200; + pub const IXUSR = 0o000100; + pub const IRWXG = 0o000070; + pub const IRGRP = 0o000040; + pub const IWGRP = 0o000020; + pub const IXGRP = 0o000010; + pub const IRWXO = 0o000007; + pub const IROTH = 0o000004; + pub const IWOTH = 0o000002; + pub const IXOTH = 0o000001; + pub const ISUID = 0o004000; + pub const ISGID = 0o002000; + pub const ISVTX = 0o001000; + pub const ISTXT = ISVTX; + pub const IREAD = IRUSR; + pub const IWRITE = IWUSR; + pub const IEXEC = IXUSR; +}; + +pub const SEEK = struct { + pub const SET = 0; + pub const CUR = 1; + pub const END = 2; + pub const HOLE = 3; + pub const DATA = 4; +}; + pub fn openat(fd: c_int, file: [*:0]const u8, oflag: c_int) errno.Error!c_int { const rc = libc.openat(fd, file, oflag); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc >= 0); return rc; } +pub fn openat4(fd: c_int, file: [*:0]const u8, oflag: c_int, mode: mode_t) errno.Error!c_int { + const rc = libc.openat(fd, file, oflag, mode); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + return rc; +} pub fn fstat(fd: c_int) errno.Error!struct_stat { var buf: struct_stat = undefined; const rc = libc.fstat(fd, &buf); @@ -369,3 +518,48 @@ pub fn clock_gettime(clock_id: clockid_t) !struct_timespec { std.debug.assert(rc == 0); return tp; } +pub fn mkdirat(fd: c_int, path: [*:0]const u8, mode: mode_t) errno.Error!void { + const rc = libc.mkdirat(fd, path, mode); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc == 0); +} +pub fn fstatat(fd: c_int, path: [*:0]const u8, flag: c_int) errno.Error!struct_stat { + var buf: struct_stat = undefined; + const rc = libc.fstatat(fd, path, &buf, flag); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc == 0); + return buf; +} +pub fn getdirentries(fd: c_int, buf: []u8, basep: *c_long) errno.Error!c_uint { + const rc = libc.getdirentries(fd, buf.ptr, @intCast(buf.len), basep); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc >= 0); + return @intCast(rc); +} +pub fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) !void { + const rc = libc.unlinkat(fd, name, flag); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc == 0); +} +pub fn write(fd: c_int, buf: []const u8) !usize { + const rc = libc.write(fd, buf.ptr, buf.len); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc >= 0); + return @intCast(rc); +} +pub fn writev(fd: c_int, iovec: []const struct_iovec) !usize { + const rc = libc.writev(fd, iovec.ptr, @intCast(iovec.len)); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc >= 0); + return @intCast(rc); +} +pub fn lseek(fd: c_int, offset: off_t, whence: c_int) !void { + const rc = libc.lseek(fd, offset, whence); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc >= 0); +} +pub fn getcwd(buf: []u8) ![*:0]u8 { + const rc = libc.getcwd(buf.ptr, buf.len); + if (rc == null) return errno.fromInt(errno.fromLibC()); + return rc.?; +} -- 2.54.0