zig/lib/std / c/freebsd.zig

const std = @import("../std.zig");
const assert = std.debug.assert;
const builtin = @import("builtin");
const maxInt = std.math.maxInt;
const iovec = std.os.iovec;
const iovec_const = std.os.iovec_const;

extern "c" fn __error() *c_int;

_errno

pub const _errno = __error;

pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) isize;
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;

pub extern "c" fn pthread_getthreadid_np() c_int;
pub extern "c" fn pthread_set_name_np(thread: std.c.pthread_t, name: [*:0]const u8) void;
pub extern "c" fn pthread_get_name_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) void;
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;

pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
pub extern "c" fn malloc_usable_size(?*const anyopaque) usize;

pub extern "c" fn getpid() pid_t;

pub extern "c" fn kinfo_getfile(pid: pid_t, cntp: *c_int) ?[*]kinfo_file;

sf_hdtr

pub const sf_hdtr = extern struct {
    headers: [*]const iovec_const,
    hdr_cnt: c_int,
    trailers: [*]const iovec_const,
    trl_cnt: c_int,
};
pub extern "c" fn sendfile(
    in_fd: fd_t,
    out_fd: fd_t,
    offset: off_t,
    nbytes: usize,
    sf_hdtr: ?*sf_hdtr,
    sbytes: ?*off_t,
    flags: u32,
) c_int;

dl_iterate_phdr_callback

pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;

pthread_mutex_t

pub const pthread_mutex_t = extern struct {
    inner: ?*anyopaque = null,
};

pthread_cond_t

pub const pthread_cond_t = extern struct {
    inner: ?*anyopaque = null,
};

pthread_rwlock_t

pub const pthread_rwlock_t = extern struct {
    ptr: ?*anyopaque = null,
};

pthread_attr_t

pub const pthread_attr_t = extern struct {
    inner: ?*anyopaque = null,
};

sem_t

pub const sem_t = extern struct {
    _magic: u32,
    _kern: extern struct {
        _count: u32,
        _flags: u32,
    },
    _padding: u32,
};

// https://github.com/freebsd/freebsd-src/blob/main/sys/sys/umtx.h

UMTX_OP

pub const UMTX_OP = enum(c_int) {
    LOCK = 0,
    UNLOCK = 1,
    WAIT = 2,
    WAKE = 3,
    MUTEX_TRYLOCK = 4,
    MUTEX_LOCK = 5,
    MUTEX_UNLOCK = 6,
    SET_CEILING = 7,
    CV_WAIT = 8,
    CV_SIGNAL = 9,
    CV_BROADCAST = 10,
    WAIT_UINT = 11,
    RW_RDLOCK = 12,
    RW_WRLOCK = 13,
    RW_UNLOCK = 14,
    WAIT_UINT_PRIVATE = 15,
    WAKE_PRIVATE = 16,
    MUTEX_WAIT = 17,
    MUTEX_WAKE = 18, // deprecated
    SEM_WAIT = 19, // deprecated
    SEM_WAKE = 20, // deprecated
    NWAKE_PRIVATE = 31,
    MUTEX_WAKE2 = 22,
    SEM2_WAIT = 23,
    SEM2_WAKE = 24,
    SHM = 25,
    ROBUST_LISTS = 26,
};

UMTX_ABSTIME

pub const UMTX_ABSTIME = 0x01;

_umtx_time

pub const _umtx_time = extern struct {
    _timeout: timespec,
    _flags: u32,
    _clockid: u32,
};

pub extern "c" fn _umtx_op(obj: usize, op: c_int, val: c_ulong, uaddr: usize, uaddr2: usize) c_int;

EAI

pub const EAI = enum(c_int) {
    ADDRFAMILY = 1,

    AGAIN = 2,

    BADFLAGS = 3,

    FAIL = 4,

    FAMILY = 5,

    MEMORY = 6,

    NODATA = 7,

    NONAME = 8,

    SERVICE = 9,

    SOCKTYPE = 10,

    SYSTEM = 11,

    BADHINTS = 12,

    PROTOCOL = 13,

    OVERFLOW = 14,

    _,
};

EAI_MAX

address family for hostname not supported name could not be resolved at this time flags parameter had an invalid value non-recoverable failure in name resolution address family not recognized memory allocation failure no address associated with hostname name does not resolve service not recognized for socket type intended socket type was not recognized system error returned in errno invalid value for hints resolved protocol is unknown argument buffer overflow

pub const EAI_MAX = 15;

IFNAMESIZE

pub const IFNAMESIZE = 16;

AI

pub const AI = struct {
    pub const PASSIVE = 0x00000001;
    pub const CANONNAME = 0x00000002;
    pub const NUMERICHOST = 0x00000004;
    pub const NUMERICSERV = 0x00000008;
    pub const MASK = (PASSIVE | CANONNAME | NUMERICHOST | NUMERICSERV | ADDRCONFIG | ALL | V4MAPPED);
    pub const ALL = 0x00000100;
    pub const V4MAPPED_CFG = 0x00000200;
    pub const ADDRCONFIG = 0x00000400;
    pub const V4MAPPED = 0x00000800;
    pub const DEFAULT = (V4MAPPED_CFG | ADDRCONFIG);
};

blksize_t

get address to use bind() fill ai_canonname prevent host name resolution prevent service name resolution valid flags for addrinfo (not a standard def, apps should not use it) IPv6 and IPv4-mapped (with V4MAPPED) accept IPv4-mapped if kernel supports only if any address is assigned accept IPv4-mapped IPv6 address special recommended flags for getipnodebyname

pub const blksize_t = i32;

blkcnt_t

pub const blkcnt_t = i64;

clockid_t

pub const clockid_t = i32;

fflags_t

pub const fflags_t = u32;

fsblkcnt_t

pub const fsblkcnt_t = u64;

fsfilcnt_t

pub const fsfilcnt_t = u64;

nlink_t

pub const nlink_t = u64;

fd_t

pub const fd_t = i32;

pid_t

pub const pid_t = i32;

uid_t

pub const uid_t = u32;

gid_t

pub const gid_t = u32;

mode_t

pub const mode_t = u16;

off_t

pub const off_t = i64;

ino_t

pub const ino_t = u64;

dev_t

pub const dev_t = u64;

time_t

pub const time_t = i64;
// The signedness is not constant across different architectures.

clock_t

pub const clock_t = isize;

socklen_t

pub const socklen_t = u32;

suseconds_t

pub const suseconds_t = c_long;

Kevent

Renamed from kevent to Kevent to avoid conflict with function name.

pub const Kevent = extern struct {
    ident: usize,
    filter: i16,
    flags: u16,
    fflags: u32,
    data: i64,
    udata: usize,
    _ext: [4]u64 = [_]u64{0} ** 4,
};

// Modes and flags for dlopen()
// include/dlfcn.h

RTLD

Identifier for this event. Filter for event. Action flags for kqueue. Filter flag value. Filter data value. Opaque user data identifier. Future extensions.

pub const RTLD = struct {
    pub const LAZY = 1;
    pub const NOW = 2;
    pub const MODEMASK = 0x3;
    pub const GLOBAL = 0x100;
    pub const LOCAL = 0;
    pub const TRACE = 0x200;
    pub const NODELETE = 0x01000;
    pub const NOLOAD = 0x02000;
};

dl_phdr_info

Bind function calls lazily. Bind function calls immediately. Make symbols globally available. Opposite of GLOBAL, and the default. Trace loaded objects and exit. Do not remove members. Do not load if not already loaded.

pub const dl_phdr_info = extern struct {
    dlpi_addr: if (builtin.target.ptrBitWidth() == 32) std.elf.Elf32_Addr else std.elf.Elf64_Addr,
    dlpi_name: ?[*:0]const u8,
    dlpi_phdr: [*]std.elf.Phdr,
    dlpi_phnum: u16,
    dlpi_adds: u64,
    dlpi_subs: u64,
    dlpi_tls_modid: usize,
    dlpi_tls_data: ?*anyopaque,
};

Flock

Module relocation base. Module name. Pointer to module's phdr. Number of entries in phdr. Total number of loads. Total number of unloads.

pub const Flock = extern struct {
    start: off_t,
    len: off_t,
    pid: pid_t,
    type: i16,
    whence: i16,
    sysid: i32,
};

msghdr

Starting offset. Number of consecutive bytes to be locked. A value of 0 means to the end of the file. Lock owner. Lock type. Type of the start member. Remote system id or zero for local.

pub const msghdr = extern struct {
    msg_name: ?*sockaddr,
    msg_namelen: socklen_t,
    msg_iov: [*]iovec,
    msg_iovlen: i32,
    msg_control: ?*anyopaque,
    msg_controllen: socklen_t,
    msg_flags: i32,
};

msghdr_const

Optional address. Size of address. Scatter/gather array. Number of elements in msg_iov. Ancillary data. Ancillary data buffer length. Flags on received message.

pub const msghdr_const = extern struct {
    msg_name: ?*const sockaddr,
    msg_namelen: socklen_t,
    msg_iov: [*]iovec_const,
    msg_iovlen: i32,
    msg_control: ?*anyopaque,
    msg_controllen: socklen_t,
    msg_flags: i32,
};

Stat

Optional address. Size of address. Scatter/gather array. Number of elements in msg_iov. Ancillary data. Ancillary data buffer length. Flags on received message.

pub const Stat = extern struct {
    dev: dev_t,
    ino: ino_t,
    nlink: nlink_t,
    mode: mode_t,
    __pad0: i16,
    uid: uid_t,
    gid: gid_t,
    __pad1: i32,
    rdev: dev_t,
    atim: timespec,
    mtim: timespec,
    ctim: timespec,
    birthtim: timespec,
    size: off_t,
    blocks: blkcnt_t,
    blksize: blksize_t,
    flags: fflags_t,
    gen: u64,
    __spare: [10]u64,

atime()

The inode's device. The inode's number. Number of hard links. Inode protection mode. User ID of the file's owner. Group ID of the file's group. Device type. Time of last access. Time of last data modification. Time of last file status change. Time of file creation. File size, in bytes. Blocks allocated for file. Optimal blocksize for I/O. User defined flags for file. File generation number.

    pub fn atime(self: @This()) timespec {
        return self.atim;
    }

mtime()

    pub fn mtime(self: @This()) timespec {
        return self.mtim;
    }

ctime()

    pub fn ctime(self: @This()) timespec {
        return self.ctim;
    }

birthtime()

    pub fn birthtime(self: @This()) timespec {
        return self.birthtim;
    }
};

timespec

pub const timespec = extern struct {
    tv_sec: isize,
    tv_nsec: isize,
};

timeval

pub const timeval = extern struct {
    tv_sec: time_t,
    tv_usec: suseconds_t,
};

dirent

seconds microseconds

pub const dirent = extern struct {
    d_fileno: ino_t,
    d_off: off_t,
    d_reclen: u16,
    d_type: u8,
    _d_pad0: u8,
    d_namlen: u16,
    _d_pad1: u16,
    d_name: [255:0]u8,

reclen()

File number of entry. Directory offset of entry. Length of this record. File type, one of DT_. Length of the d_name member. Name of entry.

    pub fn reclen(self: dirent) u16 {
        return self.d_reclen;
    }
};

in_port_t

pub const in_port_t = u16;

sa_family_t

pub const sa_family_t = u8;

sockaddr

pub const sockaddr = extern struct {
    len: u8,
    family: sa_family_t,
    data: [14]u8,

    pub const SS_MAXSIZE = 128;
    pub const storage = extern struct {
        len: u8 align(8),
        family: sa_family_t,
        padding: [126]u8 = undefined,

        comptime {
            assert(@sizeOf(storage) == SS_MAXSIZE);
            assert(@alignOf(storage) == 8);
        }
    };

    pub const in = extern struct {
        len: u8 = @sizeOf(in),
        family: sa_family_t = AF.INET,
        port: in_port_t,
        addr: u32,
        zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
    };

    pub const in6 = extern struct {
        len: u8 = @sizeOf(in6),
        family: sa_family_t = AF.INET6,
        port: in_port_t,
        flowinfo: u32,
        addr: [16]u8,
        scope_id: u32,
    };

    pub const un = extern struct {
        len: u8 = @sizeOf(un),
        family: sa_family_t = AF.UNIX,
        path: [104]u8,
    };
};

CAP_RIGHTS_VERSION

total length address family actually longer; address value

pub const CAP_RIGHTS_VERSION = 0;

cap_rights

pub const cap_rights = extern struct {
    rights: [CAP_RIGHTS_VERSION + 2]u64,
};

kinfo_file

pub const kinfo_file = extern struct {
    structsize: c_int,
    type: c_int,
    fd: fd_t,
    ref_count: c_int,
    flags: c_int,
    // 64bit padding.
    _pad0: c_int,
    offset: i64,
    un: extern union {
        socket: extern struct {
            sendq: u32,
            domain: c_int,
            type: c_int,
            protocol: c_int,
            address: sockaddr.storage,
            peer: sockaddr.storage,
            pcb: u64,
            inpcb: u64,
            unpconn: u64,
            snd_sb_state: u16,
            rcv_sb_state: u16,
            recvq: u32,
        },
        file: extern struct {
            type: i32,
            // Reserved for future use
            _spare1: [3]i32,
            _spare2: [30]u64,
            fsid: u64,
            rdev: u64,
            fileid: u64,
            size: u64,
            fsid_freebsd11: u32,
            rdev_freebsd11: u32,
            mode: u16,
            // 64bit padding.
            _pad0: u16,
            _pad1: u32,
        },
        sem: extern struct {
            _spare0: [4]u32,
            _spare1: [32]u64,
            value: u32,
            mode: u16,
        },
        pipe: extern struct {
            _spare1: [4]u32,
            _spare2: [32]u64,
            addr: u64,
            peer: u64,
            buffer_cnt: u32,
            // 64bit padding.
            kf_pipe_pad0: [3]u32,
        },
        proc: extern struct {
            _spare1: [4]u32,
            _spare2: [32]u64,
            pid: pid_t,
        },
        eventfd: extern struct {
            value: u64,
            flags: u32,
        },
    },
    status: u16,
    // 32-bit alignment padding.
    _pad1: u16,
    // Reserved for future use.
    _spare: c_int,
    cap_rights: cap_rights,
    _cap_spare: u64,
    path: [PATH_MAX - 1:0]u8,
};

KINFO_FILE_SIZE

Size of this record. A zero value is for the sentinel record at the end of an array. Descriptor type. Array index. Reference count. Flags. Seek location. Sendq size. Socket domain. Socket type. Socket protocol. Socket address. Peer address. Address of so_pcb. Address of inp_ppcb. Address of unp_conn. Send buffer state. Receive buffer state. Recvq size. Vnode type. Vnode filesystem id. File device. Global file id. File size. fsid compat for FreeBSD 11. rdev compat for FreeBSD 11. File mode. Semaphore value. Semaphore mode. Status flags. Capability rights. Reserved for future cap_rights Path to file, if any.

pub const KINFO_FILE_SIZE = 1392;

comptime {
    std.debug.assert(@sizeOf(kinfo_file) == KINFO_FILE_SIZE);
    std.debug.assert(@alignOf(kinfo_file) == @sizeOf(u64));
}

CTL

pub const CTL = struct {
    pub const KERN = 1;
    pub const DEBUG = 5;
};

KERN

pub const KERN = struct {
    pub const PROC = 14; // struct: process entries
    pub const PROC_PATHNAME = 12; // path to executable
    pub const PROC_FILEDESC = 33; // file descriptors for process
    pub const IOV_MAX = 35;
};

PATH_MAX

pub const PATH_MAX = 1024;

IOV_MAX

pub const IOV_MAX = KERN.IOV_MAX;

STDIN_FILENO

pub const STDIN_FILENO = 0;

STDOUT_FILENO

pub const STDOUT_FILENO = 1;

STDERR_FILENO

pub const STDERR_FILENO = 2;

PROT

pub const PROT = struct {
    pub const NONE = 0;
    pub const READ = 1;
    pub const WRITE = 2;
    pub const EXEC = 4;
};

CLOCK

pub const CLOCK = struct {
    pub const REALTIME = 0;
    pub const VIRTUAL = 1;
    pub const PROF = 2;
    pub const MONOTONIC = 4;
    pub const UPTIME = 5;
    pub const UPTIME_PRECISE = 7;
    pub const UPTIME_FAST = 8;
    pub const REALTIME_PRECISE = 9;
    pub const REALTIME_FAST = 10;
    pub const MONOTONIC_PRECISE = 11;
    pub const MONOTONIC_FAST = 12;
    pub const SECOND = 13;
    pub const THREAD_CPUTIME_ID = 14;
    pub const PROCESS_CPUTIME_ID = 15;
};

MAP

pub const MAP = struct {
    pub const FAILED = @as(*anyopaque, @ptrFromInt(maxInt(usize)));
    pub const SHARED = 0x0001;
    pub const PRIVATE = 0x0002;
    pub const FIXED = 0x0010;
    pub const STACK = 0x0400;
    pub const NOSYNC = 0x0800;
    pub const ANON = 0x1000;
    pub const ANONYMOUS = ANON;
    pub const FILE = 0;

    pub const GUARD = 0x00002000;
    pub const EXCL = 0x00004000;
    pub const NOCORE = 0x00020000;
    pub const PREFAULT_READ = 0x00040000;
    pub const @"32BIT" = 0x00080000;

ALIGNED()

    pub fn ALIGNED(alignment: u32) u32 {
        return alignment << 24;
    }
    pub const ALIGNED_SUPER = ALIGNED(1);
};

MADV

pub const MADV = struct {
    pub const NORMAL = 0;
    pub const RANDOM = 1;
    pub const SEQUENTIAL = 2;
    pub const WILLNEED = 3;
    pub const DONTNEED = 4;
    pub const FREE = 5;
    pub const NOSYNC = 6;
    pub const AUTOSYNC = 7;
    pub const NOCORE = 8;
    pub const CORE = 9;
    pub const PROTECT = 10;
};

MSF

pub const MSF = struct {
    pub const ASYNC = 1;
    pub const INVALIDATE = 2;
    pub const SYNC = 4;
};

W

pub const W = struct {
    pub const NOHANG = 1;
    pub const UNTRACED = 2;
    pub const STOPPED = UNTRACED;
    pub const CONTINUED = 4;
    pub const NOWAIT = 8;
    pub const EXITED = 16;
    pub const TRAPPED = 32;

EXITSTATUS()

    pub fn EXITSTATUS(s: u32) u8 {
        return @as(u8, @intCast((s & 0xff00) >> 8));
    }

TERMSIG()

    pub fn TERMSIG(s: u32) u32 {
        return s & 0x7f;
    }

STOPSIG()

    pub fn STOPSIG(s: u32) u32 {
        return EXITSTATUS(s);
    }

IFEXITED()

    pub fn IFEXITED(s: u32) bool {
        return TERMSIG(s) == 0;
    }

IFSTOPPED()

    pub fn IFSTOPPED(s: u32) bool {
        return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
    }

IFSIGNALED()

    pub fn IFSIGNALED(s: u32) bool {
        return (s & 0xffff) -% 1 < 0xff;
    }
};

SA

pub const SA = struct {
    pub const ONSTACK = 0x0001;
    pub const RESTART = 0x0002;
    pub const RESETHAND = 0x0004;
    pub const NOCLDSTOP = 0x0008;
    pub const NODEFER = 0x0010;
    pub const NOCLDWAIT = 0x0020;
    pub const SIGINFO = 0x0040;
};

SIG

pub const SIG = struct {
    pub const HUP = 1;
    pub const INT = 2;
    pub const QUIT = 3;
    pub const ILL = 4;
    pub const TRAP = 5;
    pub const ABRT = 6;
    pub const IOT = ABRT;
    pub const EMT = 7;
    pub const FPE = 8;
    pub const KILL = 9;
    pub const BUS = 10;
    pub const SEGV = 11;
    pub const SYS = 12;
    pub const PIPE = 13;
    pub const ALRM = 14;
    pub const TERM = 15;
    pub const URG = 16;
    pub const STOP = 17;
    pub const TSTP = 18;
    pub const CONT = 19;
    pub const CHLD = 20;
    pub const TTIN = 21;
    pub const TTOU = 22;
    pub const IO = 23;
    pub const XCPU = 24;
    pub const XFSZ = 25;
    pub const VTALRM = 26;
    pub const PROF = 27;
    pub const WINCH = 28;
    pub const INFO = 29;
    pub const USR1 = 30;
    pub const USR2 = 31;
    pub const THR = 32;
    pub const LWP = THR;
    pub const LIBRT = 33;

    pub const RTMIN = 65;
    pub const RTMAX = 126;

    pub const BLOCK = 1;
    pub const UNBLOCK = 2;
    pub const SETMASK = 3;

    pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
    pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
    pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));

    pub const WORDS = 4;
    pub const MAXSIG = 128;

IDX()

    pub inline fn IDX(sig: usize) usize {
        return sig - 1;
    }

WORD()

    pub inline fn WORD(sig: usize) usize {
        return IDX(sig) >> 5;
    }

BIT()

    pub inline fn BIT(sig: usize) usize {
        return 1 << (IDX(sig) & 31);
    }

VALID()

    pub inline fn VALID(sig: usize) usize {
        return sig <= MAXSIG and sig > 0;
    }
};

sigval

pub const sigval = extern union {
    int: c_int,
    ptr: ?*anyopaque,
};

sigset_t

pub const sigset_t = extern struct {
    __bits: [SIG.WORDS]u32,
};

empty_sigset

pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS };

// access function

F_OK

pub const F_OK = 0; // test for existence of file

X_OK

pub const X_OK = 1; // test for execute or search permission

W_OK

pub const W_OK = 2; // test for write permission

R_OK

pub const R_OK = 4; // test for read permission

O

pub const O = struct {
    pub const RDONLY = 0x0000;
    pub const WRONLY = 0x0001;
    pub const RDWR = 0x0002;
    pub const ACCMODE = 0x0003;

    pub const SHLOCK = 0x0010;
    pub const EXLOCK = 0x0020;

    pub const CREAT = 0x0200;
    pub const EXCL = 0x0800;
    pub const NOCTTY = 0x8000;
    pub const TRUNC = 0x0400;
    pub const APPEND = 0x0008;
    pub const NONBLOCK = 0x0004;
    pub const DSYNC = 0o10000;
    pub const SYNC = 0x0080;
    pub const RSYNC = 0o4010000;
    pub const DIRECTORY = 0x20000;
    pub const NOFOLLOW = 0x0100;
    pub const CLOEXEC = 0x00100000;

    pub const ASYNC = 0x0040;
    pub const DIRECT = 0x00010000;
    pub const NOATIME = 0o1000000;
    pub const PATH = 0o10000000;
    pub const TMPFILE = 0o20200000;
    pub const NDELAY = NONBLOCK;
};

F

Command flags for fcntl(2).

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 = 11;
    pub const SETLK = 12;
    pub const SETLKW = 13;

    pub const SETLK_REMOTE = 14;
    pub const READAHEAD = 15;

    pub const DUPFD_CLOEXEC = 17;
    pub const DUP2FD_CLOEXEC = 18;

    pub const ADD_SEALS = 19;
    pub const GET_SEALS = 20;
    pub const KINFO = 22;

    // Seals (ADD_SEALS, GET_SEALS)
    pub const SEAL_SEAL = 0x0001;
    pub const SEAL_SHRINK = 0x0002;
    pub const SEAL_GROW = 0x0004;
    pub const SEAL_WRITE = 0x0008;

    // Record locking flags (GETLK, SETLK, SETLKW).
    pub const RDLCK = 1;
    pub const UNLCK = 2;
    pub const WRLCK = 3;
    pub const UNLCKSYS = 4;
    pub const CANCEL = 5;

    pub const SETOWN_EX = 15;
    pub const GETOWN_EX = 16;

    pub const GETOWNER_UIDS = 17;
};

LOCK

Duplicate file descriptor. Get file descriptor flags. Set file descriptor flags. Get file status flags. Set file status flags. Get SIGIO/SIGURG proc/pgrrp. Set SIGIO/SIGURG proc/pgrrp. Get record locking information. Set record locking information. Set record locking information and wait if blocked. Debugging support for remote locks. Read ahead. DUPFD with FD_CLOEXEC set. DUP2FD with FD_CLOEXEC set. Return kinfo_file for a file descriptor. Prevent adding sealings. May not shrink May not grow. May not write. Shared or read lock. Unlock. Exclusive or write lock. Purge locks for a given system ID. Cancel an async lock request.

pub const LOCK = struct {
    pub const SH = 1;
    pub const EX = 2;
    pub const UN = 8;
    pub const NB = 4;
};

FD_CLOEXEC

pub const FD_CLOEXEC = 1;

SEEK

pub const SEEK = struct {
    pub const SET = 0;
    pub const CUR = 1;
    pub const END = 2;
};

SOCK

pub const SOCK = struct {
    pub const STREAM = 1;
    pub const DGRAM = 2;
    pub const RAW = 3;
    pub const RDM = 4;
    pub const SEQPACKET = 5;

    pub const CLOEXEC = 0x10000000;
    pub const NONBLOCK = 0x20000000;
};

SO

pub const SO = struct {
    pub const DEBUG = 0x00000001;
    pub const ACCEPTCONN = 0x00000002;
    pub const REUSEADDR = 0x00000004;
    pub const KEEPALIVE = 0x00000008;
    pub const DONTROUTE = 0x00000010;
    pub const BROADCAST = 0x00000020;
    pub const USELOOPBACK = 0x00000040;
    pub const LINGER = 0x00000080;
    pub const OOBINLINE = 0x00000100;
    pub const REUSEPORT = 0x00000200;
    pub const TIMESTAMP = 0x00000400;
    pub const NOSIGPIPE = 0x00000800;
    pub const ACCEPTFILTER = 0x00001000;
    pub const BINTIME = 0x00002000;
    pub const NO_OFFLOAD = 0x00004000;
    pub const NO_DDP = 0x00008000;
    pub const REUSEPORT_LB = 0x00010000;

    pub const SNDBUF = 0x1001;
    pub const RCVBUF = 0x1002;
    pub const SNDLOWAT = 0x1003;
    pub const RCVLOWAT = 0x1004;
    pub const SNDTIMEO = 0x1005;
    pub const RCVTIMEO = 0x1006;
    pub const ERROR = 0x1007;
    pub const TYPE = 0x1008;
    pub const LABEL = 0x1009;
    pub const PEERLABEL = 0x1010;
    pub const LISTENQLIMIT = 0x1011;
    pub const LISTENQLEN = 0x1012;
    pub const LISTENINCQLEN = 0x1013;
    pub const SETFIB = 0x1014;
    pub const USER_COOKIE = 0x1015;
    pub const PROTOCOL = 0x1016;
    pub const PROTOTYPE = PROTOCOL;
    pub const TS_CLOCK = 0x1017;
    pub const MAX_PACING_RATE = 0x1018;
    pub const DOMAIN = 0x1019;
};

SOL

pub const SOL = struct {
    pub const SOCKET = 0xffff;
};

PF

pub const PF = struct {
    pub const UNSPEC = AF.UNSPEC;
    pub const LOCAL = AF.LOCAL;
    pub const UNIX = PF.LOCAL;
    pub const INET = AF.INET;
    pub const IMPLINK = AF.IMPLINK;
    pub const PUP = AF.PUP;
    pub const CHAOS = AF.CHAOS;
    pub const NETBIOS = AF.NETBIOS;
    pub const ISO = AF.ISO;
    pub const OSI = AF.ISO;
    pub const ECMA = AF.ECMA;
    pub const DATAKIT = AF.DATAKIT;
    pub const CCITT = AF.CCITT;
    pub const DECnet = AF.DECnet;
    pub const DLI = AF.DLI;
    pub const LAT = AF.LAT;
    pub const HYLINK = AF.HYLINK;
    pub const APPLETALK = AF.APPLETALK;
    pub const ROUTE = AF.ROUTE;
    pub const LINK = AF.LINK;
    pub const XTP = AF.pseudo_XTP;
    pub const COIP = AF.COIP;
    pub const CNT = AF.CNT;
    pub const SIP = AF.SIP;
    pub const IPX = AF.IPX;
    pub const RTIP = AF.pseudo_RTIP;
    pub const PIP = AF.pseudo_PIP;
    pub const ISDN = AF.ISDN;
    pub const KEY = AF.pseudo_KEY;
    pub const INET6 = AF.pseudo_INET6;
    pub const NATM = AF.NATM;
    pub const ATM = AF.ATM;
    pub const NETGRAPH = AF.NETGRAPH;
    pub const SLOW = AF.SLOW;
    pub const SCLUSTER = AF.SCLUSTER;
    pub const ARP = AF.ARP;
    pub const BLUETOOTH = AF.BLUETOOTH;
    pub const IEEE80211 = AF.IEEE80211;
    pub const INET_SDP = AF.INET_SDP;
    pub const INET6_SDP = AF.INET6_SDP;
    pub const MAX = AF.MAX;
};

AF

pub const AF = struct {
    pub const UNSPEC = 0;
    pub const UNIX = 1;
    pub const LOCAL = UNIX;
    pub const FILE = LOCAL;
    pub const INET = 2;
    pub const IMPLINK = 3;
    pub const PUP = 4;
    pub const CHAOS = 5;
    pub const NETBIOS = 6;
    pub const ISO = 7;
    pub const OSI = ISO;
    pub const ECMA = 8;
    pub const DATAKIT = 9;
    pub const CCITT = 10;
    pub const SNA = 11;
    pub const DECnet = 12;
    pub const DLI = 13;
    pub const LAT = 14;
    pub const HYLINK = 15;
    pub const APPLETALK = 16;
    pub const ROUTE = 17;
    pub const LINK = 18;
    pub const pseudo_XTP = 19;
    pub const COIP = 20;
    pub const CNT = 21;
    pub const pseudo_RTIP = 22;
    pub const IPX = 23;
    pub const SIP = 24;
    pub const pseudo_PIP = 25;
    pub const ISDN = 26;
    pub const E164 = ISDN;
    pub const pseudo_KEY = 27;
    pub const INET6 = 28;
    pub const NATM = 29;
    pub const ATM = 30;
    pub const pseudo_HDRCMPLT = 31;
    pub const NETGRAPH = 32;
    pub const SLOW = 33;
    pub const SCLUSTER = 34;
    pub const ARP = 35;
    pub const BLUETOOTH = 36;
    pub const IEEE80211 = 37;
    pub const INET_SDP = 40;
    pub const INET6_SDP = 42;
    pub const MAX = 42;
};

DT

pub const DT = struct {
    pub const UNKNOWN = 0;
    pub const FIFO = 1;
    pub const CHR = 2;
    pub const DIR = 4;
    pub const BLK = 6;
    pub const REG = 8;
    pub const LNK = 10;
    pub const SOCK = 12;
    pub const WHT = 14;
};

EV_ADD

add event to kq (implies enable)

pub const EV_ADD = 0x0001;

EV_DELETE

delete event from kq

pub const EV_DELETE = 0x0002;

EV_ENABLE

enable event

pub const EV_ENABLE = 0x0004;

EV_DISABLE

disable event (not reported)

pub const EV_DISABLE = 0x0008;

EV_ONESHOT

only report one occurrence

pub const EV_ONESHOT = 0x0010;

EV_CLEAR

clear event state after reporting

pub const EV_CLEAR = 0x0020;

EV_ERROR

error, event data contains errno

pub const EV_ERROR = 0x4000;

EV_RECEIPT

force immediate event output ... with or without EV_ERROR ... use KEVENT_FLAG_ERROR_EVENTS on syscalls supporting flags

pub const EV_RECEIPT = 0x0040;

EV_DISPATCH

disable event after reporting

pub const EV_DISPATCH = 0x0080;

EVFILT_READ

pub const EVFILT_READ = -1;

EVFILT_WRITE

pub const EVFILT_WRITE = -2;

EVFILT_AIO

attached to aio requests

pub const EVFILT_AIO = -3;

EVFILT_VNODE

attached to vnodes

pub const EVFILT_VNODE = -4;

EVFILT_PROC

attached to struct proc

pub const EVFILT_PROC = -5;

EVFILT_SIGNAL

attached to struct proc

pub const EVFILT_SIGNAL = -6;

EVFILT_TIMER

timers

pub const EVFILT_TIMER = -7;

EVFILT_PROCDESC

Process descriptors

pub const EVFILT_PROCDESC = -8;

EVFILT_FS

Filesystem events

pub const EVFILT_FS = -9;

EVFILT_LIO

pub const EVFILT_LIO = -10;

EVFILT_USER

User events

pub const EVFILT_USER = -11;

EVFILT_SENDFILE

Sendfile events

pub const EVFILT_SENDFILE = -12;

EVFILT_EMPTY

pub const EVFILT_EMPTY = -13;

NOTE_TRIGGER

On input, NOTE_TRIGGER causes the event to be triggered for output.

pub const NOTE_TRIGGER = 0x01000000;

NOTE_FFNOP

ignore input fflags

pub const NOTE_FFNOP = 0x00000000;

NOTE_FFAND

and fflags

pub const NOTE_FFAND = 0x40000000;

NOTE_FFOR

or fflags

pub const NOTE_FFOR = 0x80000000;

NOTE_FFCOPY

copy fflags

pub const NOTE_FFCOPY = 0xc0000000;

NOTE_FFCTRLMASK

mask for operations

pub const NOTE_FFCTRLMASK = 0xc0000000;

NOTE_FFLAGSMASK

pub const NOTE_FFLAGSMASK = 0x00ffffff;

NOTE_LOWAT

low water mark

pub const NOTE_LOWAT = 0x00000001;

NOTE_FILE_POLL

behave like poll()

pub const NOTE_FILE_POLL = 0x00000002;

NOTE_DELETE

vnode was removed

pub const NOTE_DELETE = 0x00000001;

NOTE_WRITE

data contents changed

pub const NOTE_WRITE = 0x00000002;

NOTE_EXTEND

size increased

pub const NOTE_EXTEND = 0x00000004;

NOTE_ATTRIB

attributes changed

pub const NOTE_ATTRIB = 0x00000008;

NOTE_LINK

link count changed

pub const NOTE_LINK = 0x00000010;

NOTE_RENAME

vnode was renamed

pub const NOTE_RENAME = 0x00000020;

NOTE_REVOKE

vnode access was revoked

pub const NOTE_REVOKE = 0x00000040;

NOTE_OPEN

vnode was opened

pub const NOTE_OPEN = 0x00000080;

NOTE_CLOSE

file closed, fd did not allow write

pub const NOTE_CLOSE = 0x00000100;

NOTE_CLOSE_WRITE

file closed, fd did allow write

pub const NOTE_CLOSE_WRITE = 0x00000200;

NOTE_READ

file was read

pub const NOTE_READ = 0x00000400;

NOTE_EXIT

process exited

pub const NOTE_EXIT = 0x80000000;

NOTE_FORK

process forked

pub const NOTE_FORK = 0x40000000;

NOTE_EXEC

process exec'd

pub const NOTE_EXEC = 0x20000000;

NOTE_PDATAMASK

mask for signal & exit status

pub const NOTE_PDATAMASK = 0x000fffff;

NOTE_PCTRLMASK

pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);

NOTE_SECONDS

data is seconds

pub const NOTE_SECONDS = 0x00000001;

NOTE_MSECONDS

data is milliseconds

pub const NOTE_MSECONDS = 0x00000002;

NOTE_USECONDS

data is microseconds

pub const NOTE_USECONDS = 0x00000004;

NOTE_NSECONDS

data is nanoseconds

pub const NOTE_NSECONDS = 0x00000008;

NOTE_ABSTIME

timeout is absolute

pub const NOTE_ABSTIME = 0x00000010;

T

pub const T = struct {
    pub const IOCEXCL = 0x2000740d;
    pub const IOCNXCL = 0x2000740e;
    pub const IOCSCTTY = 0x20007461;
    pub const IOCGPGRP = 0x40047477;
    pub const IOCSPGRP = 0x80047476;
    pub const IOCOUTQ = 0x40047473;
    pub const IOCSTI = 0x80017472;
    pub const IOCGWINSZ = 0x40087468;
    pub const IOCSWINSZ = 0x80087467;
    pub const IOCMGET = 0x4004746a;
    pub const IOCMBIS = 0x8004746c;
    pub const IOCMBIC = 0x8004746b;
    pub const IOCMSET = 0x8004746d;
    pub const FIONREAD = 0x4004667f;
    pub const IOCCONS = 0x80047462;
    pub const IOCPKT = 0x80047470;
    pub const FIONBIO = 0x8004667e;
    pub const IOCNOTTY = 0x20007471;
    pub const IOCSETD = 0x8004741b;
    pub const IOCGETD = 0x4004741a;
    pub const IOCSBRK = 0x2000747b;
    pub const IOCCBRK = 0x2000747a;
    pub const IOCGSID = 0x40047463;
    pub const IOCGPTN = 0x4004740f;
    pub const IOCSIG = 0x2004745f;
};

winsize

pub const winsize = extern struct {
    ws_row: u16,
    ws_col: u16,
    ws_xpixel: u16,
    ws_ypixel: u16,
};

const NSIG = 32;

Sigaction

Renamed from sigaction to Sigaction to avoid conflict with the syscall.

pub const Sigaction = extern struct {
    pub const handler_fn = *const fn (c_int) align(1) callconv(.C) void;
    pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;

    handler: extern union {
        handler: ?handler_fn,
        sigaction: ?sigaction_fn,
    },

    flags: c_uint,

    mask: sigset_t,
};

siginfo_t

signal handler see signal options signal mask to apply

pub const siginfo_t = extern struct {
    // Signal number.
    signo: c_int,
    // Errno association.
    errno: c_int,
    code: c_int,
    pid: pid_t,
    uid: uid_t,
    status: c_int,
    addr: ?*anyopaque,
    value: sigval,
    reason: extern union {
        fault: extern struct {
            trapno: c_int,
        },
        timer: extern struct {
            timerid: c_int,
            overrun: c_int,
        },
        mesgq: extern struct {
            mqd: c_int,
        },
        poll: extern struct {
            band: c_long,
        },
        spare: extern struct {
            spare1: c_long,
            spare2: [7]c_int,
        },
    },
};

mcontext_t

Signal code.

Cause of signal, one of the SI_ macros or signal-specific values, i.e. one of the FPE_... values for SIGFPE. This value is equivalent to the second argument to an old-style FreeBSD signal handler. Sending process. Sender's ruid. Exit value. Faulting instruction. Signal value. Machine specific trap code. Band event for SIGPOLL. UNUSED.

pub const mcontext_t = switch (builtin.cpu.arch) {
    .x86_64 => extern struct {
        onstack: u64,
        rdi: u64,
        rsi: u64,
        rdx: u64,
        rcx: u64,
        r8: u64,
        r9: u64,
        rax: u64,
        rbx: u64,
        rbp: u64,
        r10: u64,
        r11: u64,
        r12: u64,
        r13: u64,
        r14: u64,
        r15: u64,
        trapno: u32,
        fs: u16,
        gs: u16,
        addr: u64,
        flags: u32,
        es: u16,
        ds: u16,
        err: u64,
        rip: u64,
        cs: u64,
        rflags: u64,
        rsp: u64,
        ss: u64,
        len: u64,
        fpformat: u64,
        ownedfp: u64,
        fpstate: [64]u64 align(16),
        fsbase: u64,
        gsbase: u64,
        xfpustate: u64,
        xfpustate_len: u64,
        spare: [4]u64,
    },
    .aarch64 => extern struct {
        gpregs: extern struct {
            x: [30]u64,
            lr: u64,
            sp: u64,
            elr: u64,
            spsr: u32,
            _pad: u32,
        },
        fpregs: extern struct {
            q: [32]u128,
            sr: u32,
            cr: u32,
            flags: u32,
            _pad: u32,
        },
        flags: u32,
        _pad: u32,
        _spare: [8]u64,
    },
    else => struct {},
};

REG

pub const REG = switch (builtin.cpu.arch) {
    .aarch64 => struct {
        pub const FP = 29;
        pub const SP = 31;
        pub const PC = 32;
    },
    .arm => struct {
        pub const FP = 11;
        pub const SP = 13;
        pub const PC = 15;
    },
    .x86_64 => struct {
        pub const RBP = 12;
        pub const RIP = 21;
        pub const RSP = 24;
    },
    else => struct {},
};

ucontext_t

pub const ucontext_t = extern struct {
    sigmask: sigset_t,
    mcontext: mcontext_t,
    link: ?*ucontext_t,
    stack: stack_t,
    flags: c_int,
    __spare__: [4]c_int,
};

E

pub const E = enum(u16) {
    SUCCESS = 0,

    PERM = 1, // Operation not permitted
    NOENT = 2, // No such file or directory
    SRCH = 3, // No such process
    INTR = 4, // Interrupted system call
    IO = 5, // Input/output error
    NXIO = 6, // Device not configured
    @"2BIG" = 7, // Argument list too long
    NOEXEC = 8, // Exec format error
    BADF = 9, // Bad file descriptor
    CHILD = 10, // No child processes
    DEADLK = 11, // Resource deadlock avoided
    // 11 was AGAIN
    NOMEM = 12, // Cannot allocate memory
    ACCES = 13, // Permission denied
    FAULT = 14, // Bad address
    NOTBLK = 15, // Block device required
    BUSY = 16, // Device busy
    EXIST = 17, // File exists
    XDEV = 18, // Cross-device link
    NODEV = 19, // Operation not supported by device
    NOTDIR = 20, // Not a directory
    ISDIR = 21, // Is a directory
    INVAL = 22, // Invalid argument
    NFILE = 23, // Too many open files in system
    MFILE = 24, // Too many open files
    NOTTY = 25, // Inappropriate ioctl for device
    TXTBSY = 26, // Text file busy
    FBIG = 27, // File too large
    NOSPC = 28, // No space left on device
    SPIPE = 29, // Illegal seek
    ROFS = 30, // Read-only filesystem
    MLINK = 31, // Too many links
    PIPE = 32, // Broken pipe

    // math software
    DOM = 33, // Numerical argument out of domain
    RANGE = 34, // Result too large

    // non-blocking and interrupt i/o

    AGAIN = 35,
    INPROGRESS = 36, // Operation now in progress
    ALREADY = 37, // Operation already in progress

    // ipc/network software -- argument errors
    NOTSOCK = 38, // Socket operation on non-socket
    DESTADDRREQ = 39, // Destination address required
    MSGSIZE = 40, // Message too long
    PROTOTYPE = 41, // Protocol wrong type for socket
    NOPROTOOPT = 42, // Protocol not available
    PROTONOSUPPORT = 43, // Protocol not supported
    SOCKTNOSUPPORT = 44, // Socket type not supported
    OPNOTSUPP = 45,
    PFNOSUPPORT = 46, // Protocol family not supported
    AFNOSUPPORT = 47, // Address family not supported by protocol family
    ADDRINUSE = 48, // Address already in use
    ADDRNOTAVAIL = 49, // Can't assign requested address

    // ipc/network software -- operational errors
    NETDOWN = 50, // Network is down
    NETUNREACH = 51, // Network is unreachable
    NETRESET = 52, // Network dropped connection on reset
    CONNABORTED = 53, // Software caused connection abort
    CONNRESET = 54, // Connection reset by peer
    NOBUFS = 55, // No buffer space available
    ISCONN = 56, // Socket is already connected
    NOTCONN = 57, // Socket is not connected
    SHUTDOWN = 58, // Can't send after socket shutdown
    TOOMANYREFS = 59, // Too many references: can't splice
    TIMEDOUT = 60, // Operation timed out
    CONNREFUSED = 61, // Connection refused

    LOOP = 62, // Too many levels of symbolic links
    NAMETOOLONG = 63, // File name too long

    // should be rearranged
    HOSTDOWN = 64, // Host is down
    HOSTUNREACH = 65, // No route to host
    NOTEMPTY = 66, // Directory not empty

    // quotas & mush
    PROCLIM = 67, // Too many processes
    USERS = 68, // Too many users
    DQUOT = 69, // Disc quota exceeded

    // Network File System
    STALE = 70, // Stale NFS file handle
    REMOTE = 71, // Too many levels of remote in path
    BADRPC = 72, // RPC struct is bad
    RPCMISMATCH = 73, // RPC version wrong
    PROGUNAVAIL = 74, // RPC prog. not avail
    PROGMISMATCH = 75, // Program version wrong
    PROCUNAVAIL = 76, // Bad procedure for program

    NOLCK = 77, // No locks available
    NOSYS = 78, // Function not implemented

    FTYPE = 79, // Inappropriate file type or format
    AUTH = 80, // Authentication error
    NEEDAUTH = 81, // Need authenticator
    IDRM = 82, // Identifier removed
    NOMSG = 83, // No message of desired type
    OVERFLOW = 84, // Value too large to be stored in data type
    CANCELED = 85, // Operation canceled
    ILSEQ = 86, // Illegal byte sequence
    NOATTR = 87, // Attribute not found

    DOOFUS = 88, // Programming error

    BADMSG = 89, // Bad message
    MULTIHOP = 90, // Multihop attempted
    NOLINK = 91, // Link has been severed
    PROTO = 92, // Protocol error

    NOTCAPABLE = 93, // Capabilities insufficient
    CAPMODE = 94, // Not permitted in capability mode
    NOTRECOVERABLE = 95, // State not recoverable
    OWNERDEAD = 96, // Previous owner died
    INTEGRITY = 97, // Integrity check failed
    _,
};

MINSIGSTKSZ

No error occurred. Resource temporarily unavailable This code is also used for WOULDBLOCK: operation would block. Operation not supported This code is also used for NOTSUP.

pub const MINSIGSTKSZ = switch (builtin.cpu.arch) {
    .x86, .x86_64 => 2048,
    .arm, .aarch64 => 4096,
    else => @compileError("MINSIGSTKSZ not defined for this architecture"),
};

SIGSTKSZ

pub const SIGSTKSZ = MINSIGSTKSZ + 32768;

SS_ONSTACK

pub const SS_ONSTACK = 1;

SS_DISABLE

pub const SS_DISABLE = 4;

stack_t

pub const stack_t = extern struct {
    sp: *anyopaque,
    size: usize,
    flags: i32,
};

S

Signal stack base. Signal stack length. SS_DISABLE and/or SS_ONSTACK.

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 ISUID = 0o4000;
    pub const ISGID = 0o2000;
    pub const ISVTX = 0o1000;
    pub const IRWXU = 0o700;
    pub const IRUSR = 0o400;
    pub const IWUSR = 0o200;
    pub const IXUSR = 0o100;
    pub const IRWXG = 0o070;
    pub const IRGRP = 0o040;
    pub const IWGRP = 0o020;
    pub const IXGRP = 0o010;
    pub const IRWXO = 0o007;
    pub const IROTH = 0o004;
    pub const IWOTH = 0o002;
    pub const IXOTH = 0o001;

ISFIFO()

    pub fn ISFIFO(m: u32) bool {
        return m & IFMT == IFIFO;
    }

ISCHR()

    pub fn ISCHR(m: u32) bool {
        return m & IFMT == IFCHR;
    }

ISDIR()

    pub fn ISDIR(m: u32) bool {
        return m & IFMT == IFDIR;
    }

ISBLK()

    pub fn ISBLK(m: u32) bool {
        return m & IFMT == IFBLK;
    }

ISREG()

    pub fn ISREG(m: u32) bool {
        return m & IFMT == IFREG;
    }

ISLNK()

    pub fn ISLNK(m: u32) bool {
        return m & IFMT == IFLNK;
    }

ISSOCK()

    pub fn ISSOCK(m: u32) bool {
        return m & IFMT == IFSOCK;
    }

IWHT()

    pub fn IWHT(m: u32) bool {
        return m & IFMT == IFWHT;
    }
};

HOST_NAME_MAX

pub const HOST_NAME_MAX = 255;

AT

pub const AT = struct {
    pub const FDCWD = -100;
    pub const EACCESS = 0x0100;
    pub const SYMLINK_NOFOLLOW = 0x0200;
    pub const SYMLINK_FOLLOW = 0x0400;
    pub const REMOVEDIR = 0x0800;
    pub const BENEATH = 0x1000;
};

addrinfo

Magic value that specify the use of the current working directory to determine the target of relative file paths in the openat() and similar syscalls. Check access using effective user and group ID Do not follow symbolic links Follow symbolic link Remove directory instead of file Fail if not under dirfd

pub const addrinfo = extern struct {
    flags: i32,
    family: i32,
    socktype: i32,
    protocol: i32,
    addrlen: socklen_t,
    canonname: ?[*:0]u8,
    addr: ?*sockaddr,
    next: ?*addrinfo,
};

IPPROTO

pub const IPPROTO = struct {
    pub const IP = 0;
    pub const ICMP = 1;
    pub const TCP = 6;
    pub const UDP = 17;
    pub const IPV6 = 41;
    pub const RAW = 255;
    pub const HOPOPTS = 0;
    pub const IGMP = 2;
    pub const GGP = 3;
    pub const IPV4 = 4;
    pub const IPIP = IPV4;
    pub const ST = 7;
    pub const EGP = 8;
    pub const PIGP = 9;
    pub const RCCMON = 10;
    pub const NVPII = 11;
    pub const PUP = 12;
    pub const ARGUS = 13;
    pub const EMCON = 14;
    pub const XNET = 15;
    pub const CHAOS = 16;
    pub const MUX = 18;
    pub const MEAS = 19;
    pub const HMP = 20;
    pub const PRM = 21;
    pub const IDP = 22;
    pub const TRUNK1 = 23;
    pub const TRUNK2 = 24;
    pub const LEAF1 = 25;
    pub const LEAF2 = 26;
    pub const RDP = 27;
    pub const IRTP = 28;
    pub const TP = 29;
    pub const BLT = 30;
    pub const NSP = 31;
    pub const INP = 32;
    pub const DCCP = 33;
    pub const @"3PC" = 34;
    pub const IDPR = 35;
    pub const XTP = 36;
    pub const DDP = 37;
    pub const CMTP = 38;
    pub const TPXX = 39;
    pub const IL = 40;
    pub const SDRP = 42;
    pub const ROUTING = 43;
    pub const FRAGMENT = 44;
    pub const IDRP = 45;
    pub const RSVP = 46;
    pub const GRE = 47;
    pub const MHRP = 48;
    pub const BHA = 49;
    pub const ESP = 50;
    pub const AH = 51;
    pub const INLSP = 52;
    pub const SWIPE = 53;
    pub const NHRP = 54;
    pub const MOBILE = 55;
    pub const TLSP = 56;
    pub const SKIP = 57;
    pub const ICMPV6 = 58;
    pub const NONE = 59;
    pub const DSTOPTS = 60;
    pub const AHIP = 61;
    pub const CFTP = 62;
    pub const HELLO = 63;
    pub const SATEXPAK = 64;
    pub const KRYPTOLAN = 65;
    pub const RVD = 66;
    pub const IPPC = 67;
    pub const ADFS = 68;
    pub const SATMON = 69;
    pub const VISA = 70;
    pub const IPCV = 71;
    pub const CPNX = 72;
    pub const CPHB = 73;
    pub const WSN = 74;
    pub const PVP = 75;
    pub const BRSATMON = 76;
    pub const ND = 77;
    pub const WBMON = 78;
    pub const WBEXPAK = 79;
    pub const EON = 80;
    pub const VMTP = 81;
    pub const SVMTP = 82;
    pub const VINES = 83;
    pub const TTP = 84;
    pub const IGP = 85;
    pub const DGP = 86;
    pub const TCF = 87;
    pub const IGRP = 88;
    pub const OSPFIGP = 89;
    pub const SRPC = 90;
    pub const LARP = 91;
    pub const MTP = 92;
    pub const AX25 = 93;
    pub const IPEIP = 94;
    pub const MICP = 95;
    pub const SCCSP = 96;
    pub const ETHERIP = 97;
    pub const ENCAP = 98;
    pub const APES = 99;
    pub const GMTP = 100;
    pub const IPCOMP = 108;
    pub const SCTP = 132;
    pub const MH = 135;
    pub const UDPLITE = 136;
    pub const HIP = 139;
    pub const SHIM6 = 140;
    pub const PIM = 103;
    pub const CARP = 112;
    pub const PGM = 113;
    pub const MPLS = 137;
    pub const PFSYNC = 240;
    pub const RESERVED_253 = 253;
    pub const RESERVED_254 = 254;
};

rlimit_resource

dummy for IP control message protocol tcp user datagram protocol IP6 header raw IP packet IP6 hop-by-hop options group mgmt protocol gateway^2 (deprecated) IPv4 encapsulation for compatibility Stream protocol II exterior gateway protocol private interior gateway BBN RCC Monitoring network voice protocol pup Argus EMCON Cross Net Debugger Chaos Multiplexing DCN Measurement Subsystems Host Monitoring Packet Radio Measurement xns idp Trunk-1 Trunk-2 Leaf-1 Leaf-2 Reliable Data Reliable Transaction tp-4 w/ class negotiation Bulk Data Transfer Network Services Merit Internodal Datagram Congestion Control Protocol Third Party Connect InterDomain Policy Routing XTP Datagram Delivery Control Message Transport TP++ Transport IL transport protocol Source Demand Routing IP6 routing header IP6 fragmentation header InterDomain Routing resource reservation General Routing Encap. Mobile Host Routing BHA IP6 Encap Sec. Payload IP6 Auth Header Integ. Net Layer Security IP with encryption Next Hop Resolution IP Mobility Transport Layer Security SKIP ICMP6 IP6 no next header IP6 destination option any host internal protocol CFTP "hello" routing protocol SATNET/Backroom EXPAK Kryptolan Remote Virtual Disk Pluribus Packet Core Any distributed FS Satnet Monitoring VISA Protocol Packet Core Utility Comp. Prot. Net. Executive Comp. Prot. HeartBeat Wang Span Network Packet Video Protocol BackRoom SATNET Monitoring Sun net disk proto (temp.) WIDEBAND Monitoring WIDEBAND EXPAK ISO cnlp VMTP Secure VMTP Banyon VINES TTP NSFNET-IGP dissimilar gateway prot. TCF Cisco/GXS IGRP OSPFIGP Strite RPC protocol Locus Address Resoloution Multicast Transport AX.25 Frames IP encapsulated in IP Mobile Int.ing control Semaphore Comm. security Ethernet IP encapsulation encapsulation header any private encr. scheme GMTP payload compression (IPComp) SCTP IPv6 Mobility Header UDP-Lite IP6 Host Identity Protocol IP6 Shim6 Protocol Protocol Independent Mcast CARP PGM MPLS-in-IP PFSYNC Reserved Reserved

pub const rlimit_resource = enum(c_int) {
    CPU = 0,
    FSIZE = 1,
    DATA = 2,
    STACK = 3,
    CORE = 4,
    RSS = 5,
    MEMLOCK = 6,
    NPROC = 7,
    NOFILE = 8,
    SBSIZE = 9,
    VMEM = 10,
    NPTS = 11,
    SWAP = 12,
    KQUEUES = 13,
    UMTXP = 14,
    _,

    pub const AS: rlimit_resource = .VMEM;
};

rlim_t

pub const rlim_t = i64;

RLIM

pub const RLIM = struct {
    pub const INFINITY: rlim_t = (1 << 63) - 1;

    pub const SAVED_MAX = INFINITY;
    pub const SAVED_CUR = INFINITY;
};

rlimit

No limit

pub const rlimit = extern struct {
    cur: rlim_t,
    max: rlim_t,
};

SHUT

Soft limit Hard limit

pub const SHUT = struct {
    pub const RD = 0;
    pub const WR = 1;
    pub const RDWR = 2;
};

nfds_t

pub const nfds_t = u32;

pollfd

pub const pollfd = extern struct {
    fd: fd_t,
    events: i16,
    revents: i16,
};

POLL

pub const POLL = struct {
    pub const IN = 0x0001;
    pub const PRI = 0x0002;
    pub const OUT = 0x0004;
    pub const RDNORM = 0x0040;
    pub const WRNORM = OUT;
    pub const RDBAND = 0x0080;
    pub const WRBAND = 0x0100;
    pub const INIGNEOF = 0x2000;
    pub const ERR = 0x0008;
    pub const HUP = 0x0010;
    pub const NVAL = 0x0020;

    pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
};

NAME_MAX

any readable data available. OOB/Urgent readable data. file descriptor is writeable. non-OOB/URG data available. no write type differentiation. OOB/Urgent readable data. OOB/Urgent data can be written. like IN, except ignore EOF. some poll error occurred. file descriptor was "hung up". requested events "invalid".

pub const NAME_MAX = 255;

MFD

pub const MFD = struct {
    pub const CLOEXEC = 0x0001;
    pub const ALLOW_SEALING = 0x0002;
};

pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;
pub extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*off_t, fd_out: fd_t, off_out: ?*off_t, len: usize, flags: u32) usize;