External definitions shared by two or more operating systems.
const private = struct
const private = struct {
pub extern "c" fn strdup(s: [*:0]const c_char) ?[*:0]c_char;
pub extern "c" fn _strdup(s: [*:0]const c_char) ?[*:0]c_char;
pub extern "c" fn wcsdup(s: [*:0]const wchar_t) ?[*:0]wchar_t;
pub extern "c" fn _wcsdup(s: [*:0]const wchar_t) ?[*:0]wchar_t;
pub extern "c" fn swab(noalias from: *const anyopaque, noalias to: *anyopaque, n: isize) void;
pub extern "c" fn _swab(noalias from: *const anyopaque, noalias to: *anyopaque, n: isize) void;
extern "c" fn close(fd: fd_t) c_int;
extern "c" fn clock_getres(clk_id: clockid_t, tp: *timespec) c_int;
extern "c" fn clock_gettime(clk_id: clockid_t, tp: *timespec) c_int;
extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: c_uint) isize;
extern "c" fn flock(fd: fd_t, operation: c_int) c_int;
extern "c" fn fork() c_int;
extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int;
extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) switch (native_os) {
.freebsd => isize,
.illumos => usize,
else => c_int,
};
extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
extern "c" fn ioctl(fd: fd_t, request: c_int, ...) 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 timespec, rmtp: ?*timespec) c_int;
extern "c" fn clock_nanosleep(clockid: clockid_t, flags: TIMER, t: *const timespec, remain: ?*timespec) c_int;
extern "c" fn pipe2(fds: *[2]fd_t, flags: O) c_int;
extern "c" fn readdir(dir: *DIR) ?*dirent;
extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
extern "c" fn recvmsg(sockfd: fd_t, msg: *msghdr, flags: u32) isize;
extern "c" fn sched_yield() c_int;
extern "c" fn sendfile(out_fd: fd_t, in_fd: fd_t, offset: ?*off_t, count: usize) isize;
extern "c" fn sigaction(sig: SIG, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
extern "c" fn sigdelset(set: ?*sigset_t, signo: SIG) c_int;
extern "c" fn sigaddset(set: ?*sigset_t, signo: SIG) c_int;
extern "c" fn sigfillset(set: ?*sigset_t) c_int;
extern "c" fn sigemptyset(set: ?*sigset_t) c_int;
extern "c" fn sigismember(set: ?*const sigset_t, signo: SIG) c_int;
extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;
extern "c" fn sigaltstack(ss: ?*const stack_t, old_ss: ?*stack_t) c_int;
extern "c" fn sysconf(sc: c_int) c_long;
extern "c" fn shm_open(name: [*:0]const u8, flag: c_int, mode: mode_t) c_int;
extern "c" fn wait4(pid: pid_t, status: ?*c_int, options: c_int, ru: ?*rusage) pid_t;
extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8) c_int;
extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
extern "c" fn getentropy(buffer: [*]u8, size: usize) c_int;
extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
extern "c" fn _msize(?*const anyopaque) usize;
extern "c" fn malloc_size(?*const anyopaque) usize;
extern "c" fn malloc_usable_size(?*const anyopaque) usize;
extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
extern "c" fn mlock(addr: *align(page_size) const anyopaque, len: usize) c_int;
extern "c" fn mlock2(addr: *align(page_size) const anyopaque, len: usize, flags: MLOCK) c_int;
extern "c" fn munlock(addr: *align(page_size) const anyopaque, len: usize) c_int;
extern "c" fn mlockall(flags: MCL) c_int;
extern "c" fn munlockall() c_int;
// linux and https://github.com/SerenityOS/serenity/blob/502caef9a40bccc7459f9835f2174a601106299a/Userland/Libraries/LibC/sys/ptrace.cpp
extern "c" fn ptrace(request: c_int, pid: pid_t, addr: ?*anyopaque, data: ?*anyopaque) c_long;
/// macos modernized symbols.
/// x86_64 links to $INODE64 suffix for 64-bit support.
/// Note these are not necessary on aarch64.
extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int;
extern "c" fn @"readdir$INODE64"(dir: *DIR) ?*dirent;
extern "c" fn @"stat$INODE64"(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
/// macos modernized symbols.
extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
extern "c" fn __getdirentries64(fd: fd_t, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
extern "c" fn pthread_threadid_np(thread: ?pthread_t, thread_id: *u64) c_int;
/// netbsd modernized symbols.
extern "c" fn __clock_getres50(clk_id: clockid_t, tp: *timespec) c_int;
extern "c" fn __clock_gettime50(clk_id: clockid_t, tp: *timespec) c_int;
extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int;
extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int;
extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
extern "c" fn __libc_thr_yield() c_int;
extern "c" fn __msync13(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int;
extern "c" fn __sigaction14(sig: SIG, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
extern "c" fn __sigemptyset14(set: ?*sigset_t) c_int;
extern "c" fn __sigfillset14(set: ?*sigset_t) c_int;
extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*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: *Stat) c_int;
extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
extern "c" fn __sigaltstack14(ss: ?*const stack_t, old_ss: ?*stack_t) c_int;
extern "c" fn __wait450(pid: pid_t, status: ?*c_int, options: c_int, ru: ?*rusage) pid_t;
extern "c" fn __libc_current_sigrtmin() c_int;
extern "c" fn __libc_current_sigrtmax() c_int;
extern "c" fn __signal_get_sigrtmin() c_int;
extern "c" fn __signal_get_sigrtmax() c_int;
// Don't forget to add another clown when an OS picks yet another unique
// symbol name for errno location!
// 🤡🤡🤡🤡🤡🤡
extern "c" fn ___errno() *c_int;
extern "c" fn __errno() *c_int;
extern "c" fn __errno_location() *c_int;
extern "c" fn __error() *c_int;
extern "c" fn _errno() *c_int;
extern threadlocal var errno: c_int;
fn errnoFromThreadLocal() *c_int {
return &private.errno;
}
}