mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
bsd: debitrot std.c
- follow-up to f4bf061d8a
- updated std.fs.Dir to use properly named symbols
This commit is contained in:
parent
5ce40e61c6
commit
d7cf25f5ca
4 changed files with 87 additions and 58 deletions
102
lib/std/c.zig
102
lib/std/c.zig
|
|
@ -1502,25 +1502,19 @@ pub extern "c" fn closedir(dp: *DIR) c_int;
|
||||||
pub extern "c" fn telldir(dp: *DIR) c_long;
|
pub extern "c" fn telldir(dp: *DIR) c_long;
|
||||||
pub extern "c" fn seekdir(dp: *DIR, loc: c_long) void;
|
pub extern "c" fn seekdir(dp: *DIR, loc: c_long) void;
|
||||||
|
|
||||||
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int;
|
|
||||||
pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int;
|
|
||||||
pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
|
|
||||||
pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
|
|
||||||
|
|
||||||
pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int;
|
|
||||||
|
|
||||||
pub extern "c" fn sched_yield() c_int;
|
|
||||||
|
|
||||||
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
|
|
||||||
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
|
|
||||||
pub extern "c" fn sigfillset(set: ?*c.sigset_t) void;
|
|
||||||
pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int;
|
pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int;
|
||||||
|
|
||||||
pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
|
|
||||||
|
|
||||||
pub extern "c" fn alarm(seconds: c_uint) c_uint;
|
pub extern "c" fn alarm(seconds: c_uint) c_uint;
|
||||||
|
|
||||||
pub extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
|
pub const clock_getres = switch (native_os) {
|
||||||
|
.netbsd => private.__clock_getres50,
|
||||||
|
else => private.clock_getres,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const clock_gettime = switch (native_os) {
|
||||||
|
.netbsd => private.__clock_gettime50,
|
||||||
|
else => private.clock_gettime,
|
||||||
|
};
|
||||||
|
|
||||||
pub const fstat = switch (native_os) {
|
pub const fstat = switch (native_os) {
|
||||||
.macos => switch (native_arch) {
|
.macos => switch (native_arch) {
|
||||||
|
|
@ -1539,6 +1533,31 @@ pub const fstatat = switch (native_os) {
|
||||||
else => private.fstatat,
|
else => private.fstatat,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const getdirentries = switch (native_os) {
|
||||||
|
.macos, .ios, .tvos, .watchos => private.__getdirentries64,
|
||||||
|
else => private.getdirentries,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const getrusage = switch (native_os) {
|
||||||
|
.netbsd => private.__getrusage50,
|
||||||
|
else => private.getrusage,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const gettimeofday = switch (native_os) {
|
||||||
|
.netbsd => private.__gettimeofday50,
|
||||||
|
else => private.gettimeofday,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const msync = switch (native_os) {
|
||||||
|
.netbsd => private.__msync13,
|
||||||
|
else => private.msync,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const nanosleep = switch (native_os) {
|
||||||
|
.netbsd => private.__nanosleep50,
|
||||||
|
else => private.nanosleep,
|
||||||
|
};
|
||||||
|
|
||||||
pub const readdir = switch (native_os) {
|
pub const readdir = switch (native_os) {
|
||||||
.macos => switch (native_arch) {
|
.macos => switch (native_arch) {
|
||||||
.x86_64 => private.@"readdir$INODE64",
|
.x86_64 => private.@"readdir$INODE64",
|
||||||
|
|
@ -1549,10 +1568,35 @@ pub const readdir = switch (native_os) {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const realpath = switch (native_os) {
|
pub const realpath = switch (native_os) {
|
||||||
.macos, .ios, .watchos, .tvos => private.@"realpath$DARWIN_EXTSN",
|
.macos, .ios, .tvos, .watchos => private.@"realpath$DARWIN_EXTSN",
|
||||||
else => private.realpath,
|
else => private.realpath,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const sched_yield = switch (native_os) {
|
||||||
|
.netbsd => private.__libc_thr_yield,
|
||||||
|
else => private.sched_yield,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const sigaction = switch (native_os) {
|
||||||
|
.netbsd => private.__sigaction14,
|
||||||
|
else => private.sigaction,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const sigfillset = switch (native_os) {
|
||||||
|
.netbsd => private.__sigfillset14,
|
||||||
|
else => private.sigfillset,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const sigprocmask = switch (native_os) {
|
||||||
|
.netbsd => private.__sigprocmask14,
|
||||||
|
else => private.sigprocmask,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const socket = switch (native_os) {
|
||||||
|
.netbsd => private.__socket30,
|
||||||
|
else => private.socket,
|
||||||
|
};
|
||||||
|
|
||||||
pub const stat = switch (native_os) {
|
pub const stat = switch (native_os) {
|
||||||
.macos => switch (native_arch) {
|
.macos => switch (native_arch) {
|
||||||
.x86_64 => private.@"stat$INODE64",
|
.x86_64 => private.@"stat$INODE64",
|
||||||
|
|
@ -1680,7 +1724,6 @@ pub extern "c" fn recvfrom(
|
||||||
pub extern "c" fn recvmsg(sockfd: c.fd_t, msg: *c.msghdr, flags: u32) isize;
|
pub extern "c" fn recvmsg(sockfd: c.fd_t, msg: *c.msghdr, flags: u32) isize;
|
||||||
|
|
||||||
pub extern "c" fn kill(pid: c.pid_t, sig: c_int) c_int;
|
pub extern "c" fn kill(pid: c.pid_t, sig: c_int) c_int;
|
||||||
pub extern "c" fn getdirentries(fd: c.fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
|
|
||||||
|
|
||||||
pub extern "c" fn setuid(uid: c.uid_t) c_int;
|
pub extern "c" fn setuid(uid: c.uid_t) c_int;
|
||||||
pub extern "c" fn setgid(gid: c.gid_t) c_int;
|
pub extern "c" fn setgid(gid: c.gid_t) c_int;
|
||||||
|
|
@ -1878,10 +1921,22 @@ else
|
||||||
};
|
};
|
||||||
|
|
||||||
const private = struct {
|
const private = struct {
|
||||||
|
extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int;
|
||||||
|
extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int;
|
||||||
extern "c" fn fstat(fd: c.fd_t, buf: *c.Stat) c_int;
|
extern "c" fn fstat(fd: c.fd_t, buf: *c.Stat) c_int;
|
||||||
extern "c" fn fstatat(dirfd: c.fd_t, path: [*:0]const u8, buf: *c.Stat, flag: u32) c_int;
|
extern "c" fn fstatat(dirfd: c.fd_t, path: [*:0]const u8, buf: *c.Stat, flag: u32) c_int;
|
||||||
|
extern "c" fn getdirentries(fd: c.fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
|
||||||
|
extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int;
|
||||||
|
extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
|
||||||
|
extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
|
||||||
|
extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
|
||||||
extern "c" fn readdir(dir: *c.DIR) ?*c.dirent;
|
extern "c" fn readdir(dir: *c.DIR) ?*c.dirent;
|
||||||
extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
|
extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
|
||||||
|
extern "c" fn sched_yield() c_int;
|
||||||
|
extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
|
||||||
|
extern "c" fn sigfillset(set: ?*c.sigset_t) void;
|
||||||
|
extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
|
||||||
|
extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
|
||||||
extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int;
|
extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int;
|
||||||
|
|
||||||
/// macos modernized symbols.
|
/// macos modernized symbols.
|
||||||
|
|
@ -1894,7 +1949,20 @@ const private = struct {
|
||||||
|
|
||||||
/// macos modernized symbols.
|
/// macos modernized symbols.
|
||||||
extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
|
extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
|
||||||
|
extern "c" fn __getdirentries64(fd: c.fd_t, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
|
||||||
|
|
||||||
/// netbsd modernized symbols.
|
/// netbsd modernized symbols.
|
||||||
|
extern "c" fn __clock_getres50(clk_id: c_int, tp: *c.timespec) c_int;
|
||||||
|
extern "c" fn __clock_gettime50(clk_id: c_int, tp: *c.timespec) c_int;
|
||||||
extern "c" fn __fstat50(fd: c.fd_t, buf: *c.Stat) c_int;
|
extern "c" fn __fstat50(fd: c.fd_t, buf: *c.Stat) c_int;
|
||||||
|
extern "c" fn __getrusage50(who: c_int, usage: *c.rusage) c_int;
|
||||||
|
extern "c" fn __gettimeofday50(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
|
||||||
|
extern "c" fn __libc_thr_yield() c_int;
|
||||||
|
extern "c" fn __msync13(addr: *align(std.mem.page_size) const anyopaque, len: usize, flags: c_int) c_int;
|
||||||
|
extern "c" fn __nanosleep50(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
|
||||||
|
extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
|
||||||
|
extern "c" fn __sigfillset14(set: ?*c.sigset_t) void;
|
||||||
|
extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
|
||||||
|
extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
|
||||||
|
extern "c" fn __stat50(path: [*:0]const u8, buf: *c.Stat) c_int;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -924,9 +924,6 @@ pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;
|
||||||
pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
|
pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
|
||||||
pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
|
pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
|
||||||
|
|
||||||
// XXX: close -> close$NOCANCEL
|
|
||||||
// XXX: getdirentries -> _getdirentries64
|
|
||||||
|
|
||||||
// See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html
|
// See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html
|
||||||
// TODO: audit mode_t/pid_t, should likely be u16/i32
|
// TODO: audit mode_t/pid_t, should likely be u16/i32
|
||||||
pub const blkcnt_t = i64;
|
pub const blkcnt_t = i64;
|
||||||
|
|
|
||||||
|
|
@ -18,47 +18,14 @@ pub extern "c" fn _lwp_self() lwpid_t;
|
||||||
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
|
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
|
||||||
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
|
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
|
||||||
|
|
||||||
pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int;
|
|
||||||
pub const stat = __stat50;
|
|
||||||
|
|
||||||
pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int;
|
|
||||||
pub const clock_gettime = __clock_gettime50;
|
|
||||||
|
|
||||||
pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int;
|
|
||||||
pub const clock_getres = __clock_getres50;
|
|
||||||
|
|
||||||
pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
|
pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
|
||||||
pub const getdents = __getdents30;
|
pub const getdents = __getdents30;
|
||||||
|
|
||||||
pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
|
pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
|
||||||
pub const sigaltstack = __sigaltstack14;
|
pub const sigaltstack = __sigaltstack14;
|
||||||
|
|
||||||
pub extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int;
|
|
||||||
pub const nanosleep = __nanosleep50;
|
|
||||||
|
|
||||||
pub extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
|
|
||||||
pub const sigaction = __sigaction14;
|
|
||||||
|
|
||||||
pub extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
|
|
||||||
pub const sigprocmask = __sigaction14;
|
|
||||||
|
|
||||||
pub extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
|
|
||||||
pub const socket = __socket30;
|
|
||||||
|
|
||||||
pub extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
|
|
||||||
pub const gettimeofday = __gettimeofday50;
|
|
||||||
|
|
||||||
pub extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int;
|
|
||||||
pub const getrusage = __getrusage50;
|
|
||||||
|
|
||||||
pub extern "c" fn __libc_thr_yield() c_int;
|
|
||||||
pub const sched_yield = __libc_thr_yield;
|
|
||||||
|
|
||||||
pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
|
pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
|
||||||
|
|
||||||
pub extern "c" fn __msync13(addr: *align(std.mem.page_size) const anyopaque, len: usize, flags: c_int) c_int;
|
|
||||||
pub const msync = __msync13;
|
|
||||||
|
|
||||||
pub const pthread_spin_t = switch (builtin.cpu.arch) {
|
pub const pthread_spin_t = switch (builtin.cpu.arch) {
|
||||||
.aarch64, .aarch64_be, .aarch64_32 => u8,
|
.aarch64, .aarch64_be, .aarch64_32 => u8,
|
||||||
.mips, .mipsel, .mips64, .mips64el => u32,
|
.mips, .mipsel, .mips64, .mips64el => u32,
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ pub const Iterator = switch (builtin.os.tag) {
|
||||||
posix.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions
|
posix.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions
|
||||||
self.first_iter = false;
|
self.first_iter = false;
|
||||||
}
|
}
|
||||||
const rc = posix.system.__getdirentries64(
|
const rc = posix.system.getdirentries(
|
||||||
self.dir.fd,
|
self.dir.fd,
|
||||||
&self.buf,
|
&self.buf,
|
||||||
self.buf.len,
|
self.buf.len,
|
||||||
|
|
@ -161,10 +161,7 @@ pub const Iterator = switch (builtin.os.tag) {
|
||||||
posix.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions
|
posix.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions
|
||||||
self.first_iter = false;
|
self.first_iter = false;
|
||||||
}
|
}
|
||||||
const rc = if (builtin.os.tag == .netbsd)
|
const rc = posix.system.getdents(self.dir.fd, &self.buf, self.buf.len);
|
||||||
posix.system.__getdents30(self.dir.fd, &self.buf, self.buf.len)
|
|
||||||
else
|
|
||||||
posix.system.getdents(self.dir.fd, &self.buf, self.buf.len);
|
|
||||||
switch (posix.errno(rc)) {
|
switch (posix.errno(rc)) {
|
||||||
.SUCCESS => {},
|
.SUCCESS => {},
|
||||||
.BADF => unreachable, // Dir is invalid or was opened without iteration ability
|
.BADF => unreachable, // Dir is invalid or was opened without iteration ability
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue