| ... | @@ -0,0 +1,1216 @@ |
| 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); |
| 3 | const arch = builtin.target.cpu.arch; |
| 4 | |
| 5 | comptime { |
| 6 | std.debug.assert(builtin.target.os.tag == .freebsd); |
| 7 | std.debug.assert(@bitSizeOf(usize) == 64); |
| 8 | } |
| 9 | |
| 10 | pub const errno = struct { |
| 11 | pub const Error = error{ |
| 12 | Unexpected, |
| 13 | EPERM, |
| 14 | ENOENT, |
| 15 | ESRCH, |
| 16 | EINTR, |
| 17 | EIO, |
| 18 | ENXIO, |
| 19 | E2BIG, |
| 20 | ENOEXEC, |
| 21 | EBADF, |
| 22 | ECHILD, |
| 23 | EDEADLK, |
| 24 | ENOMEM, |
| 25 | EACCES, |
| 26 | EFAULT, |
| 27 | ENOTBLK, |
| 28 | EBUSY, |
| 29 | EEXIST, |
| 30 | EXDEV, |
| 31 | ENODEV, |
| 32 | ENOTDIR, |
| 33 | EISDIR, |
| 34 | EINVAL, |
| 35 | ENFILE, |
| 36 | EMFILE, |
| 37 | ENOTTY, |
| 38 | ETXTBSY, |
| 39 | EFBIG, |
| 40 | ENOSPC, |
| 41 | ESPIPE, |
| 42 | EROFS, |
| 43 | EMLINK, |
| 44 | EPIPE, |
| 45 | EDOM, |
| 46 | ERANGE, |
| 47 | EAGAIN, |
| 48 | EINPROGRESS, |
| 49 | EALREADY, |
| 50 | ENOTSOCK, |
| 51 | EDESTADDRREQ, |
| 52 | EMSGSIZE, |
| 53 | EPROTOTYPE, |
| 54 | ENOPROTOOPT, |
| 55 | EPROTONOSUPPORT, |
| 56 | ESOCKTNOSUPPORT, |
| 57 | EOPNOTSUPP, |
| 58 | EPFNOSUPPORT, |
| 59 | EAFNOSUPPORT, |
| 60 | EADDRINUSE, |
| 61 | EADDRNOTAVAIL, |
| 62 | ENETDOWN, |
| 63 | ENETUNREACH, |
| 64 | ENETRESET, |
| 65 | ECONNABORTED, |
| 66 | ECONNRESET, |
| 67 | ENOBUFS, |
| 68 | EISCONN, |
| 69 | ENOTCONN, |
| 70 | ESHUTDOWN, |
| 71 | ETOOMANYREFS, |
| 72 | ETIMEDOUT, |
| 73 | ECONNREFUSED, |
| 74 | ELOOP, |
| 75 | ENAMETOOLONG, |
| 76 | EHOSTDOWN, |
| 77 | EHOSTUNREACH, |
| 78 | ENOTEMPTY, |
| 79 | EPROCLIM, |
| 80 | EUSERS, |
| 81 | EDQUOT, |
| 82 | ESTALE, |
| 83 | EREMOTE, |
| 84 | EBADRPC, |
| 85 | ERPCMISMATCH, |
| 86 | EPROGUNAVAIL, |
| 87 | EPROGMISMATCH, |
| 88 | EPROCUNAVAIL, |
| 89 | ENOLCK, |
| 90 | ENOSYS, |
| 91 | EFTYPE, |
| 92 | EAUTH, |
| 93 | ENEEDAUTH, |
| 94 | EIDRM, |
| 95 | ENOMSG, |
| 96 | EOVERFLOW, |
| 97 | ECANCELED, |
| 98 | EILSEQ, |
| 99 | ENOATTR, |
| 100 | EDOOFUS, |
| 101 | EBADMSG, |
| 102 | EMULTIHOP, |
| 103 | ENOLINK, |
| 104 | EPROTO, |
| 105 | ENOTCAPABLE, |
| 106 | ECAPMODE, |
| 107 | ENOTRECOVERABLE, |
| 108 | EOWNERDEAD, |
| 109 | EINTEGRITY, |
| 110 | }; |
| 111 | |
| 112 | pub const Enum = enum(c_ushort) { |
| 113 | EPERM = 1, |
| 114 | ENOENT = 2, |
| 115 | ESRCH = 3, |
| 116 | EINTR = 4, |
| 117 | EIO = 5, |
| 118 | ENXIO = 6, |
| 119 | E2BIG = 7, |
| 120 | ENOEXEC = 8, |
| 121 | EBADF = 9, |
| 122 | ECHILD = 10, |
| 123 | EDEADLK = 11, |
| 124 | ENOMEM = 12, |
| 125 | EACCES = 13, |
| 126 | EFAULT = 14, |
| 127 | ENOTBLK = 15, |
| 128 | EBUSY = 16, |
| 129 | EEXIST = 17, |
| 130 | EXDEV = 18, |
| 131 | ENODEV = 19, |
| 132 | ENOTDIR = 20, |
| 133 | EISDIR = 21, |
| 134 | EINVAL = 22, |
| 135 | ENFILE = 23, |
| 136 | EMFILE = 24, |
| 137 | ENOTTY = 25, |
| 138 | ETXTBSY = 26, |
| 139 | EFBIG = 27, |
| 140 | ENOSPC = 28, |
| 141 | ESPIPE = 29, |
| 142 | EROFS = 30, |
| 143 | EMLINK = 31, |
| 144 | EPIPE = 32, |
| 145 | EDOM = 33, |
| 146 | ERANGE = 34, |
| 147 | EAGAIN = 35, |
| 148 | EINPROGRESS = 36, |
| 149 | EALREADY = 37, |
| 150 | ENOTSOCK = 38, |
| 151 | EDESTADDRREQ = 39, |
| 152 | EMSGSIZE = 40, |
| 153 | EPROTOTYPE = 41, |
| 154 | ENOPROTOOPT = 42, |
| 155 | EPROTONOSUPPORT = 43, |
| 156 | ESOCKTNOSUPPORT = 44, |
| 157 | EOPNOTSUPP = 45, |
| 158 | EPFNOSUPPORT = 46, |
| 159 | EAFNOSUPPORT = 47, |
| 160 | EADDRINUSE = 48, |
| 161 | EADDRNOTAVAIL = 49, |
| 162 | ENETDOWN = 50, |
| 163 | ENETUNREACH = 51, |
| 164 | ENETRESET = 52, |
| 165 | ECONNABORTED = 53, |
| 166 | ECONNRESET = 54, |
| 167 | ENOBUFS = 55, |
| 168 | EISCONN = 56, |
| 169 | ENOTCONN = 57, |
| 170 | ESHUTDOWN = 58, |
| 171 | ETOOMANYREFS = 59, |
| 172 | ETIMEDOUT = 60, |
| 173 | ECONNREFUSED = 61, |
| 174 | ELOOP = 62, |
| 175 | ENAMETOOLONG = 63, |
| 176 | EHOSTDOWN = 64, |
| 177 | EHOSTUNREACH = 65, |
| 178 | ENOTEMPTY = 66, |
| 179 | EPROCLIM = 67, |
| 180 | EUSERS = 68, |
| 181 | EDQUOT = 69, |
| 182 | ESTALE = 70, |
| 183 | EREMOTE = 71, |
| 184 | EBADRPC = 72, |
| 185 | ERPCMISMATCH = 73, |
| 186 | EPROGUNAVAIL = 74, |
| 187 | EPROGMISMATCH = 75, |
| 188 | EPROCUNAVAIL = 76, |
| 189 | ENOLCK = 77, |
| 190 | ENOSYS = 78, |
| 191 | EFTYPE = 79, |
| 192 | EAUTH = 80, |
| 193 | ENEEDAUTH = 81, |
| 194 | EIDRM = 82, |
| 195 | ENOMSG = 83, |
| 196 | EOVERFLOW = 84, |
| 197 | ECANCELED = 85, |
| 198 | EILSEQ = 86, |
| 199 | ENOATTR = 87, |
| 200 | EDOOFUS = 88, |
| 201 | EBADMSG = 89, |
| 202 | EMULTIHOP = 90, |
| 203 | ENOLINK = 91, |
| 204 | EPROTO = 92, |
| 205 | ENOTCAPABLE = 93, |
| 206 | ECAPMODE = 94, |
| 207 | ENOTRECOVERABLE = 95, |
| 208 | EOWNERDEAD = 96, |
| 209 | EINTEGRITY = 97, |
| 210 | |
| 211 | pub const EWOULDBLOCK: Enum = .EAGAIN; |
| 212 | pub const ENOTSUP: Enum = .EOPNOTSUPP; |
| 213 | }; |
| 214 | |
| 215 | comptime { |
| 216 | // assert Enum is sequential |
| 217 | var value: c_ushort = 0; // SUCCESS |
| 218 | for (std.enums.values(Enum)) |val| { |
| 219 | std.debug.assert(@intFromEnum(val) > value); |
| 220 | value = @intFromEnum(val); |
| 221 | } |
| 222 | } |
| 223 | comptime { |
| 224 | // sanity test |
| 225 | std.debug.assert(@intFromEnum(Enum.EPERM) == 1); |
| 226 | } |
| 227 | const list = blk: { |
| 228 | const values = std.enums.values(Enum); |
| 229 | const len = @intFromEnum(values[values.len - 1]) + 1; |
| 230 | var errors: [len]Error = @splat(error.Unexpected); |
| 231 | for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f)); |
| 232 | const final = errors; |
| 233 | break :blk final; |
| 234 | }; |
| 235 | pub fn fromInt(code: c_int) Error { |
| 236 | @setRuntimeSafety(false); |
| 237 | if (code >= list.len) return error.Unexpected; |
| 238 | if (code <= 0) return error.Unexpected; |
| 239 | return list[@intCast(code)]; |
| 240 | } |
| 241 | pub fn fromLibC() c_int { |
| 242 | return libc.__error().*; |
| 243 | } |
| 244 | }; |
| 245 | |
| 246 | pub const eai = struct { |
| 247 | pub const Error = error{ |
| 248 | EAI_ADDRFAMILY, |
| 249 | EAI_AGAIN, |
| 250 | EAI_BADFLAGS, |
| 251 | EAI_FAIL, |
| 252 | EAI_FAMILY, |
| 253 | EAI_MEMORY, |
| 254 | EAI_NODATA, |
| 255 | EAI_NONAME, |
| 256 | EAI_SERVICE, |
| 257 | EAI_SOCKTYPE, |
| 258 | EAI_SYSTEM, |
| 259 | EAI_BADHINTS, |
| 260 | EAI_PROTOCOL, |
| 261 | EAI_OVERFLOW, |
| 262 | }; |
| 263 | |
| 264 | pub const Enum = enum(c_int) { |
| 265 | EAI_ADDRFAMILY = 1, |
| 266 | EAI_AGAIN = 2, |
| 267 | EAI_BADFLAGS = 3, |
| 268 | EAI_FAIL = 4, |
| 269 | EAI_FAMILY = 5, |
| 270 | EAI_MEMORY = 6, |
| 271 | EAI_NODATA = 7, |
| 272 | EAI_NONAME = 8, |
| 273 | EAI_SERVICE = 9, |
| 274 | EAI_SOCKTYPE = 10, |
| 275 | EAI_SYSTEM = 11, |
| 276 | EAI_BADHINTS = 12, |
| 277 | EAI_PROTOCOL = 13, |
| 278 | EAI_OVERFLOW = 14, |
| 279 | }; |
| 280 | |
| 281 | pub fn fromInt(code: c_int) Error { |
| 282 | return switch (@as(Enum, @enumFromInt(code))) { |
| 283 | .EAI_ADDRFAMILY => error.EAI_ADDRFAMILY, |
| 284 | .EAI_AGAIN => error.EAI_AGAIN, |
| 285 | .EAI_BADFLAGS => error.EAI_BADFLAGS, |
| 286 | .EAI_FAIL => error.EAI_FAIL, |
| 287 | .EAI_FAMILY => error.EAI_FAMILY, |
| 288 | .EAI_MEMORY => error.EAI_MEMORY, |
| 289 | .EAI_NODATA => error.EAI_NODATA, |
| 290 | .EAI_NONAME => error.EAI_NONAME, |
| 291 | .EAI_SERVICE => error.EAI_SERVICE, |
| 292 | .EAI_SOCKTYPE => error.EAI_SOCKTYPE, |
| 293 | .EAI_SYSTEM => error.EAI_SYSTEM, |
| 294 | .EAI_BADHINTS => error.EAI_BADHINTS, |
| 295 | .EAI_PROTOCOL => error.EAI_PROTOCOL, |
| 296 | .EAI_OVERFLOW => error.EAI_OVERFLOW, |
| 297 | }; |
| 298 | } |
| 299 | }; |
| 300 | |
| 301 | pub const libc = struct { |
| 302 | pub extern fn __error() *c_int; |
| 303 | pub extern fn pipe2(pipefd: *[2]c_int, flag: c_int) c_int; |
| 304 | pub extern fn openat(fd: c_int, file: [*:0]const u8, oflag: c_int, ...) c_int; |
| 305 | pub extern fn close(fildes: c_int) c_int; |
| 306 | pub extern fn fork() pid_t; |
| 307 | pub extern fn dup2(fildes: c_int, fildes2: c_int) c_int; |
| 308 | pub extern fn _exit(status: c_int) noreturn; |
| 309 | pub extern fn fchdir(fildes: c_int) c_int; |
| 310 | pub extern fn execvp(file: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int; |
| 311 | pub extern fn kill(pid: pid_t, sig: c_int) c_int; |
| 312 | pub extern fn poll(fds: [*]struct_pollfd, nfds: nfds_t, timeout: c_int) c_int; |
| 313 | pub extern fn read(fd: c_int, buf: [*]u8, count: usize) isize; |
| 314 | pub extern fn write(fd: c_int, buf: *const anyopaque, n: usize) isize; |
| 315 | pub extern fn waitpid(pid: pid_t, stat_loc: ?*c_int, options: c_int) pid_t; |
| 316 | pub extern fn getenv(name: [*:0]const u8) ?[*:0]u8; |
| 317 | pub extern fn exit(status: c_int) noreturn; |
| 318 | pub extern fn mkdirat(fd: c_int, path: [*:0]const u8, mode: mode_t) c_int; |
| 319 | pub extern fn fstatat(fd: c_int, noalias path: [*:0]const u8, noalias buf: *struct_stat, flag: c_int) c_int; |
| 320 | pub extern fn getaddrinfo(noalias nodename: ?[*:0]const u8, noalias servname: ?[*:0]const u8, noalias hints: ?*const struct_addrinfo, noalias res: **const struct_addrinfo) c_int; |
| 321 | pub extern fn freeaddrinfo(ai: *const struct_addrinfo) void; |
| 322 | pub extern fn socket(domain: c_int, type: c_int, protocol: c_int) c_int; |
| 323 | pub extern fn connect(socket: c_int, address: *const struct_sockaddr, address_len: socklen_t) c_int; |
| 324 | pub extern fn getrandom(buf: [*]u8, size: usize, flags: c_uint) isize; |
| 325 | pub extern fn arc4random_buf(buf: [*]u8, n: usize) void; |
| 326 | pub extern fn pthread_mutex_init(mutex: *pthread_mutex_t, attr: ?*const pthread_mutexattr_t) c_int; |
| 327 | pub extern fn pthread_mutex_destroy(mutex: *pthread_mutex_t) c_int; |
| 328 | pub extern fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int; |
| 329 | pub extern fn pthread_mutex_trylock(mutex: *pthread_mutex_t) c_int; |
| 330 | pub extern fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int; |
| 331 | pub extern fn pthread_cond_init(noalias cond: *pthread_cond_t, noalias attr: ?*const pthread_condattr_t) c_int; |
| 332 | pub extern fn pthread_cond_destroy(cond: *pthread_cond_t) c_int; |
| 333 | pub extern fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) c_int; |
| 334 | pub extern fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const struct_timespec) c_int; |
| 335 | pub extern fn pthread_cond_signal(cond: *pthread_cond_t) c_int; |
| 336 | pub extern fn pthread_cond_broadcast(cond: *pthread_cond_t) c_int; |
| 337 | pub extern fn pthread_rwlock_init(noalias rwlock: *pthread_rwlock_t, noalias attr: ?*const pthread_rwlockattr_t) c_int; |
| 338 | pub extern fn pthread_rwlock_destroy(rwlock: *pthread_rwlock_t) c_int; |
| 339 | pub extern fn pthread_rwlock_rdlock(rwlock: *pthread_rwlock_t) c_int; |
| 340 | pub extern fn pthread_rwlock_tryrdlock(rwlock: *pthread_rwlock_t) c_int; |
| 341 | pub extern fn pthread_rwlock_wrlock(rwlock: *pthread_rwlock_t) c_int; |
| 342 | pub extern fn pthread_rwlock_trywrlock(rwlock: *pthread_rwlock_t) c_int; |
| 343 | pub extern fn pthread_rwlock_unlock(rwlock: *pthread_rwlock_t) c_int; |
| 344 | pub extern fn clock_gettime(clock_id: clockid_t, tp: *struct_timespec) c_int; |
| 345 | pub extern fn renameat(oldfd: c_int, old: [*:0]const u8, newfd: c_int, new: [*:0]const u8) c_int; |
| 346 | pub extern fn send(fd: c_int, buffer: [*]const u8, length: usize, flags: c_int) isize; |
| 347 | pub extern fn recv(fd: c_int, buffer: [*]u8, length: usize, flags: c_int) isize; |
| 348 | pub extern fn fstat(fd: c_int, buf: *struct_stat) c_int; |
| 349 | pub extern fn mmap(addr: ?*anyopaque, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: off_t) *allowzero anyopaque; |
| 350 | pub extern fn writev(fd: c_int, iovec: [*]const struct_iovec, count: c_int) isize; |
| 351 | pub extern fn faccessat(fd: c_int, path: [*:0]const u8, amode: c_int, flag: c_int) c_int; |
| 352 | pub extern fn readlinkat(fd: c_int, noalias path: [*:0]const u8, noalias buf: [*]u8, len: usize) isize; |
| 353 | pub extern fn futimens(fd: c_int, times: *const [2]struct_timespec) c_int; |
| 354 | pub extern fn setsockopt(fd: c_int, level: c_int, optname: c_int, optval: *const anyopaque, optlen: socklen_t) c_int; |
| 355 | pub extern fn bind(socket: c_int, address: *const struct_sockaddr, address_len: socklen_t) c_int; |
| 356 | pub extern fn listen(socket: c_int, backlog: c_int) c_int; |
| 357 | pub extern fn getsockname(fd: c_int, noalias addr: *struct_sockaddr, noalias len: *socklen_t) c_int; |
| 358 | pub extern fn pthread_attr_init(attr: *pthread_attr_t) c_int; |
| 359 | pub extern fn pthread_attr_destroy(attr: *pthread_attr_t) c_int; |
| 360 | pub extern fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int; |
| 361 | pub extern fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) c_int; |
| 362 | pub extern fn pthread_create(noalias newthread: *pthread_t, noalias attr: *const pthread_attr_t, start_routine: *const fn (*anyopaque) callconv(.c) ?*anyopaque, noalias arg: *anyopaque) c_int; |
| 363 | pub extern fn pthread_detach(thread: pthread_t) c_int; |
| 364 | pub extern fn pthread_join(thread: pthread_t, retval: ?*?*anyopaque) c_int; |
| 365 | pub extern fn munmap(addr: *const anyopaque, len: usize) c_int; |
| 366 | pub extern fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) isize; |
| 367 | pub extern fn accept4(socket: c_int, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) c_int; |
| 368 | pub extern fn shutdown(socket: c_int, how: c_int) c_int; |
| 369 | pub extern fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) c_int; |
| 370 | pub extern fn lseek(fd: c_int, offset: off_t, whence: c_int) off_t; |
| 371 | }; |
| 372 | |
| 373 | pub const blksize_t = i32; |
| 374 | pub const blkcnt_t = i64; |
| 375 | pub const clockid_t = i32; |
| 376 | pub const fflags_t = u32; |
| 377 | pub const fsblkcnt_t = u64; |
| 378 | pub const fsfilcnt_t = u64; |
| 379 | pub const gid_t = u32; |
| 380 | pub const id_t = i64; |
| 381 | pub const ino_t = u64; |
| 382 | pub const key_t = c_long; |
| 383 | pub const lwpid_t = i32; |
| 384 | pub const mode_t = u16; |
| 385 | pub const accmode_t = c_int; |
| 386 | pub const nl_item = c_int; |
| 387 | pub const nlink_t = u64; |
| 388 | pub const off_t = i64; |
| 389 | pub const off64_t = i64; |
| 390 | pub const pid_t = i32; |
| 391 | pub const sbintime_t = i64; |
| 392 | pub const rlim_t = i64; |
| 393 | pub const sa_family_t = u8; |
| 394 | pub const socklen_t = u32; |
| 395 | pub const suseconds_t = c_long; |
| 396 | pub const uid_t = u32; |
| 397 | pub const useconds_t = c_uint; |
| 398 | pub const cpuwhich_t = c_int; |
| 399 | pub const cpulevel_t = c_int; |
| 400 | pub const cpusetid_t = c_int; |
| 401 | pub const daddr_t = i64; |
| 402 | pub const struct_pollfd = extern struct { fd: c_int, events: c_short, revents: c_short }; |
| 403 | pub const nfds_t = c_uint; |
| 404 | pub const struct_stat = extern struct { dev: dev_t, ino: ino_t, nlink: nlink_t, mode: mode_t, bsdflags: i16, uid: uid_t, gid: gid_t, padding1: i32, rdev: dev_t, atim: struct_timespec, mtim: struct_timespec, ctim: struct_timespec, birthtim: struct_timespec, size: off_t, blocks: blkcnt_t, blksize: blksize_t, flags: fflags_t, gen: u64, filerev: u64, spare: [9]u64 }; |
| 405 | pub const dev_t = u64; |
| 406 | pub const struct_timespec = extern struct { sec: time_t, nsec: c_long }; |
| 407 | pub const time_t = i64; |
| 408 | pub const struct_iovec = extern struct { base: [*]u8, len: usize }; |
| 409 | pub const in_addr_t = u32; |
| 410 | pub const in_port_t = u16; |
| 411 | pub const struct_in_addr = extern struct { addr: in_addr_t }; |
| 412 | pub const struct_in6_addr = extern struct { addr: extern union { a8: [16]u8, a16: [8]u16, a32: [4]u32 } }; |
| 413 | pub const struct_sockaddr = extern struct { len: u8 = 6, family: AF, data: [14]u8 }; |
| 414 | pub const struct_sockaddr_in = extern struct { len: u8 = 16, family: AF = .INET, port: in_port_t, addr: struct_in_addr, zero: [8]u8 = @splat(0) }; |
| 415 | pub const struct_sockaddr_in6 = extern struct { len: u8 = 28, family: AF = .INET6, port: in_port_t, flowinfo: u32, addr: struct_in6_addr, scope_id: u32 }; |
| 416 | pub const struct_sockaddr_un = extern struct { len: u8 = 106, family: AF = .UNIX, path: [104]u8 }; |
| 417 | comptime { |
| 418 | std.debug.assert(@sizeOf(struct_sockaddr_in) == 16); |
| 419 | std.debug.assert(@sizeOf(struct_sockaddr_in6) == 28); |
| 420 | std.debug.assert(@sizeOf(struct_sockaddr_un) == 106); |
| 421 | } |
| 422 | pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktype: c_int, protocol: c_int, addrlen: socklen_t, canonname: ?[*:0]u8, addr: ?*struct_sockaddr, next: ?*struct_addrinfo }; |
| 423 | pub const struct_dirent = extern struct { fileno: ino_t, off: off_t, reclen: u16, type: DT, pad0: u8, namlen: u16, pad1: u16, name: [NAME_MAX + 1]u8 }; |
| 424 | pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t }; |
| 425 | |
| 426 | const impdef = @cImport({ |
| 427 | @cInclude("pthread.h"); |
| 428 | }); |
| 429 | pub const pthread_t = impdef.pthread_t; |
| 430 | pub const pthread_attr_t = impdef.pthread_attr_t; |
| 431 | pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; |
| 432 | pub const pthread_mutex_t = impdef.pthread_mutex_t; |
| 433 | pub const pthread_condattr_t = impdef.pthread_condattr_t; |
| 434 | pub const pthread_cond_t = impdef.pthread_cond_t; |
| 435 | pub const pthread_rwlockattr_t = impdef.pthread_rwlockattr_t; |
| 436 | pub const pthread_rwlock_t = impdef.pthread_rwlock_t; |
| 437 | |
| 438 | pub const ARG_MAX = (256 * 1024); |
| 439 | pub const CHILD_MAX = 40; |
| 440 | pub const MAX_CANON = 255; |
| 441 | pub const MAX_INPUT = 255; |
| 442 | pub const NAME_MAX = 255; |
| 443 | pub const NGROUPS_MAX = 1023; |
| 444 | pub const OPEN_MAX = 64; |
| 445 | pub const PATH_MAX = 1024; |
| 446 | pub const PIPE_BUF = 512; |
| 447 | pub const IOV_MAX = 1024; |
| 448 | |
| 449 | pub const O = struct { |
| 450 | pub const RDONLY = 0x0000; |
| 451 | pub const WRONLY = 0x0001; |
| 452 | pub const RDWR = 0x0002; |
| 453 | pub const ACCMODE = 0x0003; |
| 454 | pub const NONBLOCK = 0x0004; |
| 455 | pub const APPEND = 0x0008; |
| 456 | pub const SHLOCK = 0x0010; |
| 457 | pub const EXLOCK = 0x0020; |
| 458 | pub const ASYNC = 0x0040; |
| 459 | pub const FSYNC = 0x0080; |
| 460 | pub const SYNC = 0x0080; |
| 461 | pub const NOFOLLOW = 0x0100; |
| 462 | pub const CREAT = 0x0200; |
| 463 | pub const TRUNC = 0x0400; |
| 464 | pub const EXCL = 0x0800; |
| 465 | pub const NOCTTY = 0x8000; |
| 466 | pub const DIRECT = 0x00010000; |
| 467 | pub const DIRECTORY = 0x00020000; |
| 468 | pub const EXEC = 0x00040000; |
| 469 | pub const SEARCH = EXEC; |
| 470 | pub const TTY_INIT = 0x00080000; |
| 471 | pub const CLOEXEC = 0x00100000; |
| 472 | pub const VERIFY = 0x00200000; |
| 473 | pub const PATH = 0x00400000; |
| 474 | pub const RESOLVE_BENEATH = 0x00800000; |
| 475 | pub const DSYNC = 0x01000000; |
| 476 | pub const EMPTY_PATH = 0x02000000; |
| 477 | pub const NAMEDATTR = 0x04000000; |
| 478 | pub const XATTR = NAMEDATTR; |
| 479 | pub const SYMLINK = (PATH | NOFOLLOW); |
| 480 | pub const CLOFORK = 0x08000000; |
| 481 | }; |
| 482 | |
| 483 | pub const AT = struct { |
| 484 | pub const FDCWD = -100; |
| 485 | pub const EACCESS = 0x0100; |
| 486 | pub const SYMLINK_NOFOLLOW = 0x0200; |
| 487 | pub const SYMLINK_FOLLOW = 0x0400; |
| 488 | pub const REMOVEDIR = 0x0800; |
| 489 | pub const BENEATH = 0x1000; |
| 490 | pub const RESOLVE_BENEATH = 0x2000; |
| 491 | pub const EMPTY_PATH = 0x4000; |
| 492 | pub const RENAME_NOREPLACE = 0x0001; |
| 493 | pub const RENAME_EXCHANGE = 0x0002; |
| 494 | }; |
| 495 | |
| 496 | pub const SIG = struct { |
| 497 | pub const HUP = 1; |
| 498 | pub const INT = 2; |
| 499 | pub const QUIT = 3; |
| 500 | pub const ILL = 4; |
| 501 | pub const TRAP = 5; |
| 502 | pub const ABRT = 6; |
| 503 | pub const IOT = ABRT; |
| 504 | pub const EMT = 7; |
| 505 | pub const FPE = 8; |
| 506 | pub const KILL = 9; |
| 507 | pub const BUS = 10; |
| 508 | pub const SEGV = 11; |
| 509 | pub const SYS = 12; |
| 510 | pub const PIPE = 13; |
| 511 | pub const ALRM = 14; |
| 512 | pub const TERM = 15; |
| 513 | pub const URG = 16; |
| 514 | pub const STOP = 17; |
| 515 | pub const TSTP = 18; |
| 516 | pub const CONT = 19; |
| 517 | pub const CHLD = 20; |
| 518 | pub const TTIN = 21; |
| 519 | pub const TTOU = 22; |
| 520 | pub const IO = 23; |
| 521 | pub const XCPU = 24; |
| 522 | pub const XFSZ = 25; |
| 523 | pub const VTALRM = 26; |
| 524 | pub const PROF = 27; |
| 525 | pub const WINCH = 28; |
| 526 | pub const INFO = 29; |
| 527 | pub const USR1 = 30; |
| 528 | pub const USR2 = 31; |
| 529 | pub const THR = 32; |
| 530 | pub const LWP = THR; |
| 531 | pub const LIBRT = 33; |
| 532 | }; |
| 533 | |
| 534 | pub const POLL = struct { |
| 535 | pub const IN = 0x0001; |
| 536 | pub const PRI = 0x0002; |
| 537 | pub const OUT = 0x0004; |
| 538 | pub const RDNORM = 0x0040; |
| 539 | pub const WRNORM = OUT; |
| 540 | pub const RDBAND = 0x0080; |
| 541 | pub const WRBAND = 0x0100; |
| 542 | pub const INIGNEOF = 0x2000; |
| 543 | pub const RDHUP = 0x4000; |
| 544 | pub const ERR = 0x0008; |
| 545 | pub const HUP = 0x0010; |
| 546 | pub const NVAL = 0x0020; |
| 547 | }; |
| 548 | |
| 549 | pub const W = struct { |
| 550 | pub const COREFLAG = 0o200; |
| 551 | pub const _STOPPED = 0o177; |
| 552 | pub const NOHANG = 1; |
| 553 | pub const UNTRACED = 2; |
| 554 | pub const STOPPED = UNTRACED; |
| 555 | pub const CONTINUED = 4; |
| 556 | pub const NOWAIT = 8; |
| 557 | pub const EXITED = 16; |
| 558 | pub const TRAPPED = 32; |
| 559 | pub const LINUXCLONE = 0x80000000; |
| 560 | |
| 561 | pub fn _INT(s: c_int) c_int { |
| 562 | return s; |
| 563 | } |
| 564 | pub fn _STATUS(s: c_int) u8 { |
| 565 | return @intCast(_INT(s) & 0o177); |
| 566 | } |
| 567 | pub fn IFSTOPPED(s: c_int) bool { |
| 568 | return _STATUS(s) == _STOPPED; |
| 569 | } |
| 570 | pub fn STOPSIG(s: c_int) u8 { |
| 571 | return @intCast(_INT(s) >> 8); |
| 572 | } |
| 573 | pub fn IFSIGNALED(s: c_int) bool { |
| 574 | return _STATUS(s) != _STOPPED and _STATUS(s) != 0 and s != 0x13; |
| 575 | } |
| 576 | pub fn TERMSIG(s: c_int) u8 { |
| 577 | return _STATUS(s); |
| 578 | } |
| 579 | pub fn IFEXITED(s: c_int) bool { |
| 580 | return _STATUS(s) == 0; |
| 581 | } |
| 582 | pub fn EXITSTATUS(s: c_int) u8 { |
| 583 | return @intCast(_INT(s) >> 8); |
| 584 | } |
| 585 | pub fn IFCONTINUED(s: c_int) bool { |
| 586 | return s == SIG.CONT; |
| 587 | } |
| 588 | pub fn COREDUMP(s: c_int) bool { |
| 589 | return s == SIG.CONT; |
| 590 | } |
| 591 | pub fn _EXITCODE(r: c_int, s: c_int) c_int { |
| 592 | return r << 8 | s; |
| 593 | } |
| 594 | pub fn _STOPCODE(s: c_int) c_int { |
| 595 | return s << 8 | _STOPPED; |
| 596 | } |
| 597 | }; |
| 598 | |
| 599 | pub const S = struct { |
| 600 | pub const ISUID = 0o004000; |
| 601 | pub const ISGID = 0o002000; |
| 602 | pub const ISTXT = 0o001000; |
| 603 | pub const IRWXU = 0o000700; |
| 604 | pub const IRUSR = 0o000400; |
| 605 | pub const IWUSR = 0o000200; |
| 606 | pub const IXUSR = 0o000100; |
| 607 | pub const IREAD = IRUSR; |
| 608 | pub const IWRITE = IWUSR; |
| 609 | pub const IEXEC = IXUSR; |
| 610 | pub const IRWXG = 0o000070; |
| 611 | pub const IRGRP = 0o000040; |
| 612 | pub const IWGRP = 0o000020; |
| 613 | pub const IXGRP = 0o000010; |
| 614 | pub const IRWXO = 0o000007; |
| 615 | pub const IROTH = 0o000004; |
| 616 | pub const IWOTH = 0o000002; |
| 617 | pub const IXOTH = 0o000001; |
| 618 | pub const IFMT = 0o170000; |
| 619 | pub const IFIFO = 0o010000; |
| 620 | pub const IFCHR = 0o020000; |
| 621 | pub const IFDIR = 0o040000; |
| 622 | pub const IFBLK = 0o060000; |
| 623 | pub const IFREG = 0o100000; |
| 624 | pub const IFLNK = 0o120000; |
| 625 | pub const IFSOCK = 0o140000; |
| 626 | pub const ISVTX = 0o001000; |
| 627 | pub const IFWHT = 0o160000; |
| 628 | }; |
| 629 | |
| 630 | pub const AF = enum(sa_family_t) { |
| 631 | UNSPEC = 0, |
| 632 | UNIX = 1, |
| 633 | INET = 2, |
| 634 | IMPLINK = 3, |
| 635 | PUP = 4, |
| 636 | CHAOS = 5, |
| 637 | NETBIOS = 6, |
| 638 | ISO = 7, |
| 639 | ECMA = 8, |
| 640 | DATAKIT = 9, |
| 641 | CCITT = 10, |
| 642 | SNA = 11, |
| 643 | DECnet = 12, |
| 644 | DLI = 13, |
| 645 | LAT = 14, |
| 646 | HYLINK = 15, |
| 647 | APPLETALK = 16, |
| 648 | ROUTE = 17, |
| 649 | LINK = 18, |
| 650 | XTP = 19, |
| 651 | COIP = 20, |
| 652 | CNT = 21, |
| 653 | RTIP = 22, |
| 654 | IPX = 23, |
| 655 | SIP = 24, |
| 656 | PIP = 25, |
| 657 | ISDN = 26, |
| 658 | KEY = 27, |
| 659 | INET6 = 28, |
| 660 | NATM = 29, |
| 661 | ATM = 30, |
| 662 | HDRCMPLT = 31, |
| 663 | NETGRAPH = 32, |
| 664 | SLOW = 33, |
| 665 | SCLUSTER = 34, |
| 666 | ARP = 35, |
| 667 | BLUETOOTH = 36, |
| 668 | IEEE80211 = 37, |
| 669 | NETLINK = 38, |
| 670 | INET_SDP = 40, |
| 671 | INET6_SDP = 42, |
| 672 | HYPERV = 43, |
| 673 | DIVERT = 44, |
| 674 | IPFWLOG = 46, |
| 675 | |
| 676 | pub const LOCAL: AF = .UNIX; |
| 677 | pub const OSI: AF = .ISO; |
| 678 | pub const E164: AF = .ISDN; |
| 679 | }; |
| 680 | |
| 681 | pub const SOCK = struct { |
| 682 | pub const STREAM = 1; |
| 683 | pub const DGRAM = 2; |
| 684 | pub const RAW = 3; |
| 685 | pub const RDM = 4; |
| 686 | pub const SEQPACKET = 5; |
| 687 | pub const CLOEXEC = 0x10000000; |
| 688 | pub const NONBLOCK = 0x20000000; |
| 689 | pub const CLOFORK = 0x40000000; |
| 690 | }; |
| 691 | |
| 692 | pub const IPPROTO = struct { |
| 693 | pub const IP = 0; |
| 694 | pub const ICMP = 1; |
| 695 | pub const TCP = 6; |
| 696 | pub const UDP = 17; |
| 697 | pub const IPV6 = 41; |
| 698 | pub const RAW = 255; |
| 699 | pub const HOPOPTS = 0; |
| 700 | pub const IGMP = 2; |
| 701 | pub const GGP = 3; |
| 702 | pub const IPV4 = 4; |
| 703 | pub const IPIP = IPV4; |
| 704 | pub const ST = 7; |
| 705 | pub const EGP = 8; |
| 706 | pub const PIGP = 9; |
| 707 | pub const RCCMON = 10; |
| 708 | pub const NVPII = 11; |
| 709 | pub const PUP = 12; |
| 710 | pub const ARGUS = 13; |
| 711 | pub const EMCON = 14; |
| 712 | pub const XNET = 15; |
| 713 | pub const CHAOS = 16; |
| 714 | pub const MUX = 18; |
| 715 | pub const MEAS = 19; |
| 716 | pub const HMP = 20; |
| 717 | pub const PRM = 21; |
| 718 | pub const IDP = 22; |
| 719 | pub const TRUNK1 = 23; |
| 720 | pub const TRUNK2 = 24; |
| 721 | pub const LEAF1 = 25; |
| 722 | pub const LEAF2 = 26; |
| 723 | pub const RDP = 27; |
| 724 | pub const IRTP = 28; |
| 725 | pub const TP = 29; |
| 726 | pub const BLT = 30; |
| 727 | pub const NSP = 31; |
| 728 | pub const INP = 32; |
| 729 | pub const DCCP = 33; |
| 730 | pub const @"3PC" = 34; |
| 731 | pub const IDPR = 35; |
| 732 | pub const XTP = 36; |
| 733 | pub const DDP = 37; |
| 734 | pub const CMTP = 38; |
| 735 | pub const TPXX = 39; |
| 736 | pub const IL = 40; |
| 737 | pub const SDRP = 42; |
| 738 | pub const ROUTING = 43; |
| 739 | pub const FRAGMENT = 44; |
| 740 | pub const IDRP = 45; |
| 741 | pub const RSVP = 46; |
| 742 | pub const GRE = 47; |
| 743 | pub const MHRP = 48; |
| 744 | pub const BHA = 49; |
| 745 | pub const ESP = 50; |
| 746 | pub const AH = 51; |
| 747 | pub const INLSP = 52; |
| 748 | pub const SWIPE = 53; |
| 749 | pub const NHRP = 54; |
| 750 | pub const MOBILE = 55; |
| 751 | pub const TLSP = 56; |
| 752 | pub const SKIP = 57; |
| 753 | pub const ICMPV6 = 58; |
| 754 | pub const NONE = 59; |
| 755 | pub const DSTOPTS = 60; |
| 756 | pub const AHIP = 61; |
| 757 | pub const CFTP = 62; |
| 758 | pub const HELLO = 63; |
| 759 | pub const SATEXPAK = 64; |
| 760 | pub const KRYPTOLAN = 65; |
| 761 | pub const RVD = 66; |
| 762 | pub const IPPC = 67; |
| 763 | pub const ADFS = 68; |
| 764 | pub const SATMON = 69; |
| 765 | pub const VISA = 70; |
| 766 | pub const IPCV = 71; |
| 767 | pub const CPNX = 72; |
| 768 | pub const CPHB = 73; |
| 769 | pub const WSN = 74; |
| 770 | pub const PVP = 75; |
| 771 | pub const BRSATMON = 76; |
| 772 | pub const ND = 77; |
| 773 | pub const WBMON = 78; |
| 774 | pub const WBEXPAK = 79; |
| 775 | pub const EON = 80; |
| 776 | pub const VMTP = 81; |
| 777 | pub const SVMTP = 82; |
| 778 | pub const VINES = 83; |
| 779 | pub const TTP = 84; |
| 780 | pub const IGP = 85; |
| 781 | pub const DGP = 86; |
| 782 | pub const TCF = 87; |
| 783 | pub const IGRP = 88; |
| 784 | pub const OSPFIGP = 89; |
| 785 | pub const SRPC = 90; |
| 786 | pub const LARP = 91; |
| 787 | pub const MTP = 92; |
| 788 | pub const AX25 = 93; |
| 789 | pub const IPEIP = 94; |
| 790 | pub const MICP = 95; |
| 791 | pub const SCCSP = 96; |
| 792 | pub const ETHERIP = 97; |
| 793 | pub const ENCAP = 98; |
| 794 | pub const APES = 99; |
| 795 | pub const GMTP = 100; |
| 796 | pub const IPCOMP = 108; |
| 797 | pub const SCTP = 132; |
| 798 | pub const MH = 135; |
| 799 | pub const UDPLITE = 136; |
| 800 | pub const HIP = 139; |
| 801 | pub const SHIM6 = 140; |
| 802 | pub const PIM = 103; |
| 803 | pub const CARP = 112; |
| 804 | pub const PGM = 113; |
| 805 | pub const MPLS = 137; |
| 806 | pub const PFSYNC = 240; |
| 807 | }; |
| 808 | |
| 809 | pub const CLOCK = enum(clockid_t) { |
| 810 | REALTIME = 0, |
| 811 | VIRTUAL = 1, |
| 812 | PROF = 2, |
| 813 | MONOTONIC = 4, |
| 814 | UPTIME_FAST = 8, |
| 815 | UPTIME = 5, |
| 816 | UPTIME_PRECISE = 7, |
| 817 | REALTIME_PRECISE = 9, |
| 818 | REALTIME_FAST = 10, |
| 819 | MONOTONIC_PRECISE = 11, |
| 820 | MONOTONIC_FAST = 12, |
| 821 | SECOND = 13, |
| 822 | THREAD_CPUTIME_ID = 14, |
| 823 | PROCESS_CPUTIME_ID = 15, |
| 824 | TAI = 16, |
| 825 | _, |
| 826 | |
| 827 | pub const BOOTTIME: CLOCK = .MONOTONIC; |
| 828 | pub const REALTIME_COARSE: CLOCK = .REALTIME_FAST; |
| 829 | pub const MONOTONIC_COARSE: CLOCK = .MONOTONIC_FAST; |
| 830 | }; |
| 831 | |
| 832 | pub const SOL = struct { |
| 833 | pub const SOCKET = 0xffff; |
| 834 | }; |
| 835 | |
| 836 | pub const SO = struct { |
| 837 | pub const DEBUG = 0x00000001; |
| 838 | pub const ACCEPTCONN = 0x00000002; |
| 839 | pub const REUSEADDR = 0x00000004; |
| 840 | pub const KEEPALIVE = 0x00000008; |
| 841 | pub const DONTROUTE = 0x00000010; |
| 842 | pub const BROADCAST = 0x00000020; |
| 843 | pub const USELOOPBACK = 0x00000040; |
| 844 | pub const LINGER = 0x00000080; |
| 845 | pub const OOBINLINE = 0x00000100; |
| 846 | pub const REUSEPORT = 0x00000200; |
| 847 | pub const TIMESTAMP = 0x00000400; |
| 848 | pub const NOSIGPIPE = 0x00000800; |
| 849 | pub const ACCEPTFILTER = 0x00001000; |
| 850 | pub const BINTIME = 0x00002000; |
| 851 | pub const NO_OFFLOAD = 0x00004000; |
| 852 | pub const NO_DDP = 0x00008000; |
| 853 | pub const REUSEPORT_LB = 0x00010000; |
| 854 | pub const RERROR = 0x00020000; |
| 855 | pub const PASSRIGHTS = 0x00040000; |
| 856 | pub const SNDBUF = 0x1001; |
| 857 | pub const RCVBUF = 0x1002; |
| 858 | pub const SNDLOWAT = 0x1003; |
| 859 | pub const RCVLOWAT = 0x1004; |
| 860 | pub const SNDTIMEO = 0x1005; |
| 861 | pub const RCVTIMEO = 0x1006; |
| 862 | pub const ERROR = 0x1007; |
| 863 | pub const TYPE = 0x1008; |
| 864 | pub const LABEL = 0x1009; |
| 865 | pub const PEERLABEL = 0x1010; |
| 866 | pub const LISTENQLIMIT = 0x1011; |
| 867 | pub const LISTENQLEN = 0x1012; |
| 868 | pub const LISTENINCQLEN = 0x1013; |
| 869 | pub const FIB = 0x1014; |
| 870 | pub const SETFIB = FIB; |
| 871 | pub const USER_COOKIE = 0x1015; |
| 872 | pub const PROTOCOL = 0x1016; |
| 873 | pub const PROTOTYPE = PROTOCOL; |
| 874 | pub const TS_CLOCK = 0x1017; |
| 875 | pub const MAX_PACING_RATE = 0x1018; |
| 876 | pub const DOMAIN = 0x1019; |
| 877 | pub const SPLICE = 0x1023; |
| 878 | pub const TS_REALTIME_MICRO = 0; |
| 879 | pub const TS_BINTIME = 1; |
| 880 | pub const TS_REALTIME = 2; |
| 881 | pub const TS_MONOTONIC = 3; |
| 882 | pub const TS_DEFAULT = TS_REALTIME_MICRO; |
| 883 | pub const TS_CLOCK_MAX = TS_MONOTONIC; |
| 884 | }; |
| 885 | |
| 886 | pub const DT = enum(u8) { |
| 887 | UNKNOWN = 0, |
| 888 | FIFO = 1, |
| 889 | CHR = 2, |
| 890 | DIR = 4, |
| 891 | BLK = 6, |
| 892 | REG = 8, |
| 893 | LNK = 10, |
| 894 | SOCK = 12, |
| 895 | WHT = 14, |
| 896 | }; |
| 897 | |
| 898 | pub const SHUT = enum(c_int) { |
| 899 | RD = 0, |
| 900 | WR = 1, |
| 901 | RDWR = 2, |
| 902 | }; |
| 903 | |
| 904 | pub const MAP = struct { |
| 905 | pub const SHARED = 0x0001; |
| 906 | pub const PRIVATE = 0x0002; |
| 907 | pub const FIXED = 0x0010; |
| 908 | pub const FILE = 0x0000; |
| 909 | pub const ANON = 0x1000; |
| 910 | pub const ANONYMOUS = ANON; |
| 911 | pub const GUARD = 0x00002000; |
| 912 | pub const EXCL = 0x00004000; |
| 913 | pub const NOCORE = 0x00020000; |
| 914 | pub const PREFAULT_READ = 0x00040000; |
| 915 | pub const _32BIT = 0x00080000; |
| 916 | pub const FAILED = -1; |
| 917 | }; |
| 918 | |
| 919 | pub const PROT = struct { |
| 920 | pub const NONE = 0x00; |
| 921 | pub const READ = 0x01; |
| 922 | pub const WRITE = 0x02; |
| 923 | pub const EXEC = 0x04; |
| 924 | pub const CHERI0 = 0x08; |
| 925 | pub const CHERI1 = 0x10; |
| 926 | }; |
| 927 | |
| 928 | pub const IPV6 = struct { |
| 929 | pub const UNICAST_HOPS = 4; |
| 930 | pub const MULTICAST_IF = 9; |
| 931 | pub const MULTICAST_HOPS = 10; |
| 932 | pub const MULTICAST_LOOP = 11; |
| 933 | pub const JOIN_GROUP = 12; |
| 934 | pub const LEAVE_GROUP = 13; |
| 935 | pub const PORTRANGE = 14; |
| 936 | pub const CHECKSUM = 26; |
| 937 | pub const V6ONLY = 27; |
| 938 | pub const IPSEC_POLICY = 28; |
| 939 | pub const FW_ADD = 30; |
| 940 | pub const FW_DEL = 31; |
| 941 | pub const FW_FLUSH = 32; |
| 942 | pub const FW_ZERO = 33; |
| 943 | pub const FW_GET = 34; |
| 944 | pub const RTHDRDSTOPTS = 35; |
| 945 | pub const RECVPKTINFO = 36; |
| 946 | pub const RECVHOPLIMIT = 37; |
| 947 | pub const RECVRTHDR = 38; |
| 948 | pub const RECVHOPOPTS = 39; |
| 949 | pub const RECVDSTOPTS = 40; |
| 950 | pub const USE_MIN_MTU = 42; |
| 951 | pub const RECVPATHMTU = 43; |
| 952 | pub const PATHMTU = 44; |
| 953 | pub const PKTINFO = 46; |
| 954 | pub const HOPLIMIT = 47; |
| 955 | pub const NEXTHOP = 48; |
| 956 | pub const HOPOPTS = 49; |
| 957 | pub const DSTOPTS = 50; |
| 958 | pub const RTHDR = 51; |
| 959 | pub const RECVTCLASS = 57; |
| 960 | pub const AUTOFLOWLABEL = 59; |
| 961 | pub const TCLASS = 61; |
| 962 | pub const DONTFRAG = 62; |
| 963 | pub const PREFER_TEMPADDR = 63; |
| 964 | pub const BINDANY = 64; |
| 965 | pub const FLOWID = 67; |
| 966 | pub const FLOWTYPE = 68; |
| 967 | pub const RSSBUCKETID = 69; |
| 968 | pub const RECVFLOWID = 70; |
| 969 | pub const RECVRSSBUCKETID = 71; |
| 970 | pub const ORIGDSTADDR = 72; |
| 971 | pub const RECVORIGDSTADDR = ORIGDSTADDR; |
| 972 | pub const MSFILTER = 74; |
| 973 | pub const VLAN_PCP = 75; |
| 974 | }; |
| 975 | |
| 976 | pub const SEEK = struct { |
| 977 | pub const SET = 0; |
| 978 | pub const CUR = 1; |
| 979 | pub const END = 2; |
| 980 | pub const DATA = 3; |
| 981 | pub const HOLE = 4; |
| 982 | }; |
| 983 | |
| 984 | pub fn pipe2(flag: c_int) ![2]c_int { |
| 985 | var fildes: [2]c_int = @splat(-1); |
| 986 | const rc = libc.pipe2(&fildes, flag); |
| 987 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 988 | std.debug.assert(rc == 0); |
| 989 | return fildes; |
| 990 | } |
| 991 | pub fn openat(fd: c_int, file: [*:0]const u8, oflag: c_int) errno.Error!c_int { |
| 992 | const rc = libc.openat(fd, file, oflag); |
| 993 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 994 | std.debug.assert(rc >= 0); |
| 995 | return rc; |
| 996 | } |
| 997 | pub fn openat4(fd: c_int, file: [*:0]const u8, oflag: c_int, mode: mode_t) errno.Error!c_int { |
| 998 | const rc = libc.openat(fd, file, oflag, mode); |
| 999 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1000 | return rc; |
| 1001 | } |
| 1002 | pub fn close(fd: c_int) errno.Error!void { |
| 1003 | const rc = libc.close(fd); |
| 1004 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1005 | std.debug.assert(rc == 0); |
| 1006 | } |
| 1007 | pub fn fork() !pid_t { |
| 1008 | const rc = libc.fork(); |
| 1009 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1010 | std.debug.assert(rc >= 0); |
| 1011 | return rc; |
| 1012 | } |
| 1013 | pub fn dup2(fildes: c_int, fildes2: c_int) !void { |
| 1014 | const rc = libc.dup2(fildes, fildes2); |
| 1015 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1016 | std.debug.assert(rc >= 0); |
| 1017 | } |
| 1018 | pub fn fchdir(fildes: c_int) !void { |
| 1019 | const rc = libc.fchdir(fildes); |
| 1020 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1021 | std.debug.assert(rc == 0); |
| 1022 | } |
| 1023 | pub fn execvp(file: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) !noreturn { |
| 1024 | const rc = libc.execvp(file, argv); |
| 1025 | std.debug.assert(rc == -1); |
| 1026 | return errno.fromInt(errno.fromLibC()); |
| 1027 | } |
| 1028 | pub fn kill(pid: pid_t, sig: c_int) !void { |
| 1029 | const rc = libc.kill(pid, sig); |
| 1030 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1031 | std.debug.assert(rc == 0); |
| 1032 | } |
| 1033 | pub fn poll(fds: []struct_pollfd, timeout_ms: c_int) !c_int { |
| 1034 | const rc = libc.poll(fds.ptr, @intCast(fds.len), timeout_ms); |
| 1035 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1036 | std.debug.assert(rc >= 0); |
| 1037 | return rc; |
| 1038 | } |
| 1039 | pub fn read(fd: c_int, buf: []u8) errno.Error!usize { |
| 1040 | const rc = libc.read(fd, buf.ptr, buf.len); |
| 1041 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1042 | std.debug.assert(rc >= 0); |
| 1043 | return @intCast(rc); |
| 1044 | } |
| 1045 | pub fn write(fd: c_int, buf: []const u8) !usize { |
| 1046 | const rc = libc.write(fd, buf.ptr, buf.len); |
| 1047 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1048 | std.debug.assert(rc >= 0); |
| 1049 | return @intCast(rc); |
| 1050 | } |
| 1051 | pub fn waitpid(pid: pid_t, options: c_int) !struct { pid_t, c_int } { |
| 1052 | var status: c_int = 0; |
| 1053 | const rc = libc.waitpid(pid, &status, options); |
| 1054 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1055 | std.debug.assert(rc >= 0); |
| 1056 | return .{ rc, status }; |
| 1057 | } |
| 1058 | pub fn getenv(name: [:0]const u8) ?[:0]u8 { |
| 1059 | return std.mem.sliceTo(libc.getenv(name.ptr) orelse return null, 0); |
| 1060 | } |
| 1061 | pub fn exit(status: c_int) noreturn { |
| 1062 | return libc.exit(status); |
| 1063 | } |
| 1064 | pub fn mkdirat(fd: c_int, path: [*:0]const u8, mode: mode_t) errno.Error!void { |
| 1065 | const rc = libc.mkdirat(fd, path, mode); |
| 1066 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1067 | std.debug.assert(rc == 0); |
| 1068 | } |
| 1069 | pub fn fstatat(fd: c_int, path: [*:0]const u8, flag: c_int) errno.Error!struct_stat { |
| 1070 | var buf: struct_stat = undefined; |
| 1071 | const rc = libc.fstatat(fd, path, &buf, flag); |
| 1072 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1073 | std.debug.assert(rc == 0); |
| 1074 | return buf; |
| 1075 | } |
| 1076 | pub fn getaddrinfo(noalias nodename: ?[*:0]const u8, noalias servname: ?[*:0]const u8, noalias req: ?*const struct_addrinfo) eai.Error!*const struct_addrinfo { |
| 1077 | var pai: *const struct_addrinfo = undefined; |
| 1078 | var hints = std.mem.zeroes(struct_addrinfo); |
| 1079 | const rc = libc.getaddrinfo(nodename, servname, req orelse &hints, &pai); |
| 1080 | if (rc > 0) return eai.fromInt(rc); |
| 1081 | std.debug.assert(rc == 0); |
| 1082 | return pai; |
| 1083 | } |
| 1084 | pub fn freeaddrinfo(ai: *const struct_addrinfo) void { |
| 1085 | return libc.freeaddrinfo(ai); |
| 1086 | } |
| 1087 | pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { |
| 1088 | const rc = libc.socket(@intFromEnum(domain), ty, protocol); |
| 1089 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1090 | std.debug.assert(rc > 0); |
| 1091 | return @intCast(rc); |
| 1092 | } |
| 1093 | pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: socklen_t) errno.Error!void { |
| 1094 | const rc = libc.connect(@intCast(socketfd), address, address_len); |
| 1095 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1096 | std.debug.assert(rc == 0); |
| 1097 | } |
| 1098 | pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 { |
| 1099 | const rc = libc.getrandom(buf.ptr, buf.len, flags); |
| 1100 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1101 | std.debug.assert(rc >= 0); |
| 1102 | return buf[0..@intCast(rc)]; |
| 1103 | } |
| 1104 | pub fn clock_gettime(clock_id: CLOCK) !struct_timespec { |
| 1105 | var tp: struct_timespec = undefined; |
| 1106 | const rc = libc.clock_gettime(@intFromEnum(clock_id), &tp); |
| 1107 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1108 | std.debug.assert(rc == 0); |
| 1109 | return tp; |
| 1110 | } |
| 1111 | pub fn renameat(oldfd: c_int, old: [*:0]const u8, newfd: c_int, new: [*:0]const u8) !void { |
| 1112 | const rc = libc.renameat(oldfd, old, newfd, new); |
| 1113 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1114 | std.debug.assert(rc == 0); |
| 1115 | } |
| 1116 | pub fn send(socketfd: c_uint, buffer: []const u8, flags: c_int) errno.Error!usize { |
| 1117 | const rc = libc.send(@intCast(socketfd), buffer.ptr, buffer.len, flags); |
| 1118 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1119 | std.debug.assert(rc >= 0); |
| 1120 | return @intCast(rc); |
| 1121 | } |
| 1122 | |
| 1123 | pub fn recv(socketfd: c_uint, buffer: []u8, flags: c_int) errno.Error!usize { |
| 1124 | const rc = libc.recv(@intCast(socketfd), buffer.ptr, buffer.len, flags); |
| 1125 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1126 | std.debug.assert(rc >= 0); |
| 1127 | return @intCast(rc); |
| 1128 | } |
| 1129 | pub fn fstat(fd: c_int) errno.Error!struct_stat { |
| 1130 | var buf: struct_stat = undefined; |
| 1131 | const rc = libc.fstat(fd, &buf); |
| 1132 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1133 | std.debug.assert(rc == 0); |
| 1134 | return buf; |
| 1135 | } |
| 1136 | pub fn mmap(addr: ?*anyopaque, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: off_t) errno.Error![]u8 { |
| 1137 | const rc = libc.mmap(addr, len, prot, flags, fd, offset); |
| 1138 | if (@intFromPtr(rc) == MAP.FAILED) return errno.fromInt(errno.fromLibC()); |
| 1139 | const ptr: [*]u8 = @ptrCast(rc); |
| 1140 | return ptr[0..len]; |
| 1141 | } |
| 1142 | pub fn writev(fd: c_int, iovec: []const struct_iovec) !usize { |
| 1143 | const rc = libc.writev(fd, iovec.ptr, @intCast(iovec.len)); |
| 1144 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1145 | std.debug.assert(rc >= 0); |
| 1146 | return @intCast(rc); |
| 1147 | } |
| 1148 | pub fn faccessat(fd: c_int, path: [*:0]const u8, amode: c_int, flag: c_int) !void { |
| 1149 | const rc = libc.faccessat(fd, path, amode, flag); |
| 1150 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1151 | std.debug.assert(rc == 0); |
| 1152 | } |
| 1153 | pub fn readlinkat(dirfd: c_int, noalias path: [*:0]const u8, noalias buf: []u8) ![:0]u8 { |
| 1154 | const rc = libc.readlinkat(dirfd, path, buf.ptr, buf.len); |
| 1155 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1156 | std.debug.assert(rc >= 0); |
| 1157 | buf[@intCast(rc)] = 0; |
| 1158 | return buf[0..@intCast(rc) :0]; |
| 1159 | } |
| 1160 | pub fn futimens(fd: c_int, times: [2]struct_timespec) !void { |
| 1161 | const rc = libc.futimens(fd, &times); |
| 1162 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1163 | std.debug.assert(rc == 0); |
| 1164 | } |
| 1165 | pub fn setsockopt(socketfd: c_uint, level: c_int, optname: c_int, opaque_opt: []const u8) errno.Error!void { |
| 1166 | const rc = libc.setsockopt(@intCast(socketfd), level, optname, opaque_opt.ptr, @intCast(opaque_opt.len)); |
| 1167 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1168 | std.debug.assert(rc == 0); |
| 1169 | } |
| 1170 | pub fn bind(socketfd: c_uint, address: *const struct_sockaddr, address_len: socklen_t) errno.Error!void { |
| 1171 | const rc = libc.bind(@intCast(socketfd), address, address_len); |
| 1172 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1173 | std.debug.assert(rc == 0); |
| 1174 | } |
| 1175 | pub fn listen(socketfd: c_uint, backlog: c_int) errno.Error!void { |
| 1176 | const rc = libc.listen(@intCast(socketfd), backlog); |
| 1177 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1178 | std.debug.assert(rc == 0); |
| 1179 | } |
| 1180 | pub fn getsockname(socketfd: c_uint, noalias address: *struct_sockaddr, noalias address_len: *socklen_t) errno.Error!void { |
| 1181 | const rc = libc.getsockname(@intCast(socketfd), address, address_len); |
| 1182 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1183 | std.debug.assert(rc == 0); |
| 1184 | } |
| 1185 | pub fn munmap(addr: *const anyopaque, len: usize) errno.Error!void { |
| 1186 | const rc = libc.munmap(addr, len); |
| 1187 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1188 | std.debug.assert(rc == 0); |
| 1189 | } |
| 1190 | pub fn getdents(dirfd: c_int, buf: []u8) errno.Error!usize { |
| 1191 | const rc = libc.getdents(dirfd, buf.ptr, buf.len); |
| 1192 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1193 | std.debug.assert(rc >= 0); |
| 1194 | return @intCast(rc); |
| 1195 | } |
| 1196 | pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) errno.Error!c_uint { |
| 1197 | const rc = libc.accept4(@intCast(socketfd), address, address_len, flags); |
| 1198 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1199 | std.debug.assert(rc > 0); |
| 1200 | return @intCast(rc); |
| 1201 | } |
| 1202 | pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { |
| 1203 | const rc = libc.shutdown(@intCast(socketfd), @intFromEnum(how)); |
| 1204 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1205 | std.debug.assert(rc == 0); |
| 1206 | } |
| 1207 | pub fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) !void { |
| 1208 | const rc = libc.unlinkat(fd, name, flag); |
| 1209 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1210 | std.debug.assert(rc == 0); |
| 1211 | } |
| 1212 | pub fn lseek(fd: c_int, offset: off_t, whence: c_int) !void { |
| 1213 | const rc = libc.lseek(fd, offset, whence); |
| 1214 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1215 | std.debug.assert(rc >= 0); |
| 1216 | } |