std: reorganize std.c to eliminate usingnamespace

Behavior tests pass on x86_64-linux with -lc
This commit is contained in:
Andrew Kelley 2021-08-24 17:21:53 -07:00
parent 3deda15e21
commit 1bbfcb95ab
34 changed files with 9657 additions and 9535 deletions

View File

@ -10,7 +10,8 @@ test {
_ = tokenizer;
}
pub usingnamespace switch (std.Target.current.os.tag) {
const generic = @import("c/generic.zig");
const system = switch (builtin.os.tag) {
.linux => @import("c/linux.zig"),
.windows => @import("c/windows.zig"),
.macos, .ios, .tvos, .watchos => @import("c/darwin.zig"),
@ -27,6 +28,109 @@ pub usingnamespace switch (std.Target.current.os.tag) {
.wasi => @import("c/wasi.zig"),
else => struct {},
};
pub const E = system.E;
pub const _errno = system._errno;
pub const MAP_FAILED = system.MAP_FAILED;
pub const AI = system.AI;
pub const NI = system.NI;
pub const EAI = system.EAI;
pub const timespec = system.timespec;
pub const Sigaction = system.Sigaction;
pub const fallocate64 = system.fallocate64;
pub const fopen64 = system.fopen64;
pub const fstat64 = system.fstat64;
pub const fstatat64 = system.fstatat64;
pub const ftruncate64 = system.ftruncate64;
pub const getrlimit64 = system.getrlimit64;
pub const lseek64 = system.lseek64;
pub const mmap64 = system.mmap64;
pub const open64 = system.open64;
pub const openat64 = system.openat64;
pub const pread64 = system.pread64;
pub const preadv64 = system.preadv64;
pub const pwrite64 = system.pwrite64;
pub const pwritev64 = system.pwritev64;
pub const sendfile64 = system.sendfile64;
pub const setrlimit64 = system.setrlimit64;
pub const AT = system.AT;
pub const CLOCK = system.CLOCK;
pub const IOV_MAX = system.IOV_MAX;
pub const NAME_MAX = system.NAME_MAX;
pub const PATH_MAX = system.PATH_MAX;
pub const PROT = system.PROT;
pub const RTLD = system.RTLD;
pub const S = system.S;
pub const SA = system.SA;
pub const SIG = system.SIG;
pub const STDERR_FILENO = system.STDIN_FILENO;
pub const STDIN_FILENO = system.STDIN_FILENO;
pub const STDOUT_FILENO = system.STDIN_FILENO;
pub const Stat = system.Stat;
pub const copy_file_range = system.copy_file_range;
pub const dl_iterate_phdr_callback = system.dl_iterate_phdr_callback;
pub const dl_phdr_info = system.dl_phdr_info;
pub const empty_sigset = system.empty_sigset;
pub const epoll_create1 = system.epoll_create1;
pub const epoll_ctl = system.epoll_ctl;
pub const epoll_pwait = system.epoll_pwait;
pub const epoll_wait = system.epoll_wait;
pub const eventfd = system.eventfd;
pub const fallocate = system.fallocate;
pub const fd_t = system.fd_t;
pub const getauxval = system.getauxval;
pub const getdents = system.getdents;
pub const getrandom = system.getrandom;
pub const inotify_add_watch = system.inotify_add_watch;
pub const inotify_init1 = system.inotify_init1;
pub const inotify_rm_watch = system.inotify_rm_watch;
pub const madvise = system.madvise;
pub const malloc_usable_size = system.malloc_usable_size;
pub const memfd_create = system.memfd_create;
pub const pipe2 = system.pipe2;
pub const pollfd = system.pollfd;
pub const posix_memalign = system.posix_memalign;
pub const prlimit = system.prlimit;
pub const pthread_attr_t = system.pthread_attr_t;
pub const pthread_cond_t = system.pthread_cond_t;
pub const pthread_getname_np = system.pthread_getname_np;
pub const pthread_mutex_t = system.pthread_mutex_t;
pub const pthread_rwlock_t = system.pthread_rwlock_t;
pub const pthread_setname_np = system.pthread_setname_np;
pub const rlimit = system.rlimit;
pub const rlimit_resource = system.rlimit_resource;
pub const sched_getaffinity = system.sched_getaffinity;
pub const sem_t = system.sem_t;
pub const sendfile = system.sendfile;
pub const sigaltstack = system.sigaltstack;
pub const siginfo_t = system.siginfo_t;
pub const signalfd = system.signalfd;
pub const sigset_t = system.sigset_t;
pub const MAP = system.MAP;
pub const LOCK = system.LOCK;
pub const REG = system.REG;
pub const dl_iterate_phdr = system.dl_iterate_phdr;
pub const ino_t = system.ino_t;
pub const mode_t = system.mode_t;
pub const ucontext_t = system.ucontext_t;
pub const O = system.O;
pub const alarm = if (@hasDecl(system, "alarm")) system.alarm else generic.alarm;
pub const clock_getres = if (@hasDecl(system, "clock_getres")) system.clock_getres else generic.clock_getres;
pub const clock_gettime = if (@hasDecl(system, "clock_gettime")) system.clock_gettime else generic.clock_gettime;
pub const fstat = if (@hasDecl(system, "fstat")) system.fstat else generic.fstat;
pub const fstatat = if (@hasDecl(system, "fstatat")) system.fstatat else generic.fstatat;
pub const getrusage = if (@hasDecl(system, "getrusage")) system.getrusage else generic.getrusage;
pub const gettimeofday = if (@hasDecl(system, "gettimeofday")) system.gettimeofday else generic.gettimeofday;
pub const nanosleep = if (@hasDecl(system, "nanosleep")) system.nanosleep else generic.nanosleep;
pub const realpath = if (@hasDecl(system, "realpath")) system.realpath else generic.realpath;
pub const sched_yield = if (@hasDecl(system, "sched_yield")) system.sched_yield else generic.sched_yield;
pub const sigaction = if (@hasDecl(system, "sigaction")) system.sigaction else generic.sigaction;
pub const sigfillset = if (@hasDecl(system, "sigfillset")) system.sigfillset else generic.sigfillset;
pub const sigprocmask = if (@hasDecl(system, "sigprocmask")) system.sigprocmask else generic.sigprocmask;
pub const sigwait = if (@hasDecl(system, "sigwait")) system.sigwait else generic.sigwait;
pub const socket = if (@hasDecl(system, "socket")) system.socket else generic.socket;
pub const stat = if (@hasDecl(system, "stat")) system.stat else generic.stat;
pub fn getErrno(rc: anytype) E {
if (rc == -1) {
@ -47,9 +151,9 @@ pub fn versionCheck(glibc_version: builtin.Version) type {
return struct {
pub const ok = blk: {
if (!builtin.link_libc) break :blk false;
if (std.Target.current.abi.isMusl()) break :blk true;
if (std.Target.current.isGnuLibC()) {
const ver = std.Target.current.os.version_range.linux.glibc;
if (builtin.abi.isMusl()) break :blk true;
if (builtin.target.isGnuLibC()) {
const ver = builtin.os.version_range.linux.glibc;
const order = ver.order(glibc_version);
break :blk switch (order) {
.gt, .eq => true,
@ -115,17 +219,6 @@ pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;
pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
pub usingnamespace switch (builtin.os.tag) {
.macos, .ios, .watchos, .tvos => struct {
pub const realpath = @"realpath$DARWIN_EXTSN";
pub const fstatat = _fstatat;
},
else => struct {
pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int;
},
};
pub extern "c" fn rmdir(path: [*:0]const u8) c_int;
pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
@ -172,75 +265,6 @@ pub extern "c" fn recvfrom(
) isize;
pub extern "c" fn recvmsg(sockfd: fd_t, msg: *std.x.os.Socket.Message, flags: c_int) isize;
pub usingnamespace switch (builtin.os.tag) {
.netbsd => struct {
pub const clock_getres = __clock_getres50;
pub const clock_gettime = __clock_gettime50;
pub const fstat = __fstat50;
pub const getdents = __getdents30;
pub const getrusage = __getrusage50;
pub const gettimeofday = __gettimeofday50;
pub const nanosleep = __nanosleep50;
pub const sched_yield = __libc_thr_yield;
pub const sigaction = __sigaction14;
pub const sigaltstack = __sigaltstack14;
pub const sigprocmask = __sigprocmask14;
pub const socket = __socket30;
pub const stat = __stat50;
},
.macos, .ios, .watchos, .tvos => struct {
// XXX: close -> close$NOCANCEL
// XXX: getdirentries -> _getdirentries64
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
pub const fstat = _fstat;
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
pub extern "c" fn sched_yield() c_int;
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
pub extern "c" fn sigfillset(set: ?*sigset_t) void;
pub extern "c" fn alarm(seconds: c_uint) c_uint;
pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
},
.windows => struct {
// TODO: copied the else case and removed the socket function (because its in ws2_32)
// need to verify which of these is actually supported on windows
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
pub extern "c" fn sched_yield() c_int;
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
pub extern "c" fn sigfillset(set: ?*sigset_t) void;
pub extern "c" fn alarm(seconds: c_uint) c_uint;
pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
},
else => struct {
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
pub extern "c" fn sched_yield() c_int;
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
pub extern "c" fn sigfillset(set: ?*sigset_t) void;
pub extern "c" fn alarm(seconds: c_uint) c_uint;
pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
},
};
pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int;
pub extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
@ -375,9 +399,9 @@ pub extern "c" fn openlog(ident: [*:0]const u8, logopt: c_int, facility: c_int)
pub extern "c" fn closelog() void;
pub extern "c" fn setlogmask(maskpri: c_int) c_int;
pub const max_align_t = if (std.Target.current.abi == .msvc)
pub const max_align_t = if (builtin.abi == .msvc)
f64
else if (std.Target.current.isDarwin())
else if (builtin.target.isDarwin())
c_longdouble
else
extern struct {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

22
lib/std/c/generic.zig Normal file
View File

@ -0,0 +1,22 @@
const std = @import("../std.zig");
const Stat = std.c.Stat;
const timespec = std.c.timespec;
const Sigaction = std.c.Sigaction;
const sigset_t = std.c.sigset_t;
pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
pub extern "c" fn sched_yield() c_int;
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
pub extern "c" fn sigfillset(set: ?*sigset_t) void;
pub extern "c" fn alarm(seconds: c_uint) c_uint;
pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,66 @@
const std = @import("../std.zig");
const builtin = @import("builtin");
const maxInt = std.math.maxInt;
const abi = std.Target.current.abi;
const arch = std.Target.current.cpu.arch;
const os_tag = std.Target.current.os.tag;
usingnamespace std.c;
const native_abi = builtin.abi;
const native_arch = builtin.cpu.arch;
const linux = std.os.linux;
pub const _errno = switch (abi) {
pub const E = linux.E;
pub const Sigaction = linux.Sigaction;
pub const dl_phdr_info = linux.dl_phdr_info;
pub const fd_t = linux.fd_t;
pub const rlimit = linux.rlimit;
pub const rlimit_resource = linux.rlimit_resource;
pub const timespec = linux.timespec;
pub const NAME_MAX = linux.NAME_MAX;
pub const PATH_MAX = linux.PATH_MAX;
pub const IOV_MAX = linux.IOV_MAX;
pub const STDIN_FILENO = linux.STDIN_FILENO;
pub const STDOUT_FILENO = linux.STDIN_FILENO;
pub const STDERR_FILENO = linux.STDIN_FILENO;
pub const AT = linux.AT;
pub const PROT = linux.PROT;
pub const CLOCK = linux.CLOCK;
pub const SIG = linux.SIG;
pub const empty_sigset = linux.empty_sigset;
pub const S = linux.S;
pub const siginfo_t = linux.siginfo_t;
pub const SA = linux.SA;
pub const pollfd = linux.pollfd;
pub const sigset_t = linux.sigset_t;
pub const ARCH = linux.ARCH;
pub const Elf_Symndx = linux.Elf_Symndx;
pub const F = linux.F;
pub const Flock = linux.Flock;
pub const LOCK = linux.LOCK;
pub const MAP = linux.MAP;
pub const MMAP2_UNIT = linux.MMAP2_UNIT;
pub const O = linux.O;
pub const REG = linux.REG;
pub const SC = linux.SC;
pub const SYS = linux.SYS;
pub const VDSO = linux.VDSO;
pub const blkcnt_t = linux.blkcnt_t;
pub const blksize_t = linux.blksize_t;
pub const dev_t = linux.dev_t;
pub const ino_t = linux.ino_t;
pub const mcontext_t = linux.mcontext_t;
pub const mode_t = linux.mode_t;
pub const msghdr = linux.msghdr;
pub const msghdr_const = linux.msghdr_const;
pub const nlink_t = linux.nlink_t;
pub const off_t = linux.off_t;
pub const time_t = linux.time_t;
pub const timeval = linux.timeval;
pub const timezone = linux.timezone;
pub const ucontext_t = linux.ucontext_t;
pub const user_desc = linux.user_desc;
pub const pid_t = linux.pid_t;
pub const uid_t = linux.uid_t;
pub const gid_t = linux.gid_t;
pub const clock_t = linux.clock_t;
pub const _errno = switch (native_abi) {
.android => struct {
extern "c" var __errno: c_int;
fn getErrno() *c_int {
@ -17,22 +72,94 @@ pub const _errno = switch (abi) {
}.__errno_location,
};
pub const Stat = switch (native_arch) {
.sparcv9 => extern struct {
dev: u64,
ino: ino_t,
mode: u32,
nlink: usize,
uid: u32,
gid: u32,
rdev: u64,
__pad0: u32,
size: off_t,
blksize: isize,
blocks: i64,
atim: timespec,
mtim: timespec,
ctim: timespec,
__unused: [2]isize,
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
},
.mips, .mipsel => extern struct {
dev: dev_t,
__pad0: [2]u32,
ino: ino_t,
mode: mode_t,
nlink: nlink_t,
uid: uid_t,
gid: gid_t,
rdev: dev_t,
__pad1: [2]u32,
size: off_t,
atim: timespec,
mtim: timespec,
ctim: timespec,
blksize: blksize_t,
__pad3: u32,
blocks: blkcnt_t,
__pad4: [14]u32,
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
},
else => std.os.linux.Stat, // libc stat is the same as kernel stat.
};
pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
pub const AI_PASSIVE = 0x01;
pub const AI_CANONNAME = 0x02;
pub const AI_NUMERICHOST = 0x04;
pub const AI_V4MAPPED = 0x08;
pub const AI_ALL = 0x10;
pub const AI_ADDRCONFIG = 0x20;
pub const AI_NUMERICSERV = 0x400;
pub const AI = struct {
pub const PASSIVE = 0x01;
pub const CANONNAME = 0x02;
pub const NUMERICHOST = 0x04;
pub const V4MAPPED = 0x08;
pub const ALL = 0x10;
pub const ADDRCONFIG = 0x20;
pub const NUMERICSERV = 0x400;
};
pub const NI_NUMERICHOST = 0x01;
pub const NI_NUMERICSERV = 0x02;
pub const NI_NOFQDN = 0x04;
pub const NI_NAMEREQD = 0x08;
pub const NI_DGRAM = 0x10;
pub const NI_NUMERICSCOPE = 0x100;
pub const NI = struct {
pub const NUMERICHOST = 0x01;
pub const NUMERICSERV = 0x02;
pub const NOFQDN = 0x04;
pub const NAMEREQD = 0x08;
pub const DGRAM = 0x10;
pub const NUMERICSCOPE = 0x100;
};
pub const EAI = enum(c_int) {
BADFLAGS = -1,
@ -60,8 +187,8 @@ pub const EAI = enum(c_int) {
pub extern "c" fn fallocate64(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
pub extern "c" fn fopen64(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
pub extern "c" fn fstat64(fd: fd_t, buf: *libc_stat) c_int;
pub extern "c" fn fstatat64(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int;
pub extern "c" fn fstat64(fd: fd_t, buf: *Stat) c_int;
pub extern "c" fn fstatat64(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
pub extern "c" fn ftruncate64(fd: c_int, length: off_t) c_int;
pub extern "c" fn getrlimit64(resource: rlimit_resource, rlim: *rlimit) c_int;
pub extern "c" fn lseek64(fd: fd_t, offset: i64, whence: c_int) i64;
@ -137,7 +264,7 @@ pub const pthread_mutex_t = extern struct {
pub const pthread_cond_t = extern struct {
size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,
};
pub const pthread_rwlock_t = switch (abi) {
pub const pthread_rwlock_t = switch (native_abi) {
.android => switch (@sizeOf(usize)) {
4 => extern struct {
lock: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER,
@ -168,11 +295,11 @@ pub const sem_t = extern struct {
};
const __SIZEOF_PTHREAD_COND_T = 48;
const __SIZEOF_PTHREAD_MUTEX_T = if (os_tag == .fuchsia) 40 else switch (abi) {
const __SIZEOF_PTHREAD_MUTEX_T = switch (native_abi) {
.musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,
.gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (arch) {
.gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (native_arch) {
.aarch64 => 48,
.x86_64 => if (abi == .gnux32) 40 else 32,
.x86_64 => if (native_abi == .gnux32) 40 else 32,
.mips64, .powerpc64, .powerpc64le, .sparcv9 => 40,
else => if (@sizeOf(usize) == 8) 40 else 24,
},
@ -184,9 +311,11 @@ const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
pub const RTLD_LAZY = 1;
pub const RTLD_NOW = 2;
pub const RTLD_NOLOAD = 4;
pub const RTLD_NODELETE = 4096;
pub const RTLD_GLOBAL = 256;
pub const RTLD_LOCAL = 0;
pub const RTLD = struct {
pub const LAZY = 1;
pub const NOW = 2;
pub const NOLOAD = 4;
pub const NODELETE = 4096;
pub const GLOBAL = 256;
pub const LOCAL = 0;
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -4,12 +4,13 @@ pub fn _errno() *c_int {
return &errno;
}
pub const fd_t = c_int;
pub const pid_t = c_int;
pub const uid_t = u32;
pub const gid_t = u32;
pub const off_t = i64;
pub const libc_stat = extern struct {
pub const Stat = extern struct {
dev: i32,
ino: ino_t,
nlink: u64,
@ -51,3 +52,27 @@ pub const libc_stat = extern struct {
};
}
};
/// Derived from
/// https://github.com/WebAssembly/wasi-libc/blob/main/expected/wasm32-wasi/predefined-macros.txt
pub const O = struct {
pub const ACCMODE = (EXEC | RDWR | SEARCH);
pub const APPEND = FDFLAG_APPEND;
pub const CLOEXEC = (0);
pub const CREAT = ((1 << 0) << 12); // = __WASI_OFLAGS_CREAT << 12
pub const DIRECTORY = ((1 << 1) << 12); // = __WASI_OFLAGS_DIRECTORY << 12
pub const DSYNC = FDFLAG_DSYNC;
pub const EXCL = ((1 << 2) << 12); // = __WASI_OFLAGS_EXCL << 12
pub const EXEC = (0x02000000);
pub const NOCTTY = (0);
pub const NOFOLLOW = (0x01000000);
pub const NONBLOCK = (1 << FDFLAG_NONBLOCK);
pub const RDONLY = (0x04000000);
pub const RDWR = (RDONLY | WRONLY);
pub const RSYNC = (1 << FDFLAG_RSYNC);
pub const SEARCH = (0x08000000);
pub const SYNC = (1 << FDFLAG_SYNC);
pub const TRUNC = ((1 << 3) << 12); // = __WASI_OFLAGS_TRUNC << 12
pub const TTY_INIT = (0);
pub const WRONLY = (0x10000000);
};

View File

@ -1,3 +1,343 @@
//! The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
const ws2_32 = @import("../os/windows/ws2_32.zig");
pub extern "c" fn _errno() *c_int;
pub extern "c" fn _msize(memblock: ?*c_void) usize;
// TODO: copied the else case and removed the socket function (because its in ws2_32)
// need to verify which of these is actually supported on windows
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
pub extern "c" fn sched_yield() c_int;
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
pub extern "c" fn sigfillset(set: ?*sigset_t) void;
pub extern "c" fn alarm(seconds: c_uint) c_uint;
pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
pub const fd_t = HANDLE;
pub const ino_t = LARGE_INTEGER;
pub const pid_t = HANDLE;
pub const mode_t = u0;
pub const PATH_MAX = 260;
pub const time_t = c_longlong;
pub const timespec = extern struct {
tv_sec: time_t,
tv_nsec: c_long,
};
pub const timeval = extern struct {
tv_sec: c_long,
tv_usec: c_long,
};
pub const sig_atomic_t = c_int;
/// maximum signal number + 1
pub const NSIG = 23;
// Signal types
/// interrupt
pub const SIGINT = 2;
/// illegal instruction - invalid function image
pub const SIGILL = 4;
/// floating point exception
pub const SIGFPE = 8;
/// segment violation
pub const SIGSEGV = 11;
/// Software termination signal from kill
pub const SIGTERM = 15;
/// Ctrl-Break sequence
pub const SIGBREAK = 21;
/// abnormal termination triggered by abort call
pub const SIGABRT = 22;
/// SIGABRT compatible with other platforms, same as SIGABRT
pub const SIGABRT_COMPAT = 6;
// Signal action codes
/// default signal action
pub const SIG_DFL = 0;
/// ignore signal
pub const SIG_IGN = 1;
/// return current value
pub const SIG_GET = 2;
/// signal gets error
pub const SIG_SGE = 3;
/// acknowledge
pub const SIG_ACK = 4;
/// Signal error value (returned by signal call on error)
pub const SIG_ERR = -1;
pub const SEEK_SET = 0;
pub const SEEK_CUR = 1;
pub const SEEK_END = 2;
pub const E = enum(u16) {
/// No error occurred.
SUCCESS = 0,
PERM = 1,
NOENT = 2,
SRCH = 3,
INTR = 4,
IO = 5,
NXIO = 6,
@"2BIG" = 7,
NOEXEC = 8,
BADF = 9,
CHILD = 10,
AGAIN = 11,
NOMEM = 12,
ACCES = 13,
FAULT = 14,
BUSY = 16,
EXIST = 17,
XDEV = 18,
NODEV = 19,
NOTDIR = 20,
ISDIR = 21,
NFILE = 23,
MFILE = 24,
NOTTY = 25,
FBIG = 27,
NOSPC = 28,
SPIPE = 29,
ROFS = 30,
MLINK = 31,
PIPE = 32,
DOM = 33,
/// Also means `DEADLOCK`.
DEADLK = 36,
NAMETOOLONG = 38,
NOLCK = 39,
NOSYS = 40,
NOTEMPTY = 41,
INVAL = 22,
RANGE = 34,
ILSEQ = 42,
// POSIX Supplement
ADDRINUSE = 100,
ADDRNOTAVAIL = 101,
AFNOSUPPORT = 102,
ALREADY = 103,
BADMSG = 104,
CANCELED = 105,
CONNABORTED = 106,
CONNREFUSED = 107,
CONNRESET = 108,
DESTADDRREQ = 109,
HOSTUNREACH = 110,
IDRM = 111,
INPROGRESS = 112,
ISCONN = 113,
LOOP = 114,
MSGSIZE = 115,
NETDOWN = 116,
NETRESET = 117,
NETUNREACH = 118,
NOBUFS = 119,
NODATA = 120,
NOLINK = 121,
NOMSG = 122,
NOPROTOOPT = 123,
NOSR = 124,
NOSTR = 125,
NOTCONN = 126,
NOTRECOVERABLE = 127,
NOTSOCK = 128,
NOTSUP = 129,
OPNOTSUPP = 130,
OTHER = 131,
OVERFLOW = 132,
OWNERDEAD = 133,
PROTO = 134,
PROTONOSUPPORT = 135,
PROTOTYPE = 136,
TIME = 137,
TIMEDOUT = 138,
TXTBSY = 139,
WOULDBLOCK = 140,
DQUOT = 10069,
_,
};
pub const STRUNCATE = 80;
pub const F_OK = 0;
/// Remove directory instead of unlinking file
pub const AT_REMOVEDIR = 0x200;
pub const in_port_t = u16;
pub const sa_family_t = ws2_32.ADDRESS_FAMILY;
pub const socklen_t = ws2_32.socklen_t;
pub const sockaddr = ws2_32.sockaddr;
pub const sockaddr_in = ws2_32.sockaddr_in;
pub const sockaddr_in6 = ws2_32.sockaddr_in6;
pub const sockaddr_un = ws2_32.sockaddr_un;
pub const in6_addr = [16]u8;
pub const in_addr = u32;
pub const addrinfo = ws2_32.addrinfo;
pub const AF_UNSPEC = ws2_32.AF_UNSPEC;
pub const AF_UNIX = ws2_32.AF_UNIX;
pub const AF_INET = ws2_32.AF_INET;
pub const AF_IMPLINK = ws2_32.AF_IMPLINK;
pub const AF_PUP = ws2_32.AF_PUP;
pub const AF_CHAOS = ws2_32.AF_CHAOS;
pub const AF_NS = ws2_32.AF_NS;
pub const AF_IPX = ws2_32.AF_IPX;
pub const AF_ISO = ws2_32.AF_ISO;
pub const AF_OSI = ws2_32.AF_OSI;
pub const AF_ECMA = ws2_32.AF_ECMA;
pub const AF_DATAKIT = ws2_32.AF_DATAKIT;
pub const AF_CCITT = ws2_32.AF_CCITT;
pub const AF_SNA = ws2_32.AF_SNA;
pub const AF_DECnet = ws2_32.AF_DECnet;
pub const AF_DLI = ws2_32.AF_DLI;
pub const AF_LAT = ws2_32.AF_LAT;
pub const AF_HYLINK = ws2_32.AF_HYLINK;
pub const AF_APPLETALK = ws2_32.AF_APPLETALK;
pub const AF_NETBIOS = ws2_32.AF_NETBIOS;
pub const AF_VOICEVIEW = ws2_32.AF_VOICEVIEW;
pub const AF_FIREFOX = ws2_32.AF_FIREFOX;
pub const AF_UNKNOWN1 = ws2_32.AF_UNKNOWN1;
pub const AF_BAN = ws2_32.AF_BAN;
pub const AF_ATM = ws2_32.AF_ATM;
pub const AF_INET6 = ws2_32.AF_INET6;
pub const AF_CLUSTER = ws2_32.AF_CLUSTER;
pub const AF_12844 = ws2_32.AF_12844;
pub const AF_IRDA = ws2_32.AF_IRDA;
pub const AF_NETDES = ws2_32.AF_NETDES;
pub const AF_TCNPROCESS = ws2_32.AF_TCNPROCESS;
pub const AF_TCNMESSAGE = ws2_32.AF_TCNMESSAGE;
pub const AF_ICLFXBM = ws2_32.AF_ICLFXBM;
pub const AF_BTH = ws2_32.AF_BTH;
pub const AF_MAX = ws2_32.AF_MAX;
pub const SOCK_STREAM = ws2_32.SOCK_STREAM;
pub const SOCK_DGRAM = ws2_32.SOCK_DGRAM;
pub const SOCK_RAW = ws2_32.SOCK_RAW;
pub const SOCK_RDM = ws2_32.SOCK_RDM;
pub const SOCK_SEQPACKET = ws2_32.SOCK_SEQPACKET;
/// WARNING: this flag is not supported by windows socket functions directly,
/// it is only supported by std.os.socket. Be sure that this value does
/// not share any bits with any of the SOCK_* values.
pub const SOCK_CLOEXEC = 0x10000;
/// WARNING: this flag is not supported by windows socket functions directly,
/// it is only supported by std.os.socket. Be sure that this value does
/// not share any bits with any of the SOCK_* values.
pub const SOCK_NONBLOCK = 0x20000;
pub const IPPROTO_ICMP = ws2_32.IPPROTO_ICMP;
pub const IPPROTO_IGMP = ws2_32.IPPROTO_IGMP;
pub const BTHPROTO_RFCOMM = ws2_32.BTHPROTO_RFCOMM;
pub const IPPROTO_TCP = ws2_32.IPPROTO_TCP;
pub const IPPROTO_UDP = ws2_32.IPPROTO_UDP;
pub const IPPROTO_ICMPV6 = ws2_32.IPPROTO_ICMPV6;
pub const IPPROTO_RM = ws2_32.IPPROTO_RM;
pub const nfds_t = c_ulong;
pub const pollfd = ws2_32.pollfd;
pub const POLLRDNORM = ws2_32.POLLRDNORM;
pub const POLLRDBAND = ws2_32.POLLRDBAND;
pub const POLLIN = ws2_32.POLLIN;
pub const POLLPRI = ws2_32.POLLPRI;
pub const POLLWRNORM = ws2_32.POLLWRNORM;
pub const POLLOUT = ws2_32.POLLOUT;
pub const POLLWRBAND = ws2_32.POLLWRBAND;
pub const POLLERR = ws2_32.POLLERR;
pub const POLLHUP = ws2_32.POLLHUP;
pub const POLLNVAL = ws2_32.POLLNVAL;
pub const SOL_SOCKET = ws2_32.SOL_SOCKET;
pub const SO_DEBUG = ws2_32.SO_DEBUG;
pub const SO_ACCEPTCONN = ws2_32.SO_ACCEPTCONN;
pub const SO_REUSEADDR = ws2_32.SO_REUSEADDR;
pub const SO_KEEPALIVE = ws2_32.SO_KEEPALIVE;
pub const SO_DONTROUTE = ws2_32.SO_DONTROUTE;
pub const SO_BROADCAST = ws2_32.SO_BROADCAST;
pub const SO_USELOOPBACK = ws2_32.SO_USELOOPBACK;
pub const SO_LINGER = ws2_32.SO_LINGER;
pub const SO_OOBINLINE = ws2_32.SO_OOBINLINE;
pub const SO_DONTLINGER = ws2_32.SO_DONTLINGER;
pub const SO_EXCLUSIVEADDRUSE = ws2_32.SO_EXCLUSIVEADDRUSE;
pub const SO_SNDBUF = ws2_32.SO_SNDBUF;
pub const SO_RCVBUF = ws2_32.SO_RCVBUF;
pub const SO_SNDLOWAT = ws2_32.SO_SNDLOWAT;
pub const SO_RCVLOWAT = ws2_32.SO_RCVLOWAT;
pub const SO_SNDTIMEO = ws2_32.SO_SNDTIMEO;
pub const SO_RCVTIMEO = ws2_32.SO_RCVTIMEO;
pub const SO_ERROR = ws2_32.SO_ERROR;
pub const SO_TYPE = ws2_32.SO_TYPE;
pub const SO_GROUP_ID = ws2_32.SO_GROUP_ID;
pub const SO_GROUP_PRIORITY = ws2_32.SO_GROUP_PRIORITY;
pub const SO_MAX_MSG_SIZE = ws2_32.SO_MAX_MSG_SIZE;
pub const SO_PROTOCOL_INFOA = ws2_32.SO_PROTOCOL_INFOA;
pub const SO_PROTOCOL_INFOW = ws2_32.SO_PROTOCOL_INFOW;
pub const PVD_CONFIG = ws2_32.PVD_CONFIG;
pub const SO_CONDITIONAL_ACCEPT = ws2_32.SO_CONDITIONAL_ACCEPT;
pub const TCP_NODELAY = ws2_32.TCP_NODELAY;
pub const O_RDONLY = 0o0;
pub const O_WRONLY = 0o1;
pub const O_RDWR = 0o2;
pub const O_CREAT = 0o100;
pub const O_EXCL = 0o200;
pub const O_NOCTTY = 0o400;
pub const O_TRUNC = 0o1000;
pub const O_APPEND = 0o2000;
pub const O_NONBLOCK = 0o4000;
pub const O_DSYNC = 0o10000;
pub const O_SYNC = 0o4010000;
pub const O_RSYNC = 0o4010000;
pub const O_DIRECTORY = 0o200000;
pub const O_NOFOLLOW = 0o400000;
pub const O_CLOEXEC = 0o2000000;
pub const O_ASYNC = 0o20000;
pub const O_DIRECT = 0o40000;
pub const O_LARGEFILE = 0;
pub const O_NOATIME = 0o1000000;
pub const O_PATH = 0o10000000;
pub const O_TMPFILE = 0o20200000;
pub const O_NDELAY = O_NONBLOCK;
pub const IFNAMESIZE = 30;

View File

@ -471,7 +471,7 @@ pub const Dir = struct {
continue :start_over;
}
var stat_info: os.libc_stat = undefined;
var stat_info: os.Stat = undefined;
_ = os.system._kern_read_stat(
self.dir.fd,
&haiku_entry.d_name,

View File

@ -40,15 +40,10 @@ comptime {
}
test {
_ = darwin;
_ = freebsd;
_ = linux;
_ = netbsd;
_ = openbsd;
_ = uefi;
_ = wasi;
_ = windows;
_ = haiku;
_ = @import("os/test.zig");
}
@ -61,85 +56,68 @@ pub const system = if (@hasDecl(root, "os") and root.os != @This())
else if (builtin.link_libc)
std.c
else switch (builtin.os.tag) {
.macos, .ios, .watchos, .tvos => darwin,
.freebsd => freebsd,
.haiku => haiku,
.linux => linux,
.netbsd => netbsd,
.openbsd => openbsd,
.dragonfly => dragonfly,
.wasi => wasi,
.windows => windows,
.uefi => uefi,
else => struct {},
};
const bits = switch (builtin.os.tag) {
.macos, .ios, .tvos, .watchos => std.c,
.dragonfly => @import("os/bits/dragonfly.zig"),
.freebsd => @import("os/bits/freebsd.zig"),
.haiku => @import("os/bits/haiku.zig"),
.linux => linux,
.netbsd => @import("os/bits/netbsd.zig"),
.openbsd => @import("os/bits/openbsd.zig"),
.wasi => @import("os/bits/wasi.zig"),
.windows => @import("os/bits/windows.zig"),
else => struct {},
};
pub const E = bits.E;
pub const ARCH = bits.ARCH;
pub const Elf_Symndx = bits.Elf_Symndx;
pub const F = bits.F;
pub const Flock = bits.Flock;
pub const LOCK = bits.LOCK;
pub const MAP = bits.MAP;
pub const MMAP2_UNIT = bits.MMAP2_UNIT;
pub const O = bits.O;
pub const REG = bits.REG;
pub const SC = bits.SC;
pub const SYS = bits.SYS;
pub const VDSO = bits.VDSO;
pub const blkcnt_t = bits.blkcnt_t;
pub const blksize_t = bits.blksize_t;
pub const dev_t = bits.dev_t;
pub const ino_t = bits.ino_t;
pub const kernel_stat = bits.kernel_stat;
pub const libc_stat = bits.libc_stat;
pub const mcontext_t = bits.mcontext_t;
pub const mode_t = bits.mode_t;
pub const msghdr = bits.msghdr;
pub const msghdr_const = bits.msghdr_const;
pub const nlink_t = bits.nlink_t;
pub const off_t = bits.off_t;
pub const time_t = bits.time_t;
pub const timespec = bits.timespec;
pub const timeval = bits.timeval;
pub const timezone = bits.timezone;
pub const ucontext_t = bits.ucontext_t;
pub const user_desc = bits.user_desc;
pub const pid_t = bits.pid_t;
pub const fd_t = bits.fd_t;
pub const uid_t = bits.uid_t;
pub const gid_t = bits.gid_t;
pub const clock_t = bits.clock_t;
pub const NAME_MAX = bits.NAME_MAX;
pub const PATH_MAX = bits.PATH_MAX;
pub const IOV_MAX = bits.IOV_MAX;
pub const MAX_ADDR_LEN = bits.MAX_ADDR_LEN;
pub const STDIN_FILENO = bits.STDIN_FILENO;
pub const STDOUT_FILENO = bits.STDIN_FILENO;
pub const STDERR_FILENO = bits.STDIN_FILENO;
pub const AT = bits.AT;
pub const PROT = bits.PROT;
pub const CLOCK = bits.CLOCK;
pub const dl_phdr_info = bits.dl_phdr_info;
pub const Sigaction = bits.Sigaction;
pub const rlimit_resource = bits.rlimit_resource;
pub const SIG = bits.SIG;
pub const rlimit = bits.rlimit;
pub const empty_sigset = bits.empty_sigset;
pub const S = bits.S;
pub const siginfo_t = bits.siginfo_t;
pub const SA = bits.SA;
pub const ARCH = system.ARCH;
pub const AT = system.AT;
pub const CLOCK = system.CLOCK;
pub const E = system.E;
pub const Elf_Symndx = system.Elf_Symndx;
pub const F = system.F;
pub const Flock = system.Flock;
pub const IOV_MAX = system.IOV_MAX;
pub const LOCK = system.LOCK;
pub const MAP = system.MAP;
pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;
pub const MMAP2_UNIT = system.MMAP2_UNIT;
pub const NAME_MAX = system.NAME_MAX;
pub const O = system.O;
pub const PATH_MAX = system.PATH_MAX;
pub const PROT = system.PROT;
pub const REG = system.REG;
pub const S = system.S;
pub const SA = system.SA;
pub const SC = system.SC;
pub const SIG = system.SIG;
pub const STDERR_FILENO = system.STDIN_FILENO;
pub const STDIN_FILENO = system.STDIN_FILENO;
pub const STDOUT_FILENO = system.STDIN_FILENO;
pub const SYS = system.SYS;
pub const Sigaction = system.Sigaction;
pub const Stat = system.Stat;
pub const VDSO = system.VDSO;
pub const blkcnt_t = system.blkcnt_t;
pub const blksize_t = system.blksize_t;
pub const clock_t = system.clock_t;
pub const dev_t = system.dev_t;
pub const dl_phdr_info = system.dl_phdr_info;
pub const empty_sigset = system.empty_sigset;
pub const fd_t = system.fd_t;
pub const gid_t = system.gid_t;
pub const ino_t = system.ino_t;
pub const mcontext_t = system.mcontext_t;
pub const mode_t = system.mode_t;
pub const msghdr = system.msghdr;
pub const msghdr_const = system.msghdr_const;
pub const nlink_t = system.nlink_t;
pub const off_t = system.off_t;
pub const pid_t = system.pid_t;
pub const pollfd = system.pollfd;
pub const rlimit = system.rlimit;
pub const rlimit_resource = system.rlimit_resource;
pub const siginfo_t = system.siginfo_t;
pub const sigset_t = system.sigset_t;
pub const time_t = system.time_t;
pub const timespec = system.timespec;
pub const timeval = system.timeval;
pub const timezone = system.timezone;
pub const ucontext_t = system.ucontext_t;
pub const uid_t = system.uid_t;
pub const user_desc = system.user_desc;
pub const iovec = extern struct {
iov_base: [*]u8,
@ -334,7 +312,7 @@ pub fn raise(sig: u8) RaiseError!void {
}
if (builtin.os.tag == .linux) {
var set: bits.sigset_t = undefined;
var set: sigset_t = undefined;
// block application signals
_ = linux.sigprocmask(SIG.BLOCK, &linux.app_mask, &set);
@ -3558,11 +3536,6 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
}
}
pub const Stat = if (builtin.link_libc)
system.libc_stat
else
system.kernel_stat;
pub const FStatError = error{
SystemResources,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -551,7 +551,7 @@ pub const dev_t = u64;
pub const blkcnt_t = i64;
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
pub const Stat = extern struct {
dev: dev_t,
__dev_padding: u32,
__ino_truncated: u32,
@ -582,9 +582,6 @@ pub const kernel_stat = extern struct {
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const timespec = extern struct {
tv_sec: i32,
tv_nsec: i32,

View File

@ -424,7 +424,7 @@ pub const dev_t = usize;
pub const blkcnt_t = isize;
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
pub const Stat = extern struct {
dev: dev_t,
ino: ino_t,
mode: mode_t,
@ -455,9 +455,6 @@ pub const kernel_stat = extern struct {
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const timespec = extern struct {
tv_sec: time_t,
tv_nsec: isize,

View File

@ -599,7 +599,7 @@ pub const dev_t = u64;
pub const blkcnt_t = i64;
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
pub const Stat = extern struct {
dev: dev_t,
__dev_padding: u32,
__ino_truncated: u32,
@ -630,9 +630,6 @@ pub const kernel_stat = extern struct {
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const timespec = extern struct {
tv_sec: i32,
tv_nsec: i32,

View File

@ -540,7 +540,7 @@ pub const dev_t = u64;
pub const blkcnt_t = i64;
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
pub const Stat = extern struct {
dev: u32,
__pad0: [3]u32, // Reserved for st_dev expansion
ino: ino_t,
@ -572,38 +572,6 @@ pub const kernel_stat = extern struct {
}
};
pub const libc_stat = extern struct {
dev: dev_t,
__pad0: [2]u32,
ino: ino_t,
mode: mode_t,
nlink: nlink_t,
uid: uid_t,
gid: gid_t,
rdev: dev_t,
__pad1: [2]u32,
size: off_t,
atim: timespec,
mtim: timespec,
ctim: timespec,
blksize: blksize_t,
__pad3: u32,
blocks: blkcnt_t,
__pad4: [14]u32,
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
};
pub const timespec = extern struct {
tv_sec: isize,
tv_nsec: isize,

View File

@ -539,7 +539,7 @@ pub const dev_t = u64;
pub const blkcnt_t = i64;
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
pub const Stat = extern struct {
dev: dev_t,
ino: ino_t,
mode: mode_t,
@ -569,9 +569,6 @@ pub const kernel_stat = extern struct {
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const timespec = extern struct {
tv_sec: time_t,
tv_nsec: isize,

View File

@ -515,7 +515,7 @@ pub const dev_t = u64;
pub const blkcnt_t = i64;
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
pub const Stat = extern struct {
dev: dev_t,
ino: ino_t,
nlink: nlink_t,
@ -544,9 +544,6 @@ pub const kernel_stat = extern struct {
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const timespec = extern struct {
tv_sec: time_t,
tv_nsec: isize,

View File

@ -386,7 +386,7 @@ pub const Flock = extern struct {
};
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
pub const Stat = extern struct {
dev: dev_t,
ino: ino_t,
mode: mode_t,
@ -417,7 +417,4 @@ pub const kernel_stat = extern struct {
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const Elf_Symndx = u32;

View File

@ -489,42 +489,8 @@ pub const off_t = i64;
pub const ino_t = u64;
pub const mode_t = u32;
// The `stat64` definition used by the libc.
pub const libc_stat = extern struct {
dev: u64,
ino: ino_t,
mode: u32,
nlink: usize,
uid: u32,
gid: u32,
rdev: u64,
__pad0: u32,
size: off_t,
blksize: isize,
blocks: i64,
atim: timespec,
mtim: timespec,
ctim: timespec,
__unused: [2]isize,
pub fn atime(self: libc_stat) timespec {
return self.atim;
}
pub fn mtime(self: libc_stat) timespec {
return self.mtim;
}
pub fn ctime(self: libc_stat) timespec {
return self.ctim;
}
};
// The `stat64` definition used by the kernel.
pub const kernel_stat = extern struct {
pub const Stat = extern struct {
dev: u64,
ino: u64,
nlink: u64,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,491 +0,0 @@
// Convenience types and consts used by std.os module
const builtin = @import("builtin");
pub const iovec = posix.iovec;
pub const iovec_const = posix.iovec_const;
pub const STDIN_FILENO = 0;
pub const STDOUT_FILENO = 1;
pub const STDERR_FILENO = 2;
pub const mode_t = u32;
pub const time_t = i64; // match https://github.com/CraneStation/wasi-libc
pub const timespec = struct {
tv_sec: time_t,
tv_nsec: isize,
pub fn fromTimestamp(tm: timestamp_t) timespec {
const tv_sec: timestamp_t = tm / 1_000_000_000;
const tv_nsec = tm - tv_sec * 1_000_000_000;
return timespec{
.tv_sec = @intCast(time_t, tv_sec),
.tv_nsec = @intCast(isize, tv_nsec),
};
}
pub fn toTimestamp(ts: timespec) timestamp_t {
const tm = @intCast(timestamp_t, ts.tv_sec * 1_000_000_000) + @intCast(timestamp_t, ts.tv_nsec);
return tm;
}
};
pub const kernel_stat = struct {
dev: device_t,
ino: inode_t,
mode: mode_t,
filetype: filetype_t,
nlink: linkcount_t,
size: filesize_t,
atim: timespec,
mtim: timespec,
ctim: timespec,
const Self = @This();
pub fn fromFilestat(stat: filestat_t) Self {
return Self{
.dev = stat.dev,
.ino = stat.ino,
.mode = 0,
.filetype = stat.filetype,
.nlink = stat.nlink,
.size = stat.size,
.atim = stat.atime(),
.mtim = stat.mtime(),
.ctim = stat.ctime(),
};
}
pub fn atime(self: Self) timespec {
return self.atim;
}
pub fn mtime(self: Self) timespec {
return self.mtim;
}
pub fn ctime(self: Self) timespec {
return self.ctim;
}
};
pub const IOV_MAX = 1024;
pub const AT_REMOVEDIR: u32 = 0x4;
pub const AT_FDCWD: fd_t = -2;
// As defined in the wasi_snapshot_preview1 spec file:
// https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/witx/typenames.witx
pub const advice_t = u8;
pub const ADVICE_NORMAL: advice_t = 0;
pub const ADVICE_SEQUENTIAL: advice_t = 1;
pub const ADVICE_RANDOM: advice_t = 2;
pub const ADVICE_WILLNEED: advice_t = 3;
pub const ADVICE_DONTNEED: advice_t = 4;
pub const ADVICE_NOREUSE: advice_t = 5;
pub const clockid_t = u32;
pub const CLOCK = struct {
pub const REALTIME: clockid_t = 0;
pub const MONOTONIC: clockid_t = 1;
pub const PROCESS_CPUTIME_ID: clockid_t = 2;
pub const THREAD_CPUTIME_ID: clockid_t = 3;
};
pub const device_t = u64;
pub const dircookie_t = u64;
pub const DIRCOOKIE_START: dircookie_t = 0;
pub const dirnamlen_t = u32;
pub const dirent_t = extern struct {
d_next: dircookie_t,
d_ino: inode_t,
d_namlen: dirnamlen_t,
d_type: filetype_t,
};
pub const errno_t = enum(u16) {
SUCCESS = 0,
@"2BIG" = 1,
ACCES = 2,
ADDRINUSE = 3,
ADDRNOTAVAIL = 4,
AFNOSUPPORT = 5,
/// This is also the error code used for `WOULDBLOCK`.
AGAIN = 6,
ALREADY = 7,
BADF = 8,
BADMSG = 9,
BUSY = 10,
CANCELED = 11,
CHILD = 12,
CONNABORTED = 13,
CONNREFUSED = 14,
CONNRESET = 15,
DEADLK = 16,
DESTADDRREQ = 17,
DOM = 18,
DQUOT = 19,
EXIST = 20,
FAULT = 21,
FBIG = 22,
HOSTUNREACH = 23,
IDRM = 24,
ILSEQ = 25,
INPROGRESS = 26,
INTR = 27,
INVAL = 28,
IO = 29,
ISCONN = 30,
ISDIR = 31,
LOOP = 32,
MFILE = 33,
MLINK = 34,
MSGSIZE = 35,
MULTIHOP = 36,
NAMETOOLONG = 37,
NETDOWN = 38,
NETRESET = 39,
NETUNREACH = 40,
NFILE = 41,
NOBUFS = 42,
NODEV = 43,
NOENT = 44,
NOEXEC = 45,
NOLCK = 46,
NOLINK = 47,
NOMEM = 48,
NOMSG = 49,
NOPROTOOPT = 50,
NOSPC = 51,
NOSYS = 52,
NOTCONN = 53,
NOTDIR = 54,
NOTEMPTY = 55,
NOTRECOVERABLE = 56,
NOTSOCK = 57,
/// This is also the code used for `NOTSUP`.
OPNOTSUPP = 58,
NOTTY = 59,
NXIO = 60,
OVERFLOW = 61,
OWNERDEAD = 62,
PERM = 63,
PIPE = 64,
PROTO = 65,
PROTONOSUPPORT = 66,
PROTOTYPE = 67,
RANGE = 68,
ROFS = 69,
SPIPE = 70,
SRCH = 71,
STALE = 72,
TIMEDOUT = 73,
TXTBSY = 74,
XDEV = 75,
NOTCAPABLE = 76,
_,
};
pub const E = errno_t;
pub const event_t = extern struct {
userdata: userdata_t,
@"error": errno_t,
@"type": eventtype_t,
fd_readwrite: eventfdreadwrite_t,
};
pub const eventfdreadwrite_t = extern struct {
nbytes: filesize_t,
flags: eventrwflags_t,
};
pub const eventrwflags_t = u16;
pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001;
pub const eventtype_t = u8;
pub const EVENTTYPE_CLOCK: eventtype_t = 0;
pub const EVENTTYPE_FD_READ: eventtype_t = 1;
pub const EVENTTYPE_FD_WRITE: eventtype_t = 2;
pub const exitcode_t = u32;
pub const fd_t = if (builtin.link_libc) c_int else u32;
pub const fdflags_t = u16;
pub const FDFLAG_APPEND: fdflags_t = 0x0001;
pub const FDFLAG_DSYNC: fdflags_t = 0x0002;
pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004;
pub const FDFLAG_RSYNC: fdflags_t = 0x0008;
pub const FDFLAG_SYNC: fdflags_t = 0x0010;
pub const fdstat_t = extern struct {
fs_filetype: filetype_t,
fs_flags: fdflags_t,
fs_rights_base: rights_t,
fs_rights_inheriting: rights_t,
};
pub const filedelta_t = i64;
pub const filesize_t = u64;
pub const filestat_t = extern struct {
dev: device_t,
ino: inode_t,
filetype: filetype_t,
nlink: linkcount_t,
size: filesize_t,
atim: timestamp_t,
mtim: timestamp_t,
ctim: timestamp_t,
pub fn atime(self: filestat_t) timespec {
return timespec.fromTimestamp(self.atim);
}
pub fn mtime(self: filestat_t) timespec {
return timespec.fromTimestamp(self.mtim);
}
pub fn ctime(self: filestat_t) timespec {
return timespec.fromTimestamp(self.ctim);
}
};
pub const filetype_t = u8;
pub const FILETYPE_UNKNOWN: filetype_t = 0;
pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1;
pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2;
pub const FILETYPE_DIRECTORY: filetype_t = 3;
pub const FILETYPE_REGULAR_FILE: filetype_t = 4;
pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5;
pub const FILETYPE_SOCKET_STREAM: filetype_t = 6;
pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7;
pub const fstflags_t = u16;
pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001;
pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002;
pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004;
pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
pub const inode_t = u64;
pub const ino_t = inode_t;
pub const linkcount_t = u64;
pub const lookupflags_t = u32;
pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001;
pub usingnamespace if (builtin.link_libc) struct {
// Derived from https://github.com/WebAssembly/wasi-libc/blob/main/expected/wasm32-wasi/predefined-macros.txt
pub const O_ACCMODE = (O_EXEC | O_RDWR | O_SEARCH);
pub const O_APPEND = FDFLAG_APPEND;
pub const O_CLOEXEC = (0);
pub const O_CREAT = ((1 << 0) << 12); // = __WASI_OFLAGS_CREAT << 12
pub const O_DIRECTORY = ((1 << 1) << 12); // = __WASI_OFLAGS_DIRECTORY << 12
pub const O_DSYNC = FDFLAG_DSYNC;
pub const O_EXCL = ((1 << 2) << 12); // = __WASI_OFLAGS_EXCL << 12
pub const O_EXEC = (0x02000000);
pub const O_NOCTTY = (0);
pub const O_NOFOLLOW = (0x01000000);
pub const O_NONBLOCK = (1 << FDFLAG_NONBLOCK);
pub const O_RDONLY = (0x04000000);
pub const O_RDWR = (O_RDONLY | O_WRONLY);
pub const O_RSYNC = (1 << FDFLAG_RSYNC);
pub const O_SEARCH = (0x08000000);
pub const O_SYNC = (1 << FDFLAG_SYNC);
pub const O_TRUNC = ((1 << 3) << 12); // = __WASI_OFLAGS_TRUNC << 12
pub const O_TTY_INIT = (0);
pub const O_WRONLY = (0x10000000);
} else struct {
pub const oflags_t = u16;
pub const O_CREAT: oflags_t = 0x0001;
pub const O_DIRECTORY: oflags_t = 0x0002;
pub const O_EXCL: oflags_t = 0x0004;
pub const O_TRUNC: oflags_t = 0x0008;
};
pub const preopentype_t = u8;
pub const PREOPENTYPE_DIR: preopentype_t = 0;
pub const prestat_t = extern struct {
pr_type: preopentype_t,
u: prestat_u_t,
};
pub const prestat_dir_t = extern struct {
pr_name_len: usize,
};
pub const prestat_u_t = extern union {
dir: prestat_dir_t,
};
pub const riflags_t = u16;
pub const SOCK_RECV_PEEK: riflags_t = 0x0001;
pub const SOCK_RECV_WAITALL: riflags_t = 0x0002;
pub const rights_t = u64;
pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001;
pub const RIGHT_FD_READ: rights_t = 0x0000000000000002;
pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004;
pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008;
pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010;
pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020;
pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040;
pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080;
pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100;
pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200;
pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400;
pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800;
pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000;
pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000;
pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000;
pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000;
pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000;
pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000;
pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000;
pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000;
pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000;
pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000;
pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000;
pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000;
pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000;
pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000;
pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000;
pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000;
pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000;
pub const RIGHT_ALL: rights_t = RIGHT_FD_DATASYNC |
RIGHT_FD_READ |
RIGHT_FD_SEEK |
RIGHT_FD_FDSTAT_SET_FLAGS |
RIGHT_FD_SYNC |
RIGHT_FD_TELL |
RIGHT_FD_WRITE |
RIGHT_FD_ADVISE |
RIGHT_FD_ALLOCATE |
RIGHT_PATH_CREATE_DIRECTORY |
RIGHT_PATH_CREATE_FILE |
RIGHT_PATH_LINK_SOURCE |
RIGHT_PATH_LINK_TARGET |
RIGHT_PATH_OPEN |
RIGHT_FD_READDIR |
RIGHT_PATH_READLINK |
RIGHT_PATH_RENAME_SOURCE |
RIGHT_PATH_RENAME_TARGET |
RIGHT_PATH_FILESTAT_GET |
RIGHT_PATH_FILESTAT_SET_SIZE |
RIGHT_PATH_FILESTAT_SET_TIMES |
RIGHT_FD_FILESTAT_GET |
RIGHT_FD_FILESTAT_SET_SIZE |
RIGHT_FD_FILESTAT_SET_TIMES |
RIGHT_PATH_SYMLINK |
RIGHT_PATH_REMOVE_DIRECTORY |
RIGHT_PATH_UNLINK_FILE |
RIGHT_POLL_FD_READWRITE |
RIGHT_SOCK_SHUTDOWN;
pub const roflags_t = u16;
pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001;
pub const sdflags_t = u8;
pub const SHUT_RD: sdflags_t = 0x01;
pub const SHUT_WR: sdflags_t = 0x02;
pub const siflags_t = u16;
pub const signal_t = u8;
pub const SIGNONE: signal_t = 0;
pub const SIGHUP: signal_t = 1;
pub const SIGINT: signal_t = 2;
pub const SIGQUIT: signal_t = 3;
pub const SIGILL: signal_t = 4;
pub const SIGTRAP: signal_t = 5;
pub const SIGABRT: signal_t = 6;
pub const SIGBUS: signal_t = 7;
pub const SIGFPE: signal_t = 8;
pub const SIGKILL: signal_t = 9;
pub const SIGUSR1: signal_t = 10;
pub const SIGSEGV: signal_t = 11;
pub const SIGUSR2: signal_t = 12;
pub const SIGPIPE: signal_t = 13;
pub const SIGALRM: signal_t = 14;
pub const SIGTERM: signal_t = 15;
pub const SIGCHLD: signal_t = 16;
pub const SIGCONT: signal_t = 17;
pub const SIGSTOP: signal_t = 18;
pub const SIGTSTP: signal_t = 19;
pub const SIGTTIN: signal_t = 20;
pub const SIGTTOU: signal_t = 21;
pub const SIGURG: signal_t = 22;
pub const SIGXCPU: signal_t = 23;
pub const SIGXFSZ: signal_t = 24;
pub const SIGVTALRM: signal_t = 25;
pub const SIGPROF: signal_t = 26;
pub const SIGWINCH: signal_t = 27;
pub const SIGPOLL: signal_t = 28;
pub const SIGPWR: signal_t = 29;
pub const SIGSYS: signal_t = 30;
pub const subclockflags_t = u16;
pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001;
pub const subscription_t = extern struct {
userdata: userdata_t,
u: subscription_u_t,
};
pub const subscription_clock_t = extern struct {
id: clockid_t,
timeout: timestamp_t,
precision: timestamp_t,
flags: subclockflags_t,
};
pub const subscription_fd_readwrite_t = extern struct {
fd: fd_t,
};
pub const subscription_u_t = extern struct {
tag: eventtype_t,
u: subscription_u_u_t,
};
pub const subscription_u_u_t = extern union {
clock: subscription_clock_t,
fd_read: subscription_fd_readwrite_t,
fd_write: subscription_fd_readwrite_t,
};
pub const timestamp_t = u64;
pub const userdata_t = u64;
pub const whence_t = u8;
pub const WHENCE_SET: whence_t = 0;
pub const WHENCE_CUR: whence_t = 1;
pub const WHENCE_END: whence_t = 2;
pub const S_IEXEC = S_IXUSR;
pub const S_IFBLK = 0x6000;
pub const S_IFCHR = 0x2000;
pub const S_IFDIR = 0x4000;
pub const S_IFIFO = 0xc000;
pub const S_IFLNK = 0xa000;
pub const S_IFMT = S_IFBLK | S_IFCHR | S_IFDIR | S_IFIFO | S_IFLNK | S_IFREG | S_IFSOCK;
pub const S_IFREG = 0x8000;
// There's no concept of UNIX domain socket but we define this value here in order to line with other OSes.
pub const S_IFSOCK = 0x1;
pub const SEEK_SET = WHENCE_SET;
pub const SEEK_CUR = WHENCE_CUR;
pub const SEEK_END = WHENCE_END;
pub const LOCK_SH = 0x1;
pub const LOCK_EX = 0x2;
pub const LOCK_NB = 0x4;
pub const LOCK_UN = 0x8;

View File

@ -1,324 +0,0 @@
// The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
usingnamespace @import("../windows/bits.zig");
const ws2_32 = @import("../windows/ws2_32.zig");
pub const fd_t = HANDLE;
pub const ino_t = LARGE_INTEGER;
pub const pid_t = HANDLE;
pub const mode_t = u0;
pub const PATH_MAX = 260;
pub const time_t = c_longlong;
pub const timespec = extern struct {
tv_sec: time_t,
tv_nsec: c_long,
};
pub const timeval = extern struct {
tv_sec: c_long,
tv_usec: c_long,
};
pub const sig_atomic_t = c_int;
/// maximum signal number + 1
pub const NSIG = 23;
// Signal types
/// interrupt
pub const SIGINT = 2;
/// illegal instruction - invalid function image
pub const SIGILL = 4;
/// floating point exception
pub const SIGFPE = 8;
/// segment violation
pub const SIGSEGV = 11;
/// Software termination signal from kill
pub const SIGTERM = 15;
/// Ctrl-Break sequence
pub const SIGBREAK = 21;
/// abnormal termination triggered by abort call
pub const SIGABRT = 22;
/// SIGABRT compatible with other platforms, same as SIGABRT
pub const SIGABRT_COMPAT = 6;
// Signal action codes
/// default signal action
pub const SIG_DFL = 0;
/// ignore signal
pub const SIG_IGN = 1;
/// return current value
pub const SIG_GET = 2;
/// signal gets error
pub const SIG_SGE = 3;
/// acknowledge
pub const SIG_ACK = 4;
/// Signal error value (returned by signal call on error)
pub const SIG_ERR = -1;
pub const SEEK_SET = 0;
pub const SEEK_CUR = 1;
pub const SEEK_END = 2;
pub const E = enum(u16) {
/// No error occurred.
SUCCESS = 0,
PERM = 1,
NOENT = 2,
SRCH = 3,
INTR = 4,
IO = 5,
NXIO = 6,
@"2BIG" = 7,
NOEXEC = 8,
BADF = 9,
CHILD = 10,
AGAIN = 11,
NOMEM = 12,
ACCES = 13,
FAULT = 14,
BUSY = 16,
EXIST = 17,
XDEV = 18,
NODEV = 19,
NOTDIR = 20,
ISDIR = 21,
NFILE = 23,
MFILE = 24,
NOTTY = 25,
FBIG = 27,
NOSPC = 28,
SPIPE = 29,
ROFS = 30,
MLINK = 31,
PIPE = 32,
DOM = 33,
/// Also means `DEADLOCK`.
DEADLK = 36,
NAMETOOLONG = 38,
NOLCK = 39,
NOSYS = 40,
NOTEMPTY = 41,
INVAL = 22,
RANGE = 34,
ILSEQ = 42,
// POSIX Supplement
ADDRINUSE = 100,
ADDRNOTAVAIL = 101,
AFNOSUPPORT = 102,
ALREADY = 103,
BADMSG = 104,
CANCELED = 105,
CONNABORTED = 106,
CONNREFUSED = 107,
CONNRESET = 108,
DESTADDRREQ = 109,
HOSTUNREACH = 110,
IDRM = 111,
INPROGRESS = 112,
ISCONN = 113,
LOOP = 114,
MSGSIZE = 115,
NETDOWN = 116,
NETRESET = 117,
NETUNREACH = 118,
NOBUFS = 119,
NODATA = 120,
NOLINK = 121,
NOMSG = 122,
NOPROTOOPT = 123,
NOSR = 124,
NOSTR = 125,
NOTCONN = 126,
NOTRECOVERABLE = 127,
NOTSOCK = 128,
NOTSUP = 129,
OPNOTSUPP = 130,
OTHER = 131,
OVERFLOW = 132,
OWNERDEAD = 133,
PROTO = 134,
PROTONOSUPPORT = 135,
PROTOTYPE = 136,
TIME = 137,
TIMEDOUT = 138,
TXTBSY = 139,
WOULDBLOCK = 140,
DQUOT = 10069,
_,
};
pub const STRUNCATE = 80;
pub const F_OK = 0;
/// Remove directory instead of unlinking file
pub const AT_REMOVEDIR = 0x200;
pub const in_port_t = u16;
pub const sa_family_t = ws2_32.ADDRESS_FAMILY;
pub const socklen_t = ws2_32.socklen_t;
pub const sockaddr = ws2_32.sockaddr;
pub const sockaddr_in = ws2_32.sockaddr_in;
pub const sockaddr_in6 = ws2_32.sockaddr_in6;
pub const sockaddr_un = ws2_32.sockaddr_un;
pub const in6_addr = [16]u8;
pub const in_addr = u32;
pub const addrinfo = ws2_32.addrinfo;
pub const AF_UNSPEC = ws2_32.AF_UNSPEC;
pub const AF_UNIX = ws2_32.AF_UNIX;
pub const AF_INET = ws2_32.AF_INET;
pub const AF_IMPLINK = ws2_32.AF_IMPLINK;
pub const AF_PUP = ws2_32.AF_PUP;
pub const AF_CHAOS = ws2_32.AF_CHAOS;
pub const AF_NS = ws2_32.AF_NS;
pub const AF_IPX = ws2_32.AF_IPX;
pub const AF_ISO = ws2_32.AF_ISO;
pub const AF_OSI = ws2_32.AF_OSI;
pub const AF_ECMA = ws2_32.AF_ECMA;
pub const AF_DATAKIT = ws2_32.AF_DATAKIT;
pub const AF_CCITT = ws2_32.AF_CCITT;
pub const AF_SNA = ws2_32.AF_SNA;
pub const AF_DECnet = ws2_32.AF_DECnet;
pub const AF_DLI = ws2_32.AF_DLI;
pub const AF_LAT = ws2_32.AF_LAT;
pub const AF_HYLINK = ws2_32.AF_HYLINK;
pub const AF_APPLETALK = ws2_32.AF_APPLETALK;
pub const AF_NETBIOS = ws2_32.AF_NETBIOS;
pub const AF_VOICEVIEW = ws2_32.AF_VOICEVIEW;
pub const AF_FIREFOX = ws2_32.AF_FIREFOX;
pub const AF_UNKNOWN1 = ws2_32.AF_UNKNOWN1;
pub const AF_BAN = ws2_32.AF_BAN;
pub const AF_ATM = ws2_32.AF_ATM;
pub const AF_INET6 = ws2_32.AF_INET6;
pub const AF_CLUSTER = ws2_32.AF_CLUSTER;
pub const AF_12844 = ws2_32.AF_12844;
pub const AF_IRDA = ws2_32.AF_IRDA;
pub const AF_NETDES = ws2_32.AF_NETDES;
pub const AF_TCNPROCESS = ws2_32.AF_TCNPROCESS;
pub const AF_TCNMESSAGE = ws2_32.AF_TCNMESSAGE;
pub const AF_ICLFXBM = ws2_32.AF_ICLFXBM;
pub const AF_BTH = ws2_32.AF_BTH;
pub const AF_MAX = ws2_32.AF_MAX;
pub const SOCK_STREAM = ws2_32.SOCK_STREAM;
pub const SOCK_DGRAM = ws2_32.SOCK_DGRAM;
pub const SOCK_RAW = ws2_32.SOCK_RAW;
pub const SOCK_RDM = ws2_32.SOCK_RDM;
pub const SOCK_SEQPACKET = ws2_32.SOCK_SEQPACKET;
/// WARNING: this flag is not supported by windows socket functions directly,
/// it is only supported by std.os.socket. Be sure that this value does
/// not share any bits with any of the SOCK_* values.
pub const SOCK_CLOEXEC = 0x10000;
/// WARNING: this flag is not supported by windows socket functions directly,
/// it is only supported by std.os.socket. Be sure that this value does
/// not share any bits with any of the SOCK_* values.
pub const SOCK_NONBLOCK = 0x20000;
pub const IPPROTO_ICMP = ws2_32.IPPROTO_ICMP;
pub const IPPROTO_IGMP = ws2_32.IPPROTO_IGMP;
pub const BTHPROTO_RFCOMM = ws2_32.BTHPROTO_RFCOMM;
pub const IPPROTO_TCP = ws2_32.IPPROTO_TCP;
pub const IPPROTO_UDP = ws2_32.IPPROTO_UDP;
pub const IPPROTO_ICMPV6 = ws2_32.IPPROTO_ICMPV6;
pub const IPPROTO_RM = ws2_32.IPPROTO_RM;
pub const nfds_t = c_ulong;
pub const pollfd = ws2_32.pollfd;
pub const POLLRDNORM = ws2_32.POLLRDNORM;
pub const POLLRDBAND = ws2_32.POLLRDBAND;
pub const POLLIN = ws2_32.POLLIN;
pub const POLLPRI = ws2_32.POLLPRI;
pub const POLLWRNORM = ws2_32.POLLWRNORM;
pub const POLLOUT = ws2_32.POLLOUT;
pub const POLLWRBAND = ws2_32.POLLWRBAND;
pub const POLLERR = ws2_32.POLLERR;
pub const POLLHUP = ws2_32.POLLHUP;
pub const POLLNVAL = ws2_32.POLLNVAL;
pub const SOL_SOCKET = ws2_32.SOL_SOCKET;
pub const SO_DEBUG = ws2_32.SO_DEBUG;
pub const SO_ACCEPTCONN = ws2_32.SO_ACCEPTCONN;
pub const SO_REUSEADDR = ws2_32.SO_REUSEADDR;
pub const SO_KEEPALIVE = ws2_32.SO_KEEPALIVE;
pub const SO_DONTROUTE = ws2_32.SO_DONTROUTE;
pub const SO_BROADCAST = ws2_32.SO_BROADCAST;
pub const SO_USELOOPBACK = ws2_32.SO_USELOOPBACK;
pub const SO_LINGER = ws2_32.SO_LINGER;
pub const SO_OOBINLINE = ws2_32.SO_OOBINLINE;
pub const SO_DONTLINGER = ws2_32.SO_DONTLINGER;
pub const SO_EXCLUSIVEADDRUSE = ws2_32.SO_EXCLUSIVEADDRUSE;
pub const SO_SNDBUF = ws2_32.SO_SNDBUF;
pub const SO_RCVBUF = ws2_32.SO_RCVBUF;
pub const SO_SNDLOWAT = ws2_32.SO_SNDLOWAT;
pub const SO_RCVLOWAT = ws2_32.SO_RCVLOWAT;
pub const SO_SNDTIMEO = ws2_32.SO_SNDTIMEO;
pub const SO_RCVTIMEO = ws2_32.SO_RCVTIMEO;
pub const SO_ERROR = ws2_32.SO_ERROR;
pub const SO_TYPE = ws2_32.SO_TYPE;
pub const SO_GROUP_ID = ws2_32.SO_GROUP_ID;
pub const SO_GROUP_PRIORITY = ws2_32.SO_GROUP_PRIORITY;
pub const SO_MAX_MSG_SIZE = ws2_32.SO_MAX_MSG_SIZE;
pub const SO_PROTOCOL_INFOA = ws2_32.SO_PROTOCOL_INFOA;
pub const SO_PROTOCOL_INFOW = ws2_32.SO_PROTOCOL_INFOW;
pub const PVD_CONFIG = ws2_32.PVD_CONFIG;
pub const SO_CONDITIONAL_ACCEPT = ws2_32.SO_CONDITIONAL_ACCEPT;
pub const TCP_NODELAY = ws2_32.TCP_NODELAY;
pub const O_RDONLY = 0o0;
pub const O_WRONLY = 0o1;
pub const O_RDWR = 0o2;
pub const O_CREAT = 0o100;
pub const O_EXCL = 0o200;
pub const O_NOCTTY = 0o400;
pub const O_TRUNC = 0o1000;
pub const O_APPEND = 0o2000;
pub const O_NONBLOCK = 0o4000;
pub const O_DSYNC = 0o10000;
pub const O_SYNC = 0o4010000;
pub const O_RSYNC = 0o4010000;
pub const O_DIRECTORY = 0o200000;
pub const O_NOFOLLOW = 0o400000;
pub const O_CLOEXEC = 0o2000000;
pub const O_ASYNC = 0o20000;
pub const O_DIRECT = 0o40000;
pub const O_LARGEFILE = 0;
pub const O_NOATIME = 0o1000000;
pub const O_PATH = 0o10000000;
pub const O_TMPFILE = 0o20200000;
pub const O_NDELAY = O_NONBLOCK;
pub const IFNAMESIZE = 30;

View File

@ -1,10 +1,10 @@
// This file provides the system interface functions for Linux matching those
// that are provided by libc, whether or not libc is linked. The following
// abstractions are made:
// * Work around kernel bugs and limitations. For example, see sendmmsg.
// * Implement all the syscalls in the same way that libc functions will
// provide `rename` when only the `renameat` syscall exists.
// * Does not support POSIX thread cancellation.
//! This file provides the system interface functions for Linux matching those
//! that are provided by libc, whether or not libc is linked. The following
//! abstractions are made:
//! * Work around kernel bugs and limitations. For example, see sendmmsg.
//! * Implement all the syscalls in the same way that libc functions will
//! provide `rename` when only the `renameat` syscall exists.
//! * Does not support POSIX thread cancellation.
const std = @import("../std.zig");
const assert = std.debug.assert;
const maxInt = std.math.maxInt;
@ -63,8 +63,7 @@ pub const blkcnt_t = arch_bits.blkcnt_t;
pub const blksize_t = arch_bits.blksize_t;
pub const dev_t = arch_bits.dev_t;
pub const ino_t = arch_bits.ino_t;
pub const kernel_stat = arch_bits.kernel_stat;
pub const libc_stat = arch_bits.libc_stat;
pub const Stat = arch_bits.Stat;
pub const mcontext_t = arch_bits.mcontext_t;
pub const mode_t = arch_bits.mode_t;
pub const msghdr = arch_bits.msghdr;
@ -81,7 +80,30 @@ pub const user_desc = arch_bits.user_desc;
pub const tls = @import("linux/tls.zig");
pub const pie = @import("linux/start_pie.zig");
pub const BPF = @import("linux/bpf.zig");
pub usingnamespace @import("linux/io_uring.zig");
const io_uring = @import("linux/io_uring.zig");
pub const IO_Uring = io_uring.IO_Uring;
pub const SubmissionQueue = io_uring.SubmissionQueue;
pub const CompletionQueue = io_uring.CompletionQueue;
pub const io_uring_prep_nop = io_uring.io_uring_prep_nop;
pub const io_uring_prep_fsync = io_uring.io_uring_prep_fsync;
pub const io_uring_prep_rw = io_uring.io_uring_prep_rw;
pub const io_uring_prep_read = io_uring.io_uring_prep_read;
pub const io_uring_prep_write = io_uring.io_uring_prep_write;
pub const io_uring_prep_readv = io_uring.io_uring_prep_readv;
pub const io_uring_prep_writev = io_uring.io_uring_prep_writev;
pub const io_uring_prep_accept = io_uring.io_uring_prep_accept;
pub const io_uring_prep_connect = io_uring.io_uring_prep_connect;
pub const io_uring_prep_epoll_ctl = io_uring.io_uring_prep_epoll_ctl;
pub const io_uring_prep_recv = io_uring.io_uring_prep_recv;
pub const io_uring_prep_send = io_uring.io_uring_prep_send;
pub const io_uring_prep_openat = io_uring.io_uring_prep_openat;
pub const io_uring_prep_close = io_uring.io_uring_prep_close;
pub const io_uring_prep_timeout = io_uring.io_uring_prep_timeout;
pub const io_uring_prep_timeout_remove = io_uring.io_uring_prep_timeout_remove;
pub const io_uring_prep_poll_add = io_uring.io_uring_prep_poll_add;
pub const io_uring_prep_poll_remove = io_uring.io_uring_prep_poll_remove;
pub const io_uring_prep_fallocate = io_uring.io_uring_prep_fallocate;
/// Set by startup code, used by `getauxval`.
pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
@ -1205,7 +1227,7 @@ pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flag
return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
}
pub fn fstat(fd: i32, stat_buf: *kernel_stat) usize {
pub fn fstat(fd: i32, stat_buf: *Stat) usize {
if (@hasField(SYS, "fstat64")) {
return syscall2(.fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
} else {
@ -1213,7 +1235,7 @@ pub fn fstat(fd: i32, stat_buf: *kernel_stat) usize {
}
}
pub fn stat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize {
if (@hasField(SYS, "stat64")) {
return syscall2(.stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
} else {
@ -1221,7 +1243,7 @@ pub fn stat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
}
}
pub fn lstat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
if (@hasField(SYS, "lstat64")) {
return syscall2(.lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
} else {
@ -1229,7 +1251,7 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
}
}
pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *kernel_stat, flags: u32) usize {
pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize {
if (@hasField(SYS, "fstatat64")) {
return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
} else {

View File

@ -82,7 +82,7 @@ test "statx" {
else => unreachable,
}
var stat_buf: linux.kernel_stat = undefined;
var stat_buf: linux.Stat = undefined;
switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {
.SUCCESS => {},
else => unreachable,

View File

@ -112,6 +112,9 @@ pub fn restore_rt() callconv(.Naked) void {
pub const mode_t = usize;
pub const time_t = isize;
pub const nlink_t = usize;
pub const blksize_t = isize;
pub const blkcnt_t = isize;
pub const SYS = enum(usize) {
read = 0,
@ -664,7 +667,7 @@ pub const ino_t = u64;
pub const dev_t = u64;
// The `stat` definition used by the Linux kernel.
pub const kernel_stat = extern struct {
pub const Stat = extern struct {
dev: dev_t,
ino: ino_t,
nlink: usize,
@ -696,9 +699,6 @@ pub const kernel_stat = extern struct {
}
};
// The `stat64` definition used by the libc.
pub const libc_stat = kernel_stat;
pub const timespec = extern struct {
tv_sec: isize,
tv_nsec: isize,

View File

@ -15,8 +15,8 @@ comptime {
// assert(@alignOf(u64) == 8);
}
pub const iovec_t = iovec;
pub const ciovec_t = iovec_const;
pub const iovec_t = std.os.iovec;
pub const ciovec_t = std.os.iovec_const;
pub extern "wasi_snapshot_preview1" fn args_get(argv: [*][*:0]u8, argv_buf: [*]u8) errno_t;
pub extern "wasi_snapshot_preview1" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t;
@ -79,3 +79,469 @@ pub extern "wasi_snapshot_preview1" fn sock_shutdown(sock: fd_t, how: sdflags_t)
pub fn getErrno(r: errno_t) errno_t {
return r;
}
pub const STDIN_FILENO = 0;
pub const STDOUT_FILENO = 1;
pub const STDERR_FILENO = 2;
pub const mode_t = u32;
pub const time_t = i64; // match https://github.com/CraneStation/wasi-libc
pub const timespec = struct {
tv_sec: time_t,
tv_nsec: isize,
pub fn fromTimestamp(tm: timestamp_t) timespec {
const tv_sec: timestamp_t = tm / 1_000_000_000;
const tv_nsec = tm - tv_sec * 1_000_000_000;
return timespec{
.tv_sec = @intCast(time_t, tv_sec),
.tv_nsec = @intCast(isize, tv_nsec),
};
}
pub fn toTimestamp(ts: timespec) timestamp_t {
const tm = @intCast(timestamp_t, ts.tv_sec * 1_000_000_000) + @intCast(timestamp_t, ts.tv_nsec);
return tm;
}
};
pub const Stat = struct {
dev: device_t,
ino: inode_t,
mode: mode_t,
filetype: filetype_t,
nlink: linkcount_t,
size: filesize_t,
atim: timespec,
mtim: timespec,
ctim: timespec,
const Self = @This();
pub fn fromFilestat(stat: filestat_t) Self {
return Self{
.dev = stat.dev,
.ino = stat.ino,
.mode = 0,
.filetype = stat.filetype,
.nlink = stat.nlink,
.size = stat.size,
.atim = stat.atime(),
.mtim = stat.mtime(),
.ctim = stat.ctime(),
};
}
pub fn atime(self: Self) timespec {
return self.atim;
}
pub fn mtime(self: Self) timespec {
return self.mtim;
}
pub fn ctime(self: Self) timespec {
return self.ctim;
}
};
pub const IOV_MAX = 1024;
pub const AT_REMOVEDIR: u32 = 0x4;
pub const AT_FDCWD: fd_t = -2;
// As defined in the wasi_snapshot_preview1 spec file:
// https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/witx/typenames.witx
pub const advice_t = u8;
pub const ADVICE_NORMAL: advice_t = 0;
pub const ADVICE_SEQUENTIAL: advice_t = 1;
pub const ADVICE_RANDOM: advice_t = 2;
pub const ADVICE_WILLNEED: advice_t = 3;
pub const ADVICE_DONTNEED: advice_t = 4;
pub const ADVICE_NOREUSE: advice_t = 5;
pub const clockid_t = u32;
pub const CLOCK = struct {
pub const REALTIME: clockid_t = 0;
pub const MONOTONIC: clockid_t = 1;
pub const PROCESS_CPUTIME_ID: clockid_t = 2;
pub const THREAD_CPUTIME_ID: clockid_t = 3;
};
pub const device_t = u64;
pub const dircookie_t = u64;
pub const DIRCOOKIE_START: dircookie_t = 0;
pub const dirnamlen_t = u32;
pub const dirent_t = extern struct {
d_next: dircookie_t,
d_ino: inode_t,
d_namlen: dirnamlen_t,
d_type: filetype_t,
};
pub const errno_t = enum(u16) {
SUCCESS = 0,
@"2BIG" = 1,
ACCES = 2,
ADDRINUSE = 3,
ADDRNOTAVAIL = 4,
AFNOSUPPORT = 5,
/// This is also the error code used for `WOULDBLOCK`.
AGAIN = 6,
ALREADY = 7,
BADF = 8,
BADMSG = 9,
BUSY = 10,
CANCELED = 11,
CHILD = 12,
CONNABORTED = 13,
CONNREFUSED = 14,
CONNRESET = 15,
DEADLK = 16,
DESTADDRREQ = 17,
DOM = 18,
DQUOT = 19,
EXIST = 20,
FAULT = 21,
FBIG = 22,
HOSTUNREACH = 23,
IDRM = 24,
ILSEQ = 25,
INPROGRESS = 26,
INTR = 27,
INVAL = 28,
IO = 29,
ISCONN = 30,
ISDIR = 31,
LOOP = 32,
MFILE = 33,
MLINK = 34,
MSGSIZE = 35,
MULTIHOP = 36,
NAMETOOLONG = 37,
NETDOWN = 38,
NETRESET = 39,
NETUNREACH = 40,
NFILE = 41,
NOBUFS = 42,
NODEV = 43,
NOENT = 44,
NOEXEC = 45,
NOLCK = 46,
NOLINK = 47,
NOMEM = 48,
NOMSG = 49,
NOPROTOOPT = 50,
NOSPC = 51,
NOSYS = 52,
NOTCONN = 53,
NOTDIR = 54,
NOTEMPTY = 55,
NOTRECOVERABLE = 56,
NOTSOCK = 57,
/// This is also the code used for `NOTSUP`.
OPNOTSUPP = 58,
NOTTY = 59,
NXIO = 60,
OVERFLOW = 61,
OWNERDEAD = 62,
PERM = 63,
PIPE = 64,
PROTO = 65,
PROTONOSUPPORT = 66,
PROTOTYPE = 67,
RANGE = 68,
ROFS = 69,
SPIPE = 70,
SRCH = 71,
STALE = 72,
TIMEDOUT = 73,
TXTBSY = 74,
XDEV = 75,
NOTCAPABLE = 76,
_,
};
pub const E = errno_t;
pub const event_t = extern struct {
userdata: userdata_t,
@"error": errno_t,
@"type": eventtype_t,
fd_readwrite: eventfdreadwrite_t,
};
pub const eventfdreadwrite_t = extern struct {
nbytes: filesize_t,
flags: eventrwflags_t,
};
pub const eventrwflags_t = u16;
pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001;
pub const eventtype_t = u8;
pub const EVENTTYPE_CLOCK: eventtype_t = 0;
pub const EVENTTYPE_FD_READ: eventtype_t = 1;
pub const EVENTTYPE_FD_WRITE: eventtype_t = 2;
pub const exitcode_t = u32;
pub const fd_t = u32;
pub const fdflags_t = u16;
pub const FDFLAG_APPEND: fdflags_t = 0x0001;
pub const FDFLAG_DSYNC: fdflags_t = 0x0002;
pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004;
pub const FDFLAG_RSYNC: fdflags_t = 0x0008;
pub const FDFLAG_SYNC: fdflags_t = 0x0010;
pub const fdstat_t = extern struct {
fs_filetype: filetype_t,
fs_flags: fdflags_t,
fs_rights_base: rights_t,
fs_rights_inheriting: rights_t,
};
pub const filedelta_t = i64;
pub const filesize_t = u64;
pub const filestat_t = extern struct {
dev: device_t,
ino: inode_t,
filetype: filetype_t,
nlink: linkcount_t,
size: filesize_t,
atim: timestamp_t,
mtim: timestamp_t,
ctim: timestamp_t,
pub fn atime(self: filestat_t) timespec {
return timespec.fromTimestamp(self.atim);
}
pub fn mtime(self: filestat_t) timespec {
return timespec.fromTimestamp(self.mtim);
}
pub fn ctime(self: filestat_t) timespec {
return timespec.fromTimestamp(self.ctim);
}
};
pub const filetype_t = u8;
pub const FILETYPE_UNKNOWN: filetype_t = 0;
pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1;
pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2;
pub const FILETYPE_DIRECTORY: filetype_t = 3;
pub const FILETYPE_REGULAR_FILE: filetype_t = 4;
pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5;
pub const FILETYPE_SOCKET_STREAM: filetype_t = 6;
pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7;
pub const fstflags_t = u16;
pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001;
pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002;
pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004;
pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
pub const inode_t = u64;
pub const ino_t = inode_t;
pub const linkcount_t = u64;
pub const lookupflags_t = u32;
pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001;
pub const oflags_t = u16;
pub const O = struct {
pub const CREAT: oflags_t = 0x0001;
pub const DIRECTORY: oflags_t = 0x0002;
pub const EXCL: oflags_t = 0x0004;
pub const TRUNC: oflags_t = 0x0008;
};
pub const preopentype_t = u8;
pub const PREOPENTYPE_DIR: preopentype_t = 0;
pub const prestat_t = extern struct {
pr_type: preopentype_t,
u: prestat_u_t,
};
pub const prestat_dir_t = extern struct {
pr_name_len: usize,
};
pub const prestat_u_t = extern union {
dir: prestat_dir_t,
};
pub const riflags_t = u16;
pub const SOCK_RECV_PEEK: riflags_t = 0x0001;
pub const SOCK_RECV_WAITALL: riflags_t = 0x0002;
pub const rights_t = u64;
pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001;
pub const RIGHT_FD_READ: rights_t = 0x0000000000000002;
pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004;
pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008;
pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010;
pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020;
pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040;
pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080;
pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100;
pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200;
pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400;
pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800;
pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000;
pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000;
pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000;
pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000;
pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000;
pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000;
pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000;
pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000;
pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000;
pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000;
pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000;
pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000;
pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000;
pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000;
pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000;
pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000;
pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000;
pub const RIGHT_ALL: rights_t = RIGHT_FD_DATASYNC |
RIGHT_FD_READ |
RIGHT_FD_SEEK |
RIGHT_FD_FDSTAT_SET_FLAGS |
RIGHT_FD_SYNC |
RIGHT_FD_TELL |
RIGHT_FD_WRITE |
RIGHT_FD_ADVISE |
RIGHT_FD_ALLOCATE |
RIGHT_PATH_CREATE_DIRECTORY |
RIGHT_PATH_CREATE_FILE |
RIGHT_PATH_LINK_SOURCE |
RIGHT_PATH_LINK_TARGET |
RIGHT_PATH_OPEN |
RIGHT_FD_READDIR |
RIGHT_PATH_READLINK |
RIGHT_PATH_RENAME_SOURCE |
RIGHT_PATH_RENAME_TARGET |
RIGHT_PATH_FILESTAT_GET |
RIGHT_PATH_FILESTAT_SET_SIZE |
RIGHT_PATH_FILESTAT_SET_TIMES |
RIGHT_FD_FILESTAT_GET |
RIGHT_FD_FILESTAT_SET_SIZE |
RIGHT_FD_FILESTAT_SET_TIMES |
RIGHT_PATH_SYMLINK |
RIGHT_PATH_REMOVE_DIRECTORY |
RIGHT_PATH_UNLINK_FILE |
RIGHT_POLL_FD_READWRITE |
RIGHT_SOCK_SHUTDOWN;
pub const roflags_t = u16;
pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001;
pub const sdflags_t = u8;
pub const SHUT_RD: sdflags_t = 0x01;
pub const SHUT_WR: sdflags_t = 0x02;
pub const siflags_t = u16;
pub const signal_t = u8;
pub const SIGNONE: signal_t = 0;
pub const SIGHUP: signal_t = 1;
pub const SIGINT: signal_t = 2;
pub const SIGQUIT: signal_t = 3;
pub const SIGILL: signal_t = 4;
pub const SIGTRAP: signal_t = 5;
pub const SIGABRT: signal_t = 6;
pub const SIGBUS: signal_t = 7;
pub const SIGFPE: signal_t = 8;
pub const SIGKILL: signal_t = 9;
pub const SIGUSR1: signal_t = 10;
pub const SIGSEGV: signal_t = 11;
pub const SIGUSR2: signal_t = 12;
pub const SIGPIPE: signal_t = 13;
pub const SIGALRM: signal_t = 14;
pub const SIGTERM: signal_t = 15;
pub const SIGCHLD: signal_t = 16;
pub const SIGCONT: signal_t = 17;
pub const SIGSTOP: signal_t = 18;
pub const SIGTSTP: signal_t = 19;
pub const SIGTTIN: signal_t = 20;
pub const SIGTTOU: signal_t = 21;
pub const SIGURG: signal_t = 22;
pub const SIGXCPU: signal_t = 23;
pub const SIGXFSZ: signal_t = 24;
pub const SIGVTALRM: signal_t = 25;
pub const SIGPROF: signal_t = 26;
pub const SIGWINCH: signal_t = 27;
pub const SIGPOLL: signal_t = 28;
pub const SIGPWR: signal_t = 29;
pub const SIGSYS: signal_t = 30;
pub const subclockflags_t = u16;
pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001;
pub const subscription_t = extern struct {
userdata: userdata_t,
u: subscription_u_t,
};
pub const subscription_clock_t = extern struct {
id: clockid_t,
timeout: timestamp_t,
precision: timestamp_t,
flags: subclockflags_t,
};
pub const subscription_fd_readwrite_t = extern struct {
fd: fd_t,
};
pub const subscription_u_t = extern struct {
tag: eventtype_t,
u: subscription_u_u_t,
};
pub const subscription_u_u_t = extern union {
clock: subscription_clock_t,
fd_read: subscription_fd_readwrite_t,
fd_write: subscription_fd_readwrite_t,
};
pub const timestamp_t = u64;
pub const userdata_t = u64;
pub const whence_t = u8;
pub const WHENCE_SET: whence_t = 0;
pub const WHENCE_CUR: whence_t = 1;
pub const WHENCE_END: whence_t = 2;
pub const S_IEXEC = S_IXUSR;
pub const S_IFBLK = 0x6000;
pub const S_IFCHR = 0x2000;
pub const S_IFDIR = 0x4000;
pub const S_IFIFO = 0xc000;
pub const S_IFLNK = 0xa000;
pub const S_IFMT = S_IFBLK | S_IFCHR | S_IFDIR | S_IFIFO | S_IFLNK | S_IFREG | S_IFSOCK;
pub const S_IFREG = 0x8000;
// There's no concept of UNIX domain socket but we define this value here in order to line with other OSes.
pub const S_IFSOCK = 0x1;
pub const SEEK_SET = WHENCE_SET;
pub const SEEK_CUR = WHENCE_CUR;
pub const SEEK_END = WHENCE_END;
pub const LOCK_SH = 0x1;
pub const LOCK_EX = 0x2;
pub const LOCK_NB = 0x4;
pub const LOCK_UN = 0x8;

View File

@ -1,5 +1,4 @@
const std = @import("../../std.zig");
usingnamespace @import("bits.zig");
pub const SOCKET = *opaque {};
pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0));