From cca57042df374305390b5b0000be75ba6d24fb63 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 30 Aug 2021 22:02:34 -0700 Subject: [PATCH] std: fix regressions from this branch Also move some usingnamespace test cases from compare_output to behavior. --- lib/std/c.zig | 36 +- lib/std/c/darwin.zig | 482 ++++++++---------- lib/std/c/dragonfly.zig | 221 ++++---- lib/std/c/freebsd.zig | 236 ++++----- lib/std/c/haiku.zig | 268 +++++----- lib/std/c/linux.zig | 6 +- lib/std/c/netbsd.zig | 397 +++++++-------- lib/std/c/openbsd.zig | 452 ++++++++-------- lib/std/c/wasi.zig | 5 + lib/std/debug.zig | 2 +- lib/std/event/loop.zig | 2 +- lib/std/fs.zig | 50 +- lib/std/fs/file.zig | 16 +- lib/std/fs/watch.zig | 2 +- lib/std/os.zig | 17 +- lib/std/os/linux.zig | 82 +-- lib/std/os/linux/arm-eabi.zig | 97 ++-- lib/std/os/linux/arm64.zig | 49 +- lib/std/os/linux/i386.zig | 34 -- lib/std/os/linux/io_uring.zig | 14 +- lib/std/os/linux/mips.zig | 48 +- lib/std/os/linux/powerpc.zig | 49 +- lib/std/os/linux/powerpc64.zig | 48 +- lib/std/os/linux/riscv64.zig | 43 +- lib/std/os/linux/sparc64.zig | 49 +- lib/std/os/linux/x86_64.zig | 32 -- lib/std/os/test.zig | 4 +- lib/std/os/wasi.zig | 2 + lib/std/os/windows.zig | 2 +- lib/std/special/ssp.zig | 4 +- lib/std/start.zig | 2 +- lib/std/x/net/tcp.zig | 6 +- lib/std/x/os/net.zig | 5 +- test/behavior/usingnamespace/a.zig | 7 + test/behavior/usingnamespace/b.zig | 3 + test/behavior/usingnamespace/bar.zig | 8 + test/behavior/usingnamespace/foo.zig | 14 + .../usingnamespace/import_segregation.zig | 11 + test/behavior/usingnamespace/other.zig | 4 + test/behavior/usingnamespace_stage1.zig | 19 + test/cases.zig | 28 +- test/cli.zig | 7 - test/compare_output.zig | 105 ---- test/standalone/brace_expansion/main.zig | 2 +- 44 files changed, 1417 insertions(+), 1553 deletions(-) create mode 100644 test/behavior/usingnamespace/a.zig create mode 100644 test/behavior/usingnamespace/b.zig create mode 100644 test/behavior/usingnamespace/bar.zig create mode 100644 test/behavior/usingnamespace/foo.zig create mode 100644 test/behavior/usingnamespace/import_segregation.zig create mode 100644 test/behavior/usingnamespace/other.zig diff --git a/lib/std/c.zig b/lib/std/c.zig index 9770af5f5f25a8b84280ca27757705a537fba0c6..5e88b1a7d30a8c43c75c0b3397d14dccef8a934a 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -58,41 +58,7 @@ pub usingnamespace switch (builtin.os.tag) { }; pub usingnamespace switch (builtin.os.tag) { - .netbsd => struct {}, - .macos, .ios, .watchos, .tvos => struct { - // XXX: close -> close$NOCANCEL - // XXX: getdirentries -> _getdirentries64 - pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int; - pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int; - pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int; - pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int; - pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int; - pub extern "c" fn sched_yield() c_int; - pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int; - pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int; - pub extern "c" fn 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: *c.Stat) c_int; - pub extern "c" fn sigfillset(set: ?*c.sigset_t) void; - pub extern "c" fn alarm(seconds: c_uint) c_uint; - pub extern "c" fn sigwait(set: ?*c.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: *c.timespec) c_int; - pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int; - pub extern "c" fn fstat(fd: c.fd_t, buf: *c.Stat) c_int; - pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int; - pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int; - pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int; - pub extern "c" fn sched_yield() c_int; - pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int; - pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int; - pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int; - pub extern "c" fn sigfillset(set: ?*c.sigset_t) void; - pub extern "c" fn alarm(seconds: c_uint) c_uint; - pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int; - }, + .netbsd, .macos, .ios, .watchos, .tvos, .windows => struct {}, else => struct { pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int; pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int; diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 75e0d32f49c2c48657de506b55d7123f524f7613..a658138a96aac1c9ce1bb507d7fe6dcec68f5f43 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -395,10 +395,85 @@ pub const timespec = extern struct { pub const sigset_t = u32; pub const empty_sigset: sigset_t = 0; -pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); -pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); -pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); -pub const SIG_HOLD = @intToPtr(?Sigaction.sigaction_fn, 5); +pub const SIG = struct { + pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); + pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); + pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); + pub const HOLD = @intToPtr(?Sigaction.sigaction_fn, 5); + + /// block specified signal set + pub const _BLOCK = 1; + /// unblock specified signal set + pub const _UNBLOCK = 2; + /// set specified signal set + pub const _SETMASK = 3; + /// hangup + pub const HUP = 1; + /// interrupt + pub const INT = 2; + /// quit + pub const QUIT = 3; + /// illegal instruction (not reset when caught) + pub const ILL = 4; + /// trace trap (not reset when caught) + pub const TRAP = 5; + /// abort() + pub const ABRT = 6; + /// pollable event ([XSR] generated, not supported) + pub const POLL = 7; + /// compatibility + pub const IOT = ABRT; + /// EMT instruction + pub const EMT = 7; + /// floating point exception + pub const FPE = 8; + /// kill (cannot be caught or ignored) + pub const KILL = 9; + /// bus error + pub const BUS = 10; + /// segmentation violation + pub const SEGV = 11; + /// bad argument to system call + pub const SYS = 12; + /// write on a pipe with no one to read it + pub const PIPE = 13; + /// alarm clock + pub const ALRM = 14; + /// software termination signal from kill + pub const TERM = 15; + /// urgent condition on IO channel + pub const URG = 16; + /// sendable stop signal not from tty + pub const STOP = 17; + /// stop signal from tty + pub const TSTP = 18; + /// continue a stopped process + pub const CONT = 19; + /// to parent on child stop or exit + pub const CHLD = 20; + /// to readers pgrp upon background tty read + pub const TTIN = 21; + /// like TTIN for output if (tp->t_local<OSTOP) + pub const TTOU = 22; + /// input/output possible signal + pub const IO = 23; + /// exceeded CPU time limit + pub const XCPU = 24; + /// exceeded file size limit + pub const XFSZ = 25; + /// virtual time alarm + pub const VTALRM = 26; + /// profiling time alarm + pub const PROF = 27; + /// window size changes + pub const WINCH = 28; + /// information request + pub const INFO = 29; + /// user defined signal 1 + pub const USR1 = 30; + /// user defined signal 2 + pub const USR2 = 31; +}; pub const siginfo_t = extern struct { signo: c_int, @@ -507,17 +582,16 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -/// [MC2] no permissions -pub const PROT_NONE = 0x00; - -/// [MC2] pages can be read -pub const PROT_READ = 0x01; - -/// [MC2] pages can be written -pub const PROT_WRITE = 0x02; - -/// [MC2] pages can be executed -pub const PROT_EXEC = 0x04; +pub const PROT = struct { + /// [MC2] no permissions + pub const NONE = 0x00; + /// [MC2] pages can be read + pub const READ = 0x01; + /// [MC2] pages can be written + pub const WRITE = 0x02; + /// [MC2] pages can be executed + pub const EXEC = 0x04; +}; pub const MAP = struct { /// allocated from memory, swap space @@ -551,10 +625,10 @@ pub const SA_ONSTACK = 0x0001; /// restart system on signal return pub const SA_RESTART = 0x0002; -/// reset to SIG_DFL when taking signal +/// reset to SIG.DFL when taking signal pub const SA_RESETHAND = 0x0004; -/// do not generate SIGCHLD on child stop +/// do not generate SIG.CHLD on child stop pub const SA_NOCLDSTOP = 0x0008; /// don't mask the signal we're delivering @@ -572,66 +646,53 @@ pub const SA_USERTRAMP = 0x0100; /// signal handler with SA_SIGINFO args with 64bit regs information pub const SA_64REGSET = 0x0200; -pub const O_PATH = 0x0000; - pub const F_OK = 0; pub const X_OK = 1; pub const W_OK = 2; pub const R_OK = 4; -/// open for reading only -pub const O_RDONLY = 0x0000; - -/// open for writing only -pub const O_WRONLY = 0x0001; - -/// open for reading and writing -pub const O_RDWR = 0x0002; - -/// do not block on open or for data to become available -pub const O_NONBLOCK = 0x0004; - -/// append on each write -pub const O_APPEND = 0x0008; - -/// create file if it does not exist -pub const O_CREAT = 0x0200; - -/// truncate size to 0 -pub const O_TRUNC = 0x0400; - -/// error if O_CREAT and the file exists -pub const O_EXCL = 0x0800; - -/// atomically obtain a shared lock -pub const O_SHLOCK = 0x0010; - -/// atomically obtain an exclusive lock -pub const O_EXLOCK = 0x0020; - -/// do not follow symlinks -pub const O_NOFOLLOW = 0x0100; - -/// allow open of symlinks -pub const O_SYMLINK = 0x200000; - -/// descriptor requested for event notifications only -pub const O_EVTONLY = 0x8000; - -/// mark as close-on-exec -pub const O_CLOEXEC = 0x1000000; - -pub const O_ACCMODE = 3; -pub const O_ALERT = 536870912; -pub const O_ASYNC = 64; -pub const O_DIRECTORY = 1048576; -pub const O_DP_GETRAWENCRYPTED = 1; -pub const O_DP_GETRAWUNENCRYPTED = 2; -pub const O_DSYNC = 4194304; -pub const O_FSYNC = O_SYNC; -pub const O_NOCTTY = 131072; -pub const O_POPUP = 2147483648; -pub const O_SYNC = 128; +pub const O = struct { + pub const PATH = 0x0000; + /// open for reading only + pub const RDONLY = 0x0000; + /// open for writing only + pub const WRONLY = 0x0001; + /// open for reading and writing + pub const RDWR = 0x0002; + /// do not block on open or for data to become available + pub const NONBLOCK = 0x0004; + /// append on each write + pub const APPEND = 0x0008; + /// create file if it does not exist + pub const CREAT = 0x0200; + /// truncate size to 0 + pub const TRUNC = 0x0400; + /// error if CREAT and the file exists + pub const EXCL = 0x0800; + /// atomically obtain a shared lock + pub const SHLOCK = 0x0010; + /// atomically obtain an exclusive lock + pub const EXLOCK = 0x0020; + /// do not follow symlinks + pub const NOFOLLOW = 0x0100; + /// allow open of symlinks + pub const SYMLINK = 0x200000; + /// descriptor requested for event notifications only + pub const EVTONLY = 0x8000; + /// mark as close-on-exec + pub const CLOEXEC = 0x1000000; + pub const ACCMODE = 3; + pub const ALERT = 536870912; + pub const ASYNC = 64; + pub const DIRECTORY = 1048576; + pub const DP_GETRAWENCRYPTED = 1; + pub const DP_GETRAWUNENCRYPTED = 2; + pub const DSYNC = 4194304; + pub const FSYNC = SYNC; + pub const NOCTTY = 131072; + pub const POPUP = 2147483648; + pub const SYNC = 128; +}; pub const SEEK_SET = 0x0; pub const SEEK_CUR = 0x1; @@ -647,114 +708,6 @@ pub const DT_LNK = 10; pub const DT_SOCK = 12; pub const DT_WHT = 14; -/// block specified signal set -pub const SIG_BLOCK = 1; - -/// unblock specified signal set -pub const SIG_UNBLOCK = 2; - -/// set specified signal set -pub const SIG_SETMASK = 3; - -/// hangup -pub const SIGHUP = 1; - -/// interrupt -pub const SIGINT = 2; - -/// quit -pub const SIGQUIT = 3; - -/// illegal instruction (not reset when caught) -pub const SIGILL = 4; - -/// trace trap (not reset when caught) -pub const SIGTRAP = 5; - -/// abort() -pub const SIGABRT = 6; - -/// pollable event ([XSR] generated, not supported) -pub const SIGPOLL = 7; - -/// compatibility -pub const SIGIOT = SIGABRT; - -/// EMT instruction -pub const SIGEMT = 7; - -/// floating point exception -pub const SIGFPE = 8; - -/// kill (cannot be caught or ignored) -pub const SIGKILL = 9; - -/// bus error -pub const SIGBUS = 10; - -/// segmentation violation -pub const SIGSEGV = 11; - -/// bad argument to system call -pub const SIGSYS = 12; - -/// write on a pipe with no one to read it -pub const SIGPIPE = 13; - -/// alarm clock -pub const SIGALRM = 14; - -/// software termination signal from kill -pub const SIGTERM = 15; - -/// urgent condition on IO channel -pub const SIGURG = 16; - -/// sendable stop signal not from tty -pub const SIGSTOP = 17; - -/// stop signal from tty -pub const SIGTSTP = 18; - -/// continue a stopped process -pub const SIGCONT = 19; - -/// to parent on child stop or exit -pub const SIGCHLD = 20; - -/// to readers pgrp upon background tty read -pub const SIGTTIN = 21; - -/// like TTIN for output if (tp->t_local<OSTOP) -pub const SIGTTOU = 22; - -/// input/output possible signal -pub const SIGIO = 23; - -/// exceeded CPU time limit -pub const SIGXCPU = 24; - -/// exceeded file size limit -pub const SIGXFSZ = 25; - -/// virtual time alarm -pub const SIGVTALRM = 26; - -/// profiling time alarm -pub const SIGPROF = 27; - -/// window size changes -pub const SIGWINCH = 28; - -/// information request -pub const SIGINFO = 29; - -/// user defined signal 1 -pub const SIGUSR1 = 30; - -/// user defined signal 2 -pub const SIGUSR2 = 31; - /// no flag value pub const KEVENT_FLAG_NONE = 0x000; @@ -1116,28 +1069,31 @@ pub const SO = struct { pub const REUSESHAREUID = 0x1025; }; -fn wstatus(x: u32) u32 { - return x & 0o177; -} -const wstopped = 0o177; -pub fn WEXITSTATUS(x: u32) u8 { - return @intCast(u8, x >> 8); -} -pub fn WTERMSIG(x: u32) u32 { - return wstatus(x); -} -pub fn WSTOPSIG(x: u32) u32 { - return x >> 8; -} -pub fn WIFEXITED(x: u32) bool { - return wstatus(x) == 0; -} -pub fn WIFSTOPPED(x: u32) bool { - return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; -} -pub fn WIFSIGNALED(x: u32) bool { - return wstatus(x) != wstopped and wstatus(x) != 0; -} +pub const W = struct { + pub fn EXITSTATUS(x: u32) u8 { + return @intCast(u8, x >> 8); + } + pub fn TERMSIG(x: u32) u32 { + return status(x); + } + pub fn STOPSIG(x: u32) u32 { + return x >> 8; + } + pub fn IFEXITED(x: u32) bool { + return status(x) == 0; + } + pub fn IFSTOPPED(x: u32) bool { + return status(x) == stopped and STOPSIG(x) != 0x13; + } + pub fn IFSIGNALED(x: u32) bool { + return status(x) != stopped and status(x) != 0; + } + + fn status(x: u32) u32 { + return x & 0o177; + } + const stopped = 0o177; +}; pub const E = enum(u16) { /// No error occurred. @@ -1488,64 +1444,66 @@ pub const stack_t = extern struct { ss_flags: i32, }; -pub const S_IFMT = 0o170000; - -pub const S_IFIFO = 0o010000; -pub const S_IFCHR = 0o020000; -pub const S_IFDIR = 0o040000; -pub const S_IFBLK = 0o060000; -pub const S_IFREG = 0o100000; -pub const S_IFLNK = 0o120000; -pub const S_IFSOCK = 0o140000; -pub const S_IFWHT = 0o160000; - -pub const S_ISUID = 0o4000; -pub const S_ISGID = 0o2000; -pub const S_ISVTX = 0o1000; -pub const S_IRWXU = 0o700; -pub const S_IRUSR = 0o400; -pub const S_IWUSR = 0o200; -pub const S_IXUSR = 0o100; -pub const S_IRWXG = 0o070; -pub const S_IRGRP = 0o040; -pub const S_IWGRP = 0o020; -pub const S_IXGRP = 0o010; -pub const S_IRWXO = 0o007; -pub const S_IROTH = 0o004; -pub const S_IWOTH = 0o002; -pub const S_IXOTH = 0o001; - -pub fn S_ISFIFO(m: u32) bool { - return m & S_IFMT == S_IFIFO; -} - -pub fn S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} - -pub fn S_ISDIR(m: u32) bool { - return m & S_IFMT == S_IFDIR; -} - -pub fn S_ISBLK(m: u32) bool { - return m & S_IFMT == S_IFBLK; -} - -pub fn S_ISREG(m: u32) bool { - return m & S_IFMT == S_IFREG; -} - -pub fn S_ISLNK(m: u32) bool { - return m & S_IFMT == S_IFLNK; -} - -pub fn S_ISSOCK(m: u32) bool { - return m & S_IFMT == S_IFSOCK; -} - -pub fn S_IWHT(m: u32) bool { - return m & S_IFMT == S_IFWHT; -} +pub const S = struct { + pub const IFMT = 0o170000; + + pub const IFIFO = 0o010000; + pub const IFCHR = 0o020000; + pub const IFDIR = 0o040000; + pub const IFBLK = 0o060000; + pub const IFREG = 0o100000; + pub const IFLNK = 0o120000; + pub const IFSOCK = 0o140000; + pub const IFWHT = 0o160000; + + pub const ISUID = 0o4000; + pub const ISGID = 0o2000; + pub const ISVTX = 0o1000; + pub const IRWXU = 0o700; + pub const IRUSR = 0o400; + pub const IWUSR = 0o200; + pub const IXUSR = 0o100; + pub const IRWXG = 0o070; + pub const IRGRP = 0o040; + pub const IWGRP = 0o020; + pub const IXGRP = 0o010; + pub const IRWXO = 0o007; + pub const IROTH = 0o004; + pub const IWOTH = 0o002; + pub const IXOTH = 0o001; + + pub fn ISFIFO(m: u32) bool { + return m & IFMT == IFIFO; + } + + pub fn ISCHR(m: u32) bool { + return m & IFMT == IFCHR; + } + + pub fn ISDIR(m: u32) bool { + return m & IFMT == IFDIR; + } + + pub fn ISBLK(m: u32) bool { + return m & IFMT == IFBLK; + } + + pub fn ISREG(m: u32) bool { + return m & IFMT == IFREG; + } + + pub fn ISLNK(m: u32) bool { + return m & IFMT == IFLNK; + } + + pub fn ISSOCK(m: u32) bool { + return m & IFMT == IFSOCK; + } + + pub fn IWHT(m: u32) bool { + return m & IFMT == IFWHT; + } +}; pub const HOST_NAME_MAX = 72; @@ -1981,7 +1939,9 @@ pub const winsize = extern struct { ws_ypixel: u16, }; -pub const TIOCGWINSZ = ior(0x40000000, 't', 104, @sizeOf(winsize)); +pub const T = struct { + pub const IOCGWINSZ = ior(0x40000000, 't', 104, @sizeOf(winsize)); +}; pub const IOCPARM_MASK = 0x1fff; fn ior(inout: u32, group: usize, num: usize, len: usize) usize { diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig index 427a08262da4c77872e75c791d72c89ba3fb6b03..921116b4f6c2355c883509a8cabee9a5dfc84f62 100644 --- a/lib/std/c/dragonfly.zig +++ b/lib/std/c/dragonfly.zig @@ -33,10 +33,6 @@ pub const pthread_attr_t = extern struct { // copied from freebsd pub const sem_t = ?*opaque {}; -pub fn S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} - // See: // - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/include/unistd.h // - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/sys/sys/types.h @@ -157,10 +153,12 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -pub const PROT_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; +pub const PROT = struct { + pub const NONE = 0; + pub const READ = 1; + pub const WRITE = 2; + pub const EXEC = 4; +}; pub const MAP = struct { pub const FILE = 0; @@ -321,32 +319,34 @@ pub const X_OK = 1; // test for execute or search permission pub const W_OK = 2; // test for write permission pub const R_OK = 4; // test for read permission -pub const O_RDONLY = 0; -pub const O_NDELAY = O_NONBLOCK; -pub const O_WRONLY = 1; -pub const O_RDWR = 2; -pub const O_ACCMODE = 3; -pub const O_NONBLOCK = 4; -pub const O_APPEND = 8; -pub const O_SHLOCK = 16; -pub const O_EXLOCK = 32; -pub const O_ASYNC = 64; -pub const O_FSYNC = 128; -pub const O_SYNC = 128; -pub const O_NOFOLLOW = 256; -pub const O_CREAT = 512; -pub const O_TRUNC = 1024; -pub const O_EXCL = 2048; -pub const O_NOCTTY = 32768; -pub const O_DIRECT = 65536; -pub const O_CLOEXEC = 131072; -pub const O_FBLOCKING = 262144; -pub const O_FNONBLOCKING = 524288; -pub const O_FAPPEND = 1048576; -pub const O_FOFFSET = 2097152; -pub const O_FSYNCWRITE = 4194304; -pub const O_FASYNCWRITE = 8388608; -pub const O_DIRECTORY = 134217728; +pub const O = struct { + pub const RDONLY = 0; + pub const NDELAY = NONBLOCK; + pub const WRONLY = 1; + pub const RDWR = 2; + pub const ACCMODE = 3; + pub const NONBLOCK = 4; + pub const APPEND = 8; + pub const SHLOCK = 16; + pub const EXLOCK = 32; + pub const ASYNC = 64; + pub const FSYNC = 128; + pub const SYNC = 128; + pub const NOFOLLOW = 256; + pub const CREAT = 512; + pub const TRUNC = 1024; + pub const EXCL = 2048; + pub const NOCTTY = 32768; + pub const DIRECT = 65536; + pub const CLOEXEC = 131072; + pub const FBLOCKING = 262144; + pub const FNONBLOCKING = 524288; + pub const FAPPEND = 1048576; + pub const FOFFSET = 2097152; + pub const FSYNCWRITE = 4194304; + pub const FASYNCWRITE = 8388608; + pub const DIRECTORY = 134217728; +}; pub const SEEK_SET = 0; pub const SEEK_CUR = 1; @@ -540,81 +540,90 @@ pub const stack_t = extern struct { ss_flags: i32, }; -pub const S_IREAD = S_IRUSR; -pub const S_IEXEC = S_IXUSR; -pub const S_IWRITE = S_IWUSR; -pub const S_IXOTH = 1; -pub const S_IWOTH = 2; -pub const S_IROTH = 4; -pub const S_IRWXO = 7; -pub const S_IXGRP = 8; -pub const S_IWGRP = 16; -pub const S_IRGRP = 32; -pub const S_IRWXG = 56; -pub const S_IXUSR = 64; -pub const S_IWUSR = 128; -pub const S_IRUSR = 256; -pub const S_IRWXU = 448; -pub const S_ISTXT = 512; -pub const S_BLKSIZE = 512; -pub const S_ISVTX = 512; -pub const S_ISGID = 1024; -pub const S_ISUID = 2048; -pub const S_IFIFO = 4096; -pub const S_IFCHR = 8192; -pub const S_IFDIR = 16384; -pub const S_IFBLK = 24576; -pub const S_IFREG = 32768; -pub const S_IFDB = 36864; -pub const S_IFLNK = 40960; -pub const S_IFSOCK = 49152; -pub const S_IFWHT = 57344; -pub const S_IFMT = 61440; +pub const S = struct { + pub const IREAD = IRUSR; + pub const IEXEC = IXUSR; + pub const IWRITE = IWUSR; + pub const IXOTH = 1; + pub const IWOTH = 2; + pub const IROTH = 4; + pub const IRWXO = 7; + pub const IXGRP = 8; + pub const IWGRP = 16; + pub const IRGRP = 32; + pub const IRWXG = 56; + pub const IXUSR = 64; + pub const IWUSR = 128; + pub const IRUSR = 256; + pub const IRWXU = 448; + pub const ISTXT = 512; + pub const BLKSIZE = 512; + pub const ISVTX = 512; + pub const ISGID = 1024; + pub const ISUID = 2048; + pub const IFIFO = 4096; + pub const IFCHR = 8192; + pub const IFDIR = 16384; + pub const IFBLK = 24576; + pub const IFREG = 32768; + pub const IFDB = 36864; + pub const IFLNK = 40960; + pub const IFSOCK = 49152; + pub const IFWHT = 57344; + pub const IFMT = 61440; -pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); -pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); -pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); -pub const BADSIG = SIG_ERR; + pub fn ISCHR(m: u32) bool { + return m & IFMT == IFCHR; + } +}; -pub const SIG_BLOCK = 1; -pub const SIG_UNBLOCK = 2; -pub const SIG_SETMASK = 3; +pub const BADSIG = SIG.ERR; -pub const SIGIOT = SIGABRT; -pub const SIGHUP = 1; -pub const SIGINT = 2; -pub const SIGQUIT = 3; -pub const SIGILL = 4; -pub const SIGTRAP = 5; -pub const SIGABRT = 6; -pub const SIGEMT = 7; -pub const SIGFPE = 8; -pub const SIGKILL = 9; -pub const SIGBUS = 10; -pub const SIGSEGV = 11; -pub const SIGSYS = 12; -pub const SIGPIPE = 13; -pub const SIGALRM = 14; -pub const SIGTERM = 15; -pub const SIGURG = 16; -pub const SIGSTOP = 17; -pub const SIGTSTP = 18; -pub const SIGCONT = 19; -pub const SIGCHLD = 20; -pub const SIGTTIN = 21; -pub const SIGTTOU = 22; -pub const SIGIO = 23; -pub const SIGXCPU = 24; -pub const SIGXFSZ = 25; -pub const SIGVTALRM = 26; -pub const SIGPROF = 27; -pub const SIGWINCH = 28; -pub const SIGINFO = 29; -pub const SIGUSR1 = 30; -pub const SIGUSR2 = 31; -pub const SIGTHR = 32; -pub const SIGCKPT = 33; -pub const SIGCKPTEXIT = 34; +pub const SIG = struct { + pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); + pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); + pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); + + pub const BLOCK = 1; + pub const UNBLOCK = 2; + pub const SETMASK = 3; + + pub const IOT = ABRT; + pub const HUP = 1; + pub const INT = 2; + pub const QUIT = 3; + pub const ILL = 4; + pub const TRAP = 5; + pub const ABRT = 6; + pub const EMT = 7; + pub const FPE = 8; + pub const KILL = 9; + pub const BUS = 10; + pub const SEGV = 11; + pub const SYS = 12; + pub const PIPE = 13; + pub const ALRM = 14; + pub const TERM = 15; + pub const URG = 16; + pub const STOP = 17; + pub const TSTP = 18; + pub const CONT = 19; + pub const CHLD = 20; + pub const TTIN = 21; + pub const TTOU = 22; + pub const IO = 23; + pub const XCPU = 24; + pub const XFSZ = 25; + pub const VTALRM = 26; + pub const PROF = 27; + pub const WINCH = 28; + pub const INFO = 29; + pub const USR1 = 30; + pub const USR2 = 31; + pub const THR = 32; + pub const CKPT = 33; + pub const CKPTEXIT = 34; +}; pub const siginfo_t = extern struct { signo: c_int, diff --git a/lib/std/c/freebsd.zig b/lib/std/c/freebsd.zig index 5c9cf82b097a88ec84c91398ce864bee3f1f719e..3e5fbf25feb9a0aef4339c7712edaf6f21c96807 100644 --- a/lib/std/c/freebsd.zig +++ b/lib/std/c/freebsd.zig @@ -363,10 +363,12 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -pub const PROT_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; +pub const PROT = struct { + pub const NONE = 0; + pub const READ = 1; + pub const WRITE = 2; + pub const EXEC = 4; +}; pub const CLOCK = struct { pub const REALTIME = 0; @@ -504,33 +506,35 @@ pub const X_OK = 1; // test for execute or search permission pub const W_OK = 2; // test for write permission pub const R_OK = 4; // test for read permission -pub const O_RDONLY = 0x0000; -pub const O_WRONLY = 0x0001; -pub const O_RDWR = 0x0002; -pub const O_ACCMODE = 0x0003; +pub const O = struct { + pub const RDONLY = 0x0000; + pub const WRONLY = 0x0001; + pub const RDWR = 0x0002; + pub const ACCMODE = 0x0003; -pub const O_SHLOCK = 0x0010; -pub const O_EXLOCK = 0x0020; + pub const SHLOCK = 0x0010; + pub const EXLOCK = 0x0020; -pub const O_CREAT = 0x0200; -pub const O_EXCL = 0x0800; -pub const O_NOCTTY = 0x8000; -pub const O_TRUNC = 0x0400; -pub const O_APPEND = 0x0008; -pub const O_NONBLOCK = 0x0004; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0x0080; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0x20000; -pub const O_NOFOLLOW = 0x0100; -pub const O_CLOEXEC = 0x00100000; + pub const CREAT = 0x0200; + pub const EXCL = 0x0800; + pub const NOCTTY = 0x8000; + pub const TRUNC = 0x0400; + pub const APPEND = 0x0008; + pub const NONBLOCK = 0x0004; + pub const DSYNC = 0o10000; + pub const SYNC = 0x0080; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0x20000; + pub const NOFOLLOW = 0x0100; + pub const CLOEXEC = 0x00100000; -pub const O_ASYNC = 0x0040; -pub const O_DIRECT = 0x00010000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20200000; -pub const O_NDELAY = O_NONBLOCK; + pub const ASYNC = 0x0040; + pub const DIRECT = 0x00010000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20200000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -877,31 +881,33 @@ pub const NOTE_NSECONDS = 0x00000008; /// timeout is absolute pub const NOTE_ABSTIME = 0x00000010; -pub const TIOCEXCL = 0x2000740d; -pub const TIOCNXCL = 0x2000740e; -pub const TIOCSCTTY = 0x20007461; -pub const TIOCGPGRP = 0x40047477; -pub const TIOCSPGRP = 0x80047476; -pub const TIOCOUTQ = 0x40047473; -pub const TIOCSTI = 0x80017472; -pub const TIOCGWINSZ = 0x40087468; -pub const TIOCSWINSZ = 0x80087467; -pub const TIOCMGET = 0x4004746a; -pub const TIOCMBIS = 0x8004746c; -pub const TIOCMBIC = 0x8004746b; -pub const TIOCMSET = 0x8004746d; -pub const FIONREAD = 0x4004667f; -pub const TIOCCONS = 0x80047462; -pub const TIOCPKT = 0x80047470; -pub const FIONBIO = 0x8004667e; -pub const TIOCNOTTY = 0x20007471; -pub const TIOCSETD = 0x8004741b; -pub const TIOCGETD = 0x4004741a; -pub const TIOCSBRK = 0x2000747b; -pub const TIOCCBRK = 0x2000747a; -pub const TIOCGSID = 0x40047463; -pub const TIOCGPTN = 0x4004740f; -pub const TIOCSIG = 0x2004745f; +pub const T = struct { + pub const IOCEXCL = 0x2000740d; + pub const IOCNXCL = 0x2000740e; + pub const IOCSCTTY = 0x20007461; + pub const IOCGPGRP = 0x40047477; + pub const IOCSPGRP = 0x80047476; + pub const IOCOUTQ = 0x40047473; + pub const IOCSTI = 0x80017472; + pub const IOCGWINSZ = 0x40087468; + pub const IOCSWINSZ = 0x80087467; + pub const IOCMGET = 0x4004746a; + pub const IOCMBIS = 0x8004746c; + pub const IOCMBIC = 0x8004746b; + pub const IOCMSET = 0x8004746d; + pub const FIONREAD = 0x4004667f; + pub const IOCCONS = 0x80047462; + pub const IOCPKT = 0x80047470; + pub const FIONBIO = 0x8004667e; + pub const IOCNOTTY = 0x20007471; + pub const IOCSETD = 0x8004741b; + pub const IOCGETD = 0x4004741a; + pub const IOCSBRK = 0x2000747b; + pub const IOCCBRK = 0x2000747a; + pub const IOCGSID = 0x40047463; + pub const IOCGPTN = 0x4004740f; + pub const IOCSIG = 0x2004745f; +}; pub fn WEXITSTATUS(s: u32) u8 { return @intCast(u8, (s & 0xff00) >> 8); @@ -1166,69 +1172,71 @@ pub const SS_ONSTACK = 1; pub const SS_DISABLE = 4; pub const stack_t = extern struct { - ss_sp: [*]u8, - ss_size: isize, - ss_flags: i32, + sp: [*]u8, + size: isize, + flags: i32, }; -pub const S_IFMT = 0o170000; - -pub const S_IFIFO = 0o010000; -pub const S_IFCHR = 0o020000; -pub const S_IFDIR = 0o040000; -pub const S_IFBLK = 0o060000; -pub const S_IFREG = 0o100000; -pub const S_IFLNK = 0o120000; -pub const S_IFSOCK = 0o140000; -pub const S_IFWHT = 0o160000; - -pub const S_ISUID = 0o4000; -pub const S_ISGID = 0o2000; -pub const S_ISVTX = 0o1000; -pub const S_IRWXU = 0o700; -pub const S_IRUSR = 0o400; -pub const S_IWUSR = 0o200; -pub const S_IXUSR = 0o100; -pub const S_IRWXG = 0o070; -pub const S_IRGRP = 0o040; -pub const S_IWGRP = 0o020; -pub const S_IXGRP = 0o010; -pub const S_IRWXO = 0o007; -pub const S_IROTH = 0o004; -pub const S_IWOTH = 0o002; -pub const S_IXOTH = 0o001; - -pub fn S_ISFIFO(m: u32) bool { - return m & S_IFMT == S_IFIFO; -} - -pub fn S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} - -pub fn S_ISDIR(m: u32) bool { - return m & S_IFMT == S_IFDIR; -} - -pub fn S_ISBLK(m: u32) bool { - return m & S_IFMT == S_IFBLK; -} - -pub fn S_ISREG(m: u32) bool { - return m & S_IFMT == S_IFREG; -} - -pub fn S_ISLNK(m: u32) bool { - return m & S_IFMT == S_IFLNK; -} - -pub fn S_ISSOCK(m: u32) bool { - return m & S_IFMT == S_IFSOCK; -} - -pub fn S_IWHT(m: u32) bool { - return m & S_IFMT == S_IFWHT; -} +pub const S = struct { + pub const IFMT = 0o170000; + + pub const IFIFO = 0o010000; + pub const IFCHR = 0o020000; + pub const IFDIR = 0o040000; + pub const IFBLK = 0o060000; + pub const IFREG = 0o100000; + pub const IFLNK = 0o120000; + pub const IFSOCK = 0o140000; + pub const IFWHT = 0o160000; + + pub const ISUID = 0o4000; + pub const ISGID = 0o2000; + pub const ISVTX = 0o1000; + pub const IRWXU = 0o700; + pub const IRUSR = 0o400; + pub const IWUSR = 0o200; + pub const IXUSR = 0o100; + pub const IRWXG = 0o070; + pub const IRGRP = 0o040; + pub const IWGRP = 0o020; + pub const IXGRP = 0o010; + pub const IRWXO = 0o007; + pub const IROTH = 0o004; + pub const IWOTH = 0o002; + pub const IXOTH = 0o001; + + pub fn ISFIFO(m: u32) bool { + return m & IFMT == IFIFO; + } + + pub fn ISCHR(m: u32) bool { + return m & IFMT == IFCHR; + } + + pub fn ISDIR(m: u32) bool { + return m & IFMT == IFDIR; + } + + pub fn ISBLK(m: u32) bool { + return m & IFMT == IFBLK; + } + + pub fn ISREG(m: u32) bool { + return m & IFMT == IFREG; + } + + pub fn ISLNK(m: u32) bool { + return m & IFMT == IFLNK; + } + + pub fn ISSOCK(m: u32) bool { + return m & IFMT == IFSOCK; + } + + pub fn IWHT(m: u32) bool { + return m & IFMT == IFWHT; + } +}; pub const HOST_NAME_MAX = 255; diff --git a/lib/std/c/haiku.zig b/lib/std/c/haiku.zig index b5aa325908c319e6eaef47ba14d192895216ab75..e759ab10a4a977b627d3838918322785b5c25813 100644 --- a/lib/std/c/haiku.zig +++ b/lib/std/c/haiku.zig @@ -377,10 +377,12 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -pub const PROT_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; +pub const PROT = struct { + pub const NONE = 0; + pub const READ = 1; + pub const WRITE = 2; + pub const EXEC = 4; +}; pub const CLOCK = struct { pub const MONOTONIC = 0; @@ -425,6 +427,10 @@ pub const SA_STACK = SA_ONSTACK; pub const SA_ONESHOT = SA_RESETHAND; pub const SIG = struct { + pub const ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize)); + pub const DFL = @intToPtr(fn (i32) callconv(.C) void, 0); + pub const IGN = @intToPtr(fn (i32) callconv(.C) void, 1); + pub const HUP = 1; pub const INT = 2; pub const QUIT = 3; @@ -489,33 +495,35 @@ pub const X_OK = 1; // test for execute or search permission pub const W_OK = 2; // test for write permission pub const R_OK = 4; // test for read permission -pub const O_RDONLY = 0x0000; -pub const O_WRONLY = 0x0001; -pub const O_RDWR = 0x0002; -pub const O_ACCMODE = 0x0003; +pub const O = struct { + pub const RDONLY = 0x0000; + pub const WRONLY = 0x0001; + pub const RDWR = 0x0002; + pub const ACCMODE = 0x0003; -pub const O_SHLOCK = 0x0010; -pub const O_EXLOCK = 0x0020; + pub const SHLOCK = 0x0010; + pub const EXLOCK = 0x0020; -pub const O_CREAT = 0x0200; -pub const O_EXCL = 0x0800; -pub const O_NOCTTY = 0x8000; -pub const O_TRUNC = 0x0400; -pub const O_APPEND = 0x0008; -pub const O_NONBLOCK = 0x0004; -pub const O_DSYNC = 0o10000; -pub const O_SYNC = 0x0080; -pub const O_RSYNC = 0o4010000; -pub const O_DIRECTORY = 0x20000; -pub const O_NOFOLLOW = 0x0100; -pub const O_CLOEXEC = 0x00100000; + pub const CREAT = 0x0200; + pub const EXCL = 0x0800; + pub const NOCTTY = 0x8000; + pub const TRUNC = 0x0400; + pub const APPEND = 0x0008; + pub const NONBLOCK = 0x0004; + pub const DSYNC = 0o10000; + pub const SYNC = 0x0080; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0x20000; + pub const NOFOLLOW = 0x0100; + pub const CLOEXEC = 0x00100000; -pub const O_ASYNC = 0x0040; -pub const O_DIRECT = 0x00010000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20200000; -pub const O_NDELAY = O_NONBLOCK; + pub const ASYNC = 0x0040; + pub const DIRECT = 0x00010000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20200000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -773,52 +781,56 @@ pub const EVFILT_SENDFILE = -12; pub const EVFILT_EMPTY = -13; -pub const TCGETA = 0x8000; -pub const TCSETA = 0x8001; -pub const TCSETAW = 0x8004; -pub const TCSETAF = 0x8003; -pub const TCSBRK = 08005; -pub const TCXONC = 0x8007; -pub const TCFLSH = 0x8006; +pub const T = struct { + pub const CGETA = 0x8000; + pub const CSETA = 0x8001; + pub const CSETAW = 0x8004; + pub const CSETAF = 0x8003; + pub const CSBRK = 08005; + pub const CXONC = 0x8007; + pub const CFLSH = 0x8006; -pub const TIOCSCTTY = 0x8017; -pub const TIOCGPGRP = 0x8015; -pub const TIOCSPGRP = 0x8016; -pub const TIOCGWINSZ = 0x8012; -pub const TIOCSWINSZ = 0x8013; -pub const TIOCMGET = 0x8018; -pub const TIOCMBIS = 0x8022; -pub const TIOCMBIC = 0x8023; -pub const TIOCMSET = 0x8019; -pub const FIONREAD = 0xbe000001; -pub const FIONBIO = 0xbe000000; -pub const TIOCSBRK = 0x8020; -pub const TIOCCBRK = 0x8021; -pub const TIOCGSID = 0x8024; + pub const IOCSCTTY = 0x8017; + pub const IOCGPGRP = 0x8015; + pub const IOCSPGRP = 0x8016; + pub const IOCGWINSZ = 0x8012; + pub const IOCSWINSZ = 0x8013; + pub const IOCMGET = 0x8018; + pub const IOCMBIS = 0x8022; + pub const IOCMBIC = 0x8023; + pub const IOCMSET = 0x8019; + pub const FIONREAD = 0xbe000001; + pub const FIONBIO = 0xbe000000; + pub const IOCSBRK = 0x8020; + pub const IOCCBRK = 0x8021; + pub const IOCGSID = 0x8024; +}; -pub fn WEXITSTATUS(s: u32) u8 { - return @intCast(u8, s & 0xff); -} +pub const W = struct { + pub fn EXITSTATUS(s: u32) u8 { + return @intCast(u8, s & 0xff); + } -pub fn WTERMSIG(s: u32) u32 { - return (s >> 8) & 0xff; -} + pub fn TERMSIG(s: u32) u32 { + return (s >> 8) & 0xff; + } -pub fn WSTOPSIG(s: u32) u32 { - return WEXITSTATUS(s); -} + pub fn STOPSIG(s: u32) u32 { + return EXITSTATUS(s); + } -pub fn WIFEXITED(s: u32) bool { - return WTERMSIG(s) == 0; -} + pub fn IFEXITED(s: u32) bool { + return TERMSIG(s) == 0; + } -pub fn WIFSTOPPED(s: u32) bool { - return ((s >> 16) & 0xff) != 0; -} + pub fn IFSTOPPED(s: u32) bool { + return ((s >> 16) & 0xff) != 0; + } -pub fn WIFSIGNALED(s: u32) bool { - return ((s >> 8) & 0xff) != 0; -} + pub fn IFSIGNALED(s: u32) bool { + return ((s >> 8) & 0xff) != 0; + } +}; pub const winsize = extern struct { ws_row: u16, @@ -829,10 +841,6 @@ pub const winsize = extern struct { const NSIG = 32; -pub const SIG_ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize)); -pub const SIG_DFL = @intToPtr(fn (i32) callconv(.C) void, 0); -pub const SIG_IGN = @intToPtr(fn (i32) callconv(.C) void, 1); - /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. pub const Sigaction = extern struct { /// signal handler @@ -992,64 +1000,66 @@ pub const stack_t = extern struct { ss_flags: i32, }; -pub const S_IFMT = 0o170000; - -pub const S_IFIFO = 0o010000; -pub const S_IFCHR = 0o020000; -pub const S_IFDIR = 0o040000; -pub const S_IFBLK = 0o060000; -pub const S_IFREG = 0o100000; -pub const S_IFLNK = 0o120000; -pub const S_IFSOCK = 0o140000; -pub const S_IFWHT = 0o160000; - -pub const S_ISUID = 0o4000; -pub const S_ISGID = 0o2000; -pub const S_ISVTX = 0o1000; -pub const S_IRWXU = 0o700; -pub const S_IRUSR = 0o400; -pub const S_IWUSR = 0o200; -pub const S_IXUSR = 0o100; -pub const S_IRWXG = 0o070; -pub const S_IRGRP = 0o040; -pub const S_IWGRP = 0o020; -pub const S_IXGRP = 0o010; -pub const S_IRWXO = 0o007; -pub const S_IROTH = 0o004; -pub const S_IWOTH = 0o002; -pub const S_IXOTH = 0o001; - -pub fn S_ISFIFO(m: u32) bool { - return m & S_IFMT == S_IFIFO; -} - -pub fn S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} - -pub fn S_ISDIR(m: u32) bool { - return m & S_IFMT == S_IFDIR; -} - -pub fn S_ISBLK(m: u32) bool { - return m & S_IFMT == S_IFBLK; -} - -pub fn S_ISREG(m: u32) bool { - return m & S_IFMT == S_IFREG; -} - -pub fn S_ISLNK(m: u32) bool { - return m & S_IFMT == S_IFLNK; -} - -pub fn S_ISSOCK(m: u32) bool { - return m & S_IFMT == S_IFSOCK; -} - -pub fn S_IWHT(m: u32) bool { - return m & S_IFMT == S_IFWHT; -} +pub const S = struct { + pub const IFMT = 0o170000; + + pub const IFIFO = 0o010000; + pub const IFCHR = 0o020000; + pub const IFDIR = 0o040000; + pub const IFBLK = 0o060000; + pub const IFREG = 0o100000; + pub const IFLNK = 0o120000; + pub const IFSOCK = 0o140000; + pub const IFWHT = 0o160000; + + pub const ISUID = 0o4000; + pub const ISGID = 0o2000; + pub const ISVTX = 0o1000; + pub const IRWXU = 0o700; + pub const IRUSR = 0o400; + pub const IWUSR = 0o200; + pub const IXUSR = 0o100; + pub const IRWXG = 0o070; + pub const IRGRP = 0o040; + pub const IWGRP = 0o020; + pub const IXGRP = 0o010; + pub const IRWXO = 0o007; + pub const IROTH = 0o004; + pub const IWOTH = 0o002; + pub const IXOTH = 0o001; + + pub fn ISFIFO(m: u32) bool { + return m & IFMT == IFIFO; + } + + pub fn ISCHR(m: u32) bool { + return m & IFMT == IFCHR; + } + + pub fn ISDIR(m: u32) bool { + return m & IFMT == IFDIR; + } + + pub fn ISBLK(m: u32) bool { + return m & IFMT == IFBLK; + } + + pub fn ISREG(m: u32) bool { + return m & IFMT == IFREG; + } + + pub fn ISLNK(m: u32) bool { + return m & IFMT == IFLNK; + } + + pub fn ISSOCK(m: u32) bool { + return m & IFMT == IFSOCK; + } + + pub fn IWHT(m: u32) bool { + return m & IFMT == IFWHT; + } +}; pub const HOST_NAME_MAX = 255; diff --git a/lib/std/c/linux.zig b/lib/std/c/linux.zig index 00b88ecb02dfbfd6304305afa34b15fdc9435322..5ffdc376897aadb5ce98c2e0116a28b3ecb67b1a 100644 --- a/lib/std/c/linux.zig +++ b/lib/std/c/linux.zig @@ -25,7 +25,11 @@ pub const IOV_MAX = linux.IOV_MAX; pub const IPPROTO = linux.IPPROTO; pub const LOCK = linux.LOCK; pub const MADV = linux.MADV; -pub const MAP = linux.MAP; +pub const MAP = struct { + pub usingnamespace linux.MAP; + /// Only used by libc to communicate failure. + pub const FAILED = @intToPtr(*c_void, maxInt(usize)); +}; pub const MMAP2_UNIT = linux.MMAP2_UNIT; pub const NAME_MAX = linux.NAME_MAX; pub const O = linux.O; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index c5bc633e018442fcd4f7402ba2bc33e7d51afa34..cf066f3f470ce6d3cf0a6931670c6ec9b612a68f 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -534,10 +534,12 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -pub const PROT_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; +pub const PROT = struct { + pub const NONE = 0; + pub const READ = 1; + pub const WRITE = 2; + pub const EXEC = 4; +}; pub const CLOCK = struct { pub const REALTIME = 0; @@ -589,71 +591,52 @@ pub const X_OK = 1; // test for execute or search permission pub const W_OK = 2; // test for write permission pub const R_OK = 4; // test for read permission -/// open for reading only -pub const O_RDONLY = 0x00000000; - -/// open for writing only -pub const O_WRONLY = 0x00000001; - -/// open for reading and writing -pub const O_RDWR = 0x00000002; - -/// mask for above modes -pub const O_ACCMODE = 0x00000003; - -/// no delay -pub const O_NONBLOCK = 0x00000004; - -/// set append mode -pub const O_APPEND = 0x00000008; - -/// open with shared file lock -pub const O_SHLOCK = 0x00000010; - -/// open with exclusive file lock -pub const O_EXLOCK = 0x00000020; - -/// signal pgrp when data ready -pub const O_ASYNC = 0x00000040; - -/// synchronous writes -pub const O_SYNC = 0x00000080; - -/// don't follow symlinks on the last -pub const O_NOFOLLOW = 0x00000100; - -/// create if nonexistent -pub const O_CREAT = 0x00000200; - -/// truncate to zero length -pub const O_TRUNC = 0x00000400; - -/// error if already exists -pub const O_EXCL = 0x00000800; - -/// don't assign controlling terminal -pub const O_NOCTTY = 0x00008000; - -/// write: I/O data completion -pub const O_DSYNC = 0x00010000; - -/// read: I/O completion as for write -pub const O_RSYNC = 0x00020000; - -/// use alternate i/o semantics -pub const O_ALT_IO = 0x00040000; - -/// direct I/O hint -pub const O_DIRECT = 0x00080000; - -/// fail if not a directory -pub const O_DIRECTORY = 0x00200000; - -/// set close on exec -pub const O_CLOEXEC = 0x00400000; - -/// skip search permission checks -pub const O_SEARCH = 0x00800000; +pub const O = struct { + /// open for reading only + pub const RDONLY = 0x00000000; + /// open for writing only + pub const WRONLY = 0x00000001; + /// open for reading and writing + pub const RDWR = 0x00000002; + /// mask for above modes + pub const ACCMODE = 0x00000003; + /// no delay + pub const NONBLOCK = 0x00000004; + /// set append mode + pub const APPEND = 0x00000008; + /// open with shared file lock + pub const SHLOCK = 0x00000010; + /// open with exclusive file lock + pub const EXLOCK = 0x00000020; + /// signal pgrp when data ready + pub const ASYNC = 0x00000040; + /// synchronous writes + pub const SYNC = 0x00000080; + /// don't follow symlinks on the last + pub const NOFOLLOW = 0x00000100; + /// create if nonexistent + pub const CREAT = 0x00000200; + /// truncate to zero length + pub const TRUNC = 0x00000400; + /// error if already exists + pub const EXCL = 0x00000800; + /// don't assign controlling terminal + pub const NOCTTY = 0x00008000; + /// write: I/O data completion + pub const DSYNC = 0x00010000; + /// read: I/O completion as for write + pub const RSYNC = 0x00020000; + /// use alternate i/o semantics + pub const ALT_IO = 0x00040000; + /// direct I/O hint + pub const DIRECT = 0x00080000; + /// fail if not a directory + pub const DIRECTORY = 0x00200000; + /// set close on exec + pub const CLOEXEC = 0x00400000; + /// skip search permission checks + pub const SEARCH = 0x00800000; +}; pub const F = struct { pub const DUPFD = 0; @@ -687,10 +670,6 @@ pub const SEEK_SET = 0; pub const SEEK_CUR = 1; pub const SEEK_END = 2; -pub const SIG_BLOCK = 1; -pub const SIG_UNBLOCK = 2; -pub const SIG_SETMASK = 3; - pub const DT_UNKNOWN = 0; pub const DT_FIFO = 1; pub const DT_CHR = 2; @@ -789,80 +768,82 @@ pub const NOTE_EXEC = 0x20000000; pub const NOTE_PDATAMASK = 0x000fffff; pub const NOTE_PCTRLMASK = 0xf0000000; -pub const TIOCCBRK = 0x2000747a; -pub const TIOCCDTR = 0x20007478; -pub const TIOCCONS = 0x80047462; -pub const TIOCDCDTIMESTAMP = 0x40107458; -pub const TIOCDRAIN = 0x2000745e; -pub const TIOCEXCL = 0x2000740d; -pub const TIOCEXT = 0x80047460; -pub const TIOCFLAG_CDTRCTS = 0x10; -pub const TIOCFLAG_CLOCAL = 0x2; -pub const TIOCFLAG_CRTSCTS = 0x4; -pub const TIOCFLAG_MDMBUF = 0x8; -pub const TIOCFLAG_SOFTCAR = 0x1; -pub const TIOCFLUSH = 0x80047410; -pub const TIOCGETA = 0x402c7413; -pub const TIOCGETD = 0x4004741a; -pub const TIOCGFLAGS = 0x4004745d; -pub const TIOCGLINED = 0x40207442; -pub const TIOCGPGRP = 0x40047477; -pub const TIOCGQSIZE = 0x40047481; -pub const TIOCGRANTPT = 0x20007447; -pub const TIOCGSID = 0x40047463; -pub const TIOCGSIZE = 0x40087468; -pub const TIOCGWINSZ = 0x40087468; -pub const TIOCMBIC = 0x8004746b; -pub const TIOCMBIS = 0x8004746c; -pub const TIOCMGET = 0x4004746a; -pub const TIOCMSET = 0x8004746d; -pub const TIOCM_CAR = 0x40; -pub const TIOCM_CD = 0x40; -pub const TIOCM_CTS = 0x20; -pub const TIOCM_DSR = 0x100; -pub const TIOCM_DTR = 0x2; -pub const TIOCM_LE = 0x1; -pub const TIOCM_RI = 0x80; -pub const TIOCM_RNG = 0x80; -pub const TIOCM_RTS = 0x4; -pub const TIOCM_SR = 0x10; -pub const TIOCM_ST = 0x8; -pub const TIOCNOTTY = 0x20007471; -pub const TIOCNXCL = 0x2000740e; -pub const TIOCOUTQ = 0x40047473; -pub const TIOCPKT = 0x80047470; -pub const TIOCPKT_DATA = 0x0; -pub const TIOCPKT_DOSTOP = 0x20; -pub const TIOCPKT_FLUSHREAD = 0x1; -pub const TIOCPKT_FLUSHWRITE = 0x2; -pub const TIOCPKT_IOCTL = 0x40; -pub const TIOCPKT_NOSTOP = 0x10; -pub const TIOCPKT_START = 0x8; -pub const TIOCPKT_STOP = 0x4; -pub const TIOCPTMGET = 0x40287446; -pub const TIOCPTSNAME = 0x40287448; -pub const TIOCRCVFRAME = 0x80087445; -pub const TIOCREMOTE = 0x80047469; -pub const TIOCSBRK = 0x2000747b; -pub const TIOCSCTTY = 0x20007461; -pub const TIOCSDTR = 0x20007479; -pub const TIOCSETA = 0x802c7414; -pub const TIOCSETAF = 0x802c7416; -pub const TIOCSETAW = 0x802c7415; -pub const TIOCSETD = 0x8004741b; -pub const TIOCSFLAGS = 0x8004745c; -pub const TIOCSIG = 0x2000745f; -pub const TIOCSLINED = 0x80207443; -pub const TIOCSPGRP = 0x80047476; -pub const TIOCSQSIZE = 0x80047480; -pub const TIOCSSIZE = 0x80087467; -pub const TIOCSTART = 0x2000746e; -pub const TIOCSTAT = 0x80047465; -pub const TIOCSTI = 0x80017472; -pub const TIOCSTOP = 0x2000746f; -pub const TIOCSWINSZ = 0x80087467; -pub const TIOCUCNTL = 0x80047466; -pub const TIOCXMTFRAME = 0x80087444; +pub const T = struct { + pub const IOCCBRK = 0x2000747a; + pub const IOCCDTR = 0x20007478; + pub const IOCCONS = 0x80047462; + pub const IOCDCDTIMESTAMP = 0x40107458; + pub const IOCDRAIN = 0x2000745e; + pub const IOCEXCL = 0x2000740d; + pub const IOCEXT = 0x80047460; + pub const IOCFLAG_CDTRCTS = 0x10; + pub const IOCFLAG_CLOCAL = 0x2; + pub const IOCFLAG_CRTSCTS = 0x4; + pub const IOCFLAG_MDMBUF = 0x8; + pub const IOCFLAG_SOFTCAR = 0x1; + pub const IOCFLUSH = 0x80047410; + pub const IOCGETA = 0x402c7413; + pub const IOCGETD = 0x4004741a; + pub const IOCGFLAGS = 0x4004745d; + pub const IOCGLINED = 0x40207442; + pub const IOCGPGRP = 0x40047477; + pub const IOCGQSIZE = 0x40047481; + pub const IOCGRANTPT = 0x20007447; + pub const IOCGSID = 0x40047463; + pub const IOCGSIZE = 0x40087468; + pub const IOCGWINSZ = 0x40087468; + pub const IOCMBIC = 0x8004746b; + pub const IOCMBIS = 0x8004746c; + pub const IOCMGET = 0x4004746a; + pub const IOCMSET = 0x8004746d; + pub const IOCM_CAR = 0x40; + pub const IOCM_CD = 0x40; + pub const IOCM_CTS = 0x20; + pub const IOCM_DSR = 0x100; + pub const IOCM_DTR = 0x2; + pub const IOCM_LE = 0x1; + pub const IOCM_RI = 0x80; + pub const IOCM_RNG = 0x80; + pub const IOCM_RTS = 0x4; + pub const IOCM_SR = 0x10; + pub const IOCM_ST = 0x8; + pub const IOCNOTTY = 0x20007471; + pub const IOCNXCL = 0x2000740e; + pub const IOCOUTQ = 0x40047473; + pub const IOCPKT = 0x80047470; + pub const IOCPKT_DATA = 0x0; + pub const IOCPKT_DOSTOP = 0x20; + pub const IOCPKT_FLUSHREAD = 0x1; + pub const IOCPKT_FLUSHWRITE = 0x2; + pub const IOCPKT_IOCTL = 0x40; + pub const IOCPKT_NOSTOP = 0x10; + pub const IOCPKT_START = 0x8; + pub const IOCPKT_STOP = 0x4; + pub const IOCPTMGET = 0x40287446; + pub const IOCPTSNAME = 0x40287448; + pub const IOCRCVFRAME = 0x80087445; + pub const IOCREMOTE = 0x80047469; + pub const IOCSBRK = 0x2000747b; + pub const IOCSCTTY = 0x20007461; + pub const IOCSDTR = 0x20007479; + pub const IOCSETA = 0x802c7414; + pub const IOCSETAF = 0x802c7416; + pub const IOCSETAW = 0x802c7415; + pub const IOCSETD = 0x8004741b; + pub const IOCSFLAGS = 0x8004745c; + pub const IOCSIG = 0x2000745f; + pub const IOCSLINED = 0x80207443; + pub const IOCSPGRP = 0x80047476; + pub const IOCSQSIZE = 0x80047480; + pub const IOCSSIZE = 0x80087467; + pub const IOCSTART = 0x2000746e; + pub const IOCSTAT = 0x80047465; + pub const IOCSTI = 0x80017472; + pub const IOCSTOP = 0x2000746f; + pub const IOCSWINSZ = 0x80087467; + pub const IOCUCNTL = 0x80047466; + pub const IOCXMTFRAME = 0x80087444; +}; pub fn WEXITSTATUS(s: u32) u8 { return @intCast(u8, (s >> 8) & 0xff); @@ -906,6 +887,10 @@ pub const SIG = struct { pub const WORDS = 4; pub const MAXSIG = 128; + pub const BLOCK = 1; + pub const UNBLOCK = 2; + pub const SETMASK = 3; + pub const HUP = 1; pub const INT = 2; pub const QUIT = 3; @@ -1213,64 +1198,66 @@ pub const stack_t = extern struct { ss_flags: i32, }; -pub const S_IFMT = 0o170000; - -pub const S_IFIFO = 0o010000; -pub const S_IFCHR = 0o020000; -pub const S_IFDIR = 0o040000; -pub const S_IFBLK = 0o060000; -pub const S_IFREG = 0o100000; -pub const S_IFLNK = 0o120000; -pub const S_IFSOCK = 0o140000; -pub const S_IFWHT = 0o160000; - -pub const S_ISUID = 0o4000; -pub const S_ISGID = 0o2000; -pub const S_ISVTX = 0o1000; -pub const S_IRWXU = 0o700; -pub const S_IRUSR = 0o400; -pub const S_IWUSR = 0o200; -pub const S_IXUSR = 0o100; -pub const S_IRWXG = 0o070; -pub const S_IRGRP = 0o040; -pub const S_IWGRP = 0o020; -pub const S_IXGRP = 0o010; -pub const S_IRWXO = 0o007; -pub const S_IROTH = 0o004; -pub const S_IWOTH = 0o002; -pub const S_IXOTH = 0o001; - -pub fn S_ISFIFO(m: u32) bool { - return m & S_IFMT == S_IFIFO; -} - -pub fn S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} - -pub fn S_ISDIR(m: u32) bool { - return m & S_IFMT == S_IFDIR; -} - -pub fn S_ISBLK(m: u32) bool { - return m & S_IFMT == S_IFBLK; -} - -pub fn S_ISREG(m: u32) bool { - return m & S_IFMT == S_IFREG; -} - -pub fn S_ISLNK(m: u32) bool { - return m & S_IFMT == S_IFLNK; -} - -pub fn S_ISSOCK(m: u32) bool { - return m & S_IFMT == S_IFSOCK; -} - -pub fn S_IWHT(m: u32) bool { - return m & S_IFMT == S_IFWHT; -} +pub const S = struct { + pub const IFMT = 0o170000; + + pub const IFIFO = 0o010000; + pub const IFCHR = 0o020000; + pub const IFDIR = 0o040000; + pub const IFBLK = 0o060000; + pub const IFREG = 0o100000; + pub const IFLNK = 0o120000; + pub const IFSOCK = 0o140000; + pub const IFWHT = 0o160000; + + pub const ISUID = 0o4000; + pub const ISGID = 0o2000; + pub const ISVTX = 0o1000; + pub const IRWXU = 0o700; + pub const IRUSR = 0o400; + pub const IWUSR = 0o200; + pub const IXUSR = 0o100; + pub const IRWXG = 0o070; + pub const IRGRP = 0o040; + pub const IWGRP = 0o020; + pub const IXGRP = 0o010; + pub const IRWXO = 0o007; + pub const IROTH = 0o004; + pub const IWOTH = 0o002; + pub const IXOTH = 0o001; + + pub fn ISFIFO(m: u32) bool { + return m & IFMT == IFIFO; + } + + pub fn ISCHR(m: u32) bool { + return m & IFMT == IFCHR; + } + + pub fn ISDIR(m: u32) bool { + return m & IFMT == IFDIR; + } + + pub fn ISBLK(m: u32) bool { + return m & IFMT == IFBLK; + } + + pub fn ISREG(m: u32) bool { + return m & IFMT == IFREG; + } + + pub fn ISLNK(m: u32) bool { + return m & IFMT == IFLNK; + } + + pub fn ISSOCK(m: u32) bool { + return m & IFMT == IFSOCK; + } + + pub fn IWHT(m: u32) bool { + return m & IFMT == IFWHT; + } +}; pub const AT = struct { /// Magic value that specify the use of the current working directory diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index cd7632df3c469d84974a07f51b25e0ad22c070cd..83a32d52e39d24a2f6d439e9ae48bc7ad850583a 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -330,10 +330,12 @@ pub const STDIN_FILENO = 0; pub const STDOUT_FILENO = 1; pub const STDERR_FILENO = 2; -pub const PROT_NONE = 0; -pub const PROT_READ = 1; -pub const PROT_WRITE = 2; -pub const PROT_EXEC = 4; +pub const PROT = struct { + pub const NONE = 0; + pub const READ = 1; + pub const WRITE = 2; + pub const EXEC = 4; +}; pub const CLOCK = struct { pub const REALTIME = 0; @@ -371,102 +373,52 @@ pub const SA_NODEFER = 0x0010; pub const SA_NOCLDWAIT = 0x0020; pub const SA_SIGINFO = 0x0040; -pub const SIGHUP = 1; -pub const SIGINT = 2; -pub const SIGQUIT = 3; -pub const SIGILL = 4; -pub const SIGTRAP = 5; -pub const SIGABRT = 6; -pub const SIGIOT = SIGABRT; -pub const SIGEMT = 7; -pub const SIGFPE = 8; -pub const SIGKILL = 9; -pub const SIGBUS = 10; -pub const SIGSEGV = 11; -pub const SIGSYS = 12; -pub const SIGPIPE = 13; -pub const SIGALRM = 14; -pub const SIGTERM = 15; -pub const SIGURG = 16; -pub const SIGSTOP = 17; -pub const SIGTSTP = 18; -pub const SIGCONT = 19; -pub const SIGCHLD = 20; -pub const SIGTTIN = 21; -pub const SIGTTOU = 22; -pub const SIGIO = 23; -pub const SIGXCPU = 24; -pub const SIGXFSZ = 25; -pub const SIGVTALRM = 26; -pub const SIGPROF = 27; -pub const SIGWINCH = 28; -pub const SIGINFO = 29; -pub const SIGUSR1 = 30; -pub const SIGUSR2 = 31; -pub const SIGPWR = 32; - // access function pub const F_OK = 0; // test for existence of file pub const X_OK = 1; // test for execute or search permission pub const W_OK = 2; // test for write permission pub const R_OK = 4; // test for read permission -/// open for reading only -pub const O_RDONLY = 0x00000000; - -/// open for writing only -pub const O_WRONLY = 0x00000001; - -/// open for reading and writing -pub const O_RDWR = 0x00000002; - -/// mask for above modes -pub const O_ACCMODE = 0x00000003; - -/// no delay -pub const O_NONBLOCK = 0x00000004; - -/// set append mode -pub const O_APPEND = 0x00000008; - -/// open with shared file lock -pub const O_SHLOCK = 0x00000010; - -/// open with exclusive file lock -pub const O_EXLOCK = 0x00000020; - -/// signal pgrp when data ready -pub const O_ASYNC = 0x00000040; - -/// synchronous writes -pub const O_SYNC = 0x00000080; - -/// don't follow symlinks on the last -pub const O_NOFOLLOW = 0x00000100; - -/// create if nonexistent -pub const O_CREAT = 0x00000200; - -/// truncate to zero length -pub const O_TRUNC = 0x00000400; - -/// error if already exists -pub const O_EXCL = 0x00000800; - -/// don't assign controlling terminal -pub const O_NOCTTY = 0x00008000; - -/// write: I/O data completion -pub const O_DSYNC = O_SYNC; - -/// read: I/O completion as for write -pub const O_RSYNC = O_SYNC; - -/// fail if not a directory -pub const O_DIRECTORY = 0x20000; - -/// set close on exec -pub const O_CLOEXEC = 0x10000; +pub const O = struct { + /// open for reading only + pub const RDONLY = 0x00000000; + /// open for writing only + pub const WRONLY = 0x00000001; + /// open for reading and writing + pub const RDWR = 0x00000002; + /// mask for above modes + pub const ACCMODE = 0x00000003; + /// no delay + pub const NONBLOCK = 0x00000004; + /// set append mode + pub const APPEND = 0x00000008; + /// open with shared file lock + pub const SHLOCK = 0x00000010; + /// open with exclusive file lock + pub const EXLOCK = 0x00000020; + /// signal pgrp when data ready + pub const ASYNC = 0x00000040; + /// synchronous writes + pub const SYNC = 0x00000080; + /// don't follow symlinks on the last + pub const NOFOLLOW = 0x00000100; + /// create if nonexistent + pub const CREAT = 0x00000200; + /// truncate to zero length + pub const TRUNC = 0x00000400; + /// error if already exists + pub const EXCL = 0x00000800; + /// don't assign controlling terminal + pub const NOCTTY = 0x00008000; + /// write: I/O data completion + pub const DSYNC = SYNC; + /// read: I/O completion as for write + pub const RSYNC = SYNC; + /// fail if not a directory + pub const DIRECTORY = 0x20000; + /// set close on exec + pub const CLOEXEC = 0x10000; +}; pub const F = struct { pub const DUPFD = 0; @@ -500,10 +452,6 @@ pub const SEEK_SET = 0; pub const SEEK_CUR = 1; pub const SEEK_END = 2; -pub const SIG_BLOCK = 1; -pub const SIG_UNBLOCK = 2; -pub const SIG_SETMASK = 3; - pub const SOCK = struct { pub const STREAM = 1; pub const DGRAM = 2; @@ -643,80 +591,82 @@ pub const NOTE_CHILD = 0x00000004; // data/hint flags for EVFILT_DEVICE pub const NOTE_CHANGE = 0x00000001; -pub const TIOCCBRK = 0x2000747a; -pub const TIOCCDTR = 0x20007478; -pub const TIOCCONS = 0x80047462; -pub const TIOCDCDTIMESTAMP = 0x40107458; -pub const TIOCDRAIN = 0x2000745e; -pub const TIOCEXCL = 0x2000740d; -pub const TIOCEXT = 0x80047460; -pub const TIOCFLAG_CDTRCTS = 0x10; -pub const TIOCFLAG_CLOCAL = 0x2; -pub const TIOCFLAG_CRTSCTS = 0x4; -pub const TIOCFLAG_MDMBUF = 0x8; -pub const TIOCFLAG_SOFTCAR = 0x1; -pub const TIOCFLUSH = 0x80047410; -pub const TIOCGETA = 0x402c7413; -pub const TIOCGETD = 0x4004741a; -pub const TIOCGFLAGS = 0x4004745d; -pub const TIOCGLINED = 0x40207442; -pub const TIOCGPGRP = 0x40047477; -pub const TIOCGQSIZE = 0x40047481; -pub const TIOCGRANTPT = 0x20007447; -pub const TIOCGSID = 0x40047463; -pub const TIOCGSIZE = 0x40087468; -pub const TIOCGWINSZ = 0x40087468; -pub const TIOCMBIC = 0x8004746b; -pub const TIOCMBIS = 0x8004746c; -pub const TIOCMGET = 0x4004746a; -pub const TIOCMSET = 0x8004746d; -pub const TIOCM_CAR = 0x40; -pub const TIOCM_CD = 0x40; -pub const TIOCM_CTS = 0x20; -pub const TIOCM_DSR = 0x100; -pub const TIOCM_DTR = 0x2; -pub const TIOCM_LE = 0x1; -pub const TIOCM_RI = 0x80; -pub const TIOCM_RNG = 0x80; -pub const TIOCM_RTS = 0x4; -pub const TIOCM_SR = 0x10; -pub const TIOCM_ST = 0x8; -pub const TIOCNOTTY = 0x20007471; -pub const TIOCNXCL = 0x2000740e; -pub const TIOCOUTQ = 0x40047473; -pub const TIOCPKT = 0x80047470; -pub const TIOCPKT_DATA = 0x0; -pub const TIOCPKT_DOSTOP = 0x20; -pub const TIOCPKT_FLUSHREAD = 0x1; -pub const TIOCPKT_FLUSHWRITE = 0x2; -pub const TIOCPKT_IOCTL = 0x40; -pub const TIOCPKT_NOSTOP = 0x10; -pub const TIOCPKT_START = 0x8; -pub const TIOCPKT_STOP = 0x4; -pub const TIOCPTMGET = 0x40287446; -pub const TIOCPTSNAME = 0x40287448; -pub const TIOCRCVFRAME = 0x80087445; -pub const TIOCREMOTE = 0x80047469; -pub const TIOCSBRK = 0x2000747b; -pub const TIOCSCTTY = 0x20007461; -pub const TIOCSDTR = 0x20007479; -pub const TIOCSETA = 0x802c7414; -pub const TIOCSETAF = 0x802c7416; -pub const TIOCSETAW = 0x802c7415; -pub const TIOCSETD = 0x8004741b; -pub const TIOCSFLAGS = 0x8004745c; -pub const TIOCSIG = 0x2000745f; -pub const TIOCSLINED = 0x80207443; -pub const TIOCSPGRP = 0x80047476; -pub const TIOCSQSIZE = 0x80047480; -pub const TIOCSSIZE = 0x80087467; -pub const TIOCSTART = 0x2000746e; -pub const TIOCSTAT = 0x80047465; -pub const TIOCSTI = 0x80017472; -pub const TIOCSTOP = 0x2000746f; -pub const TIOCSWINSZ = 0x80087467; -pub const TIOCUCNTL = 0x80047466; -pub const TIOCXMTFRAME = 0x80087444; +pub const T = struct { + pub const IOCCBRK = 0x2000747a; + pub const IOCCDTR = 0x20007478; + pub const IOCCONS = 0x80047462; + pub const IOCDCDTIMESTAMP = 0x40107458; + pub const IOCDRAIN = 0x2000745e; + pub const IOCEXCL = 0x2000740d; + pub const IOCEXT = 0x80047460; + pub const IOCFLAG_CDTRCTS = 0x10; + pub const IOCFLAG_CLOCAL = 0x2; + pub const IOCFLAG_CRTSCTS = 0x4; + pub const IOCFLAG_MDMBUF = 0x8; + pub const IOCFLAG_SOFTCAR = 0x1; + pub const IOCFLUSH = 0x80047410; + pub const IOCGETA = 0x402c7413; + pub const IOCGETD = 0x4004741a; + pub const IOCGFLAGS = 0x4004745d; + pub const IOCGLINED = 0x40207442; + pub const IOCGPGRP = 0x40047477; + pub const IOCGQSIZE = 0x40047481; + pub const IOCGRANTPT = 0x20007447; + pub const IOCGSID = 0x40047463; + pub const IOCGSIZE = 0x40087468; + pub const IOCGWINSZ = 0x40087468; + pub const IOCMBIC = 0x8004746b; + pub const IOCMBIS = 0x8004746c; + pub const IOCMGET = 0x4004746a; + pub const IOCMSET = 0x8004746d; + pub const IOCM_CAR = 0x40; + pub const IOCM_CD = 0x40; + pub const IOCM_CTS = 0x20; + pub const IOCM_DSR = 0x100; + pub const IOCM_DTR = 0x2; + pub const IOCM_LE = 0x1; + pub const IOCM_RI = 0x80; + pub const IOCM_RNG = 0x80; + pub const IOCM_RTS = 0x4; + pub const IOCM_SR = 0x10; + pub const IOCM_ST = 0x8; + pub const IOCNOTTY = 0x20007471; + pub const IOCNXCL = 0x2000740e; + pub const IOCOUTQ = 0x40047473; + pub const IOCPKT = 0x80047470; + pub const IOCPKT_DATA = 0x0; + pub const IOCPKT_DOSTOP = 0x20; + pub const IOCPKT_FLUSHREAD = 0x1; + pub const IOCPKT_FLUSHWRITE = 0x2; + pub const IOCPKT_IOCTL = 0x40; + pub const IOCPKT_NOSTOP = 0x10; + pub const IOCPKT_START = 0x8; + pub const IOCPKT_STOP = 0x4; + pub const IOCPTMGET = 0x40287446; + pub const IOCPTSNAME = 0x40287448; + pub const IOCRCVFRAME = 0x80087445; + pub const IOCREMOTE = 0x80047469; + pub const IOCSBRK = 0x2000747b; + pub const IOCSCTTY = 0x20007461; + pub const IOCSDTR = 0x20007479; + pub const IOCSETA = 0x802c7414; + pub const IOCSETAF = 0x802c7416; + pub const IOCSETAW = 0x802c7415; + pub const IOCSETD = 0x8004741b; + pub const IOCSFLAGS = 0x8004745c; + pub const IOCSIG = 0x2000745f; + pub const IOCSLINED = 0x80207443; + pub const IOCSPGRP = 0x80047476; + pub const IOCSQSIZE = 0x80047480; + pub const IOCSSIZE = 0x80087467; + pub const IOCSTART = 0x2000746e; + pub const IOCSTAT = 0x80047465; + pub const IOCSTI = 0x80017472; + pub const IOCSTOP = 0x2000746f; + pub const IOCSWINSZ = 0x80087467; + pub const IOCUCNTL = 0x80047466; + pub const IOCXMTFRAME = 0x80087444; +}; pub fn WEXITSTATUS(s: u32) u8 { return @intCast(u8, (s >> 8) & 0xff); @@ -752,11 +702,51 @@ pub const winsize = extern struct { const NSIG = 33; -pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); -pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); -pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); -pub const SIG_CATCH = @intToPtr(?Sigaction.sigaction_fn, 2); -pub const SIG_HOLD = @intToPtr(?Sigaction.sigaction_fn, 3); +pub const SIG = struct { + pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); + pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); + pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); + pub const CATCH = @intToPtr(?Sigaction.sigaction_fn, 2); + pub const HOLD = @intToPtr(?Sigaction.sigaction_fn, 3); + + pub const HUP = 1; + pub const INT = 2; + pub const QUIT = 3; + pub const ILL = 4; + pub const TRAP = 5; + pub const ABRT = 6; + pub const IOT = ABRT; + pub const EMT = 7; + pub const FPE = 8; + pub const KILL = 9; + pub const BUS = 10; + pub const SEGV = 11; + pub const SYS = 12; + pub const PIPE = 13; + pub const ALRM = 14; + pub const TERM = 15; + pub const URG = 16; + pub const STOP = 17; + pub const TSTP = 18; + pub const CONT = 19; + pub const CHLD = 20; + pub const TTIN = 21; + pub const TTOU = 22; + pub const IO = 23; + pub const XCPU = 24; + pub const XFSZ = 25; + pub const VTALRM = 26; + pub const PROF = 27; + pub const WINCH = 28; + pub const INFO = 29; + pub const USR1 = 30; + pub const USR2 = 31; + pub const PWR = 32; + + pub const BLOCK = 1; + pub const UNBLOCK = 2; + pub const SETMASK = 3; +}; /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. pub const Sigaction = extern struct { @@ -1013,59 +1003,61 @@ pub const stack_t = extern struct { ss_flags: c_int, }; -pub const S_IFMT = 0o170000; - -pub const S_IFIFO = 0o010000; -pub const S_IFCHR = 0o020000; -pub const S_IFDIR = 0o040000; -pub const S_IFBLK = 0o060000; -pub const S_IFREG = 0o100000; -pub const S_IFLNK = 0o120000; -pub const S_IFSOCK = 0o140000; - -pub const S_ISUID = 0o4000; -pub const S_ISGID = 0o2000; -pub const S_ISVTX = 0o1000; -pub const S_IRWXU = 0o700; -pub const S_IRUSR = 0o400; -pub const S_IWUSR = 0o200; -pub const S_IXUSR = 0o100; -pub const S_IRWXG = 0o070; -pub const S_IRGRP = 0o040; -pub const S_IWGRP = 0o020; -pub const S_IXGRP = 0o010; -pub const S_IRWXO = 0o007; -pub const S_IROTH = 0o004; -pub const S_IWOTH = 0o002; -pub const S_IXOTH = 0o001; - -pub fn S_ISFIFO(m: u32) bool { - return m & S_IFMT == S_IFIFO; -} - -pub fn S_ISCHR(m: u32) bool { - return m & S_IFMT == S_IFCHR; -} - -pub fn S_ISDIR(m: u32) bool { - return m & S_IFMT == S_IFDIR; -} - -pub fn S_ISBLK(m: u32) bool { - return m & S_IFMT == S_IFBLK; -} - -pub fn S_ISREG(m: u32) bool { - return m & S_IFMT == S_IFREG; -} - -pub fn S_ISLNK(m: u32) bool { - return m & S_IFMT == S_IFLNK; -} - -pub fn S_ISSOCK(m: u32) bool { - return m & S_IFMT == S_IFSOCK; -} +pub const S = struct { + pub const IFMT = 0o170000; + + pub const IFIFO = 0o010000; + pub const IFCHR = 0o020000; + pub const IFDIR = 0o040000; + pub const IFBLK = 0o060000; + pub const IFREG = 0o100000; + pub const IFLNK = 0o120000; + pub const IFSOCK = 0o140000; + + pub const ISUID = 0o4000; + pub const ISGID = 0o2000; + pub const ISVTX = 0o1000; + pub const IRWXU = 0o700; + pub const IRUSR = 0o400; + pub const IWUSR = 0o200; + pub const IXUSR = 0o100; + pub const IRWXG = 0o070; + pub const IRGRP = 0o040; + pub const IWGRP = 0o020; + pub const IXGRP = 0o010; + pub const IRWXO = 0o007; + pub const IROTH = 0o004; + pub const IWOTH = 0o002; + pub const IXOTH = 0o001; + + pub fn ISFIFO(m: u32) bool { + return m & IFMT == IFIFO; + } + + pub fn ISCHR(m: u32) bool { + return m & IFMT == IFCHR; + } + + pub fn ISDIR(m: u32) bool { + return m & IFMT == IFDIR; + } + + pub fn ISBLK(m: u32) bool { + return m & IFMT == IFBLK; + } + + pub fn ISREG(m: u32) bool { + return m & IFMT == IFREG; + } + + pub fn ISLNK(m: u32) bool { + return m & IFMT == IFLNK; + } + + pub fn ISSOCK(m: u32) bool { + return m & IFMT == IFSOCK; + } +}; pub const AT = struct { /// Magic value that specify the use of the current working directory diff --git a/lib/std/c/wasi.zig b/lib/std/c/wasi.zig index 95eafd7fadf719aa0924fc301d224dae0e99063c..497f1213c8e961657c6db02acf58f4971c8f263e 100644 --- a/lib/std/c/wasi.zig +++ b/lib/std/c/wasi.zig @@ -17,6 +17,11 @@ pub const ino_t = wasi.ino_t; pub const mode_t = wasi.mode_t; pub const time_t = wasi.time_t; pub const timespec = wasi.timespec; +pub const STDERR_FILENO = wasi.STDERR_FILENO; +pub const STDIN_FILENO = wasi.STDIN_FILENO; +pub const STDOUT_FILENO = wasi.STDOUT_FILENO; +pub const E = wasi.E; +pub const CLOCK = wasi.CLOCK; pub const Stat = extern struct { dev: i32, diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 8402f42e6dbca84fd452f83ff1a428fa3908124b..8517703566a15545a6986db861075019f3df921d 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1470,7 +1470,7 @@ fn getDebugInfoAllocator() *mem.Allocator { pub const have_segfault_handling_support = switch (native_os) { .linux, .netbsd => true, .windows => true, - .freebsd, .openbsd => @hasDecl(os, "ucontext_t"), + .freebsd, .openbsd => @hasDecl(os.system, "ucontext_t"), else => false, }; pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler")) diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index ef19728ec90cd61bc9f3035bc4929b764d7582d6..21211c9af0026185ef4cb47cea9f87bad8a3288c 100644 --- a/lib/std/event/loop.zig +++ b/lib/std/event/loop.zig @@ -904,7 +904,7 @@ pub const Loop = struct { addr_size: *os.socklen_t, /// The following values can be bitwise ORed in flags to obtain different behavior: /// * `SOCK.CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. See the - /// description of the `O_CLOEXEC` flag in `open` for reasons why this may be useful. + /// description of the `O.CLOEXEC` flag in `open` for reasons why this may be useful. flags: u32, ) os.AcceptError!os.socket_t { while (true) { diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 1f063bb88adbbc3f0759708e8a66d4e2866b87ec..5c795e658fd33a1d40d36e85865403e0c08c031a 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -479,15 +479,15 @@ pub const Dir = struct { &stat_info, 0, ); - const statmode = stat_info.mode & os.S_IFMT; + const statmode = stat_info.mode & os.S.IFMT; const entry_kind = switch (statmode) { - os.S_IFDIR => Entry.Kind.Directory, - os.S_IFBLK => Entry.Kind.BlockDevice, - os.S_IFCHR => Entry.Kind.CharacterDevice, - os.S_IFLNK => Entry.Kind.SymLink, - os.S_IFREG => Entry.Kind.File, - os.S_IFIFO => Entry.Kind.NamedPipe, + os.S.IFDIR => Entry.Kind.Directory, + os.S.IFBLK => Entry.Kind.BlockDevice, + os.S.IFCHR => Entry.Kind.CharacterDevice, + os.S.IFLNK => Entry.Kind.SymLink, + os.S.IFREG => Entry.Kind.File, + os.S.IFIFO => Entry.Kind.NamedPipe, else => Entry.Kind.Unknown, }; @@ -678,12 +678,12 @@ pub const Dir = struct { } const entry_kind = switch (entry.d_type) { - w.FILETYPE_BLOCK_DEVICE => Entry.Kind.BlockDevice, - w.FILETYPE_CHARACTER_DEVICE => Entry.Kind.CharacterDevice, - w.FILETYPE_DIRECTORY => Entry.Kind.Directory, - w.FILETYPE_SYMBOLIC_LINK => Entry.Kind.SymLink, - w.FILETYPE_REGULAR_FILE => Entry.Kind.File, - w.FILETYPE_SOCKET_STREAM, wasi.FILETYPE_SOCKET_DGRAM => Entry.Kind.UnixDomainSocket, + .BLOCK_DEVICE => Entry.Kind.BlockDevice, + .CHARACTER_DEVICE => Entry.Kind.CharacterDevice, + .DIRECTORY => Entry.Kind.Directory, + .SYMBOLIC_LINK => Entry.Kind.SymLink, + .REGULAR_FILE => Entry.Kind.File, + .SOCKET_STREAM, .SOCKET_DGRAM => Entry.Kind.UnixDomainSocket, else => Entry.Kind.Unknown, }; return Entry{ @@ -909,11 +909,11 @@ pub const Dir = struct { } var os_flags: u32 = os.O.CLOEXEC; - // Use the O_ locking flags if the os supports them to acquire the lock + // Use the O locking flags if the os supports them to acquire the lock // atomically. const has_flock_open_flags = @hasDecl(os.O, "EXLOCK"); if (has_flock_open_flags) { - // Note that the O_NONBLOCK flag is removed after the openat() call + // Note that the O.NONBLOCK flag is removed after the openat() call // is successful. const nonblocking_lock_flag: u32 = if (flags.lock_nonblocking) os.O.NONBLOCK @@ -1071,10 +1071,10 @@ pub const Dir = struct { return self.createFileW(path_w.span(), flags); } - // Use the O_ locking flags if the os supports them to acquire the lock + // Use the O locking flags if the os supports them to acquire the lock // atomically. const has_flock_open_flags = @hasDecl(os.O, "EXLOCK"); - // Note that the O_NONBLOCK flag is removed after the openat() call + // Note that the O.NONBLOCK flag is removed after the openat() call // is successful. const nonblocking_lock_flag: u32 = if (has_flock_open_flags and flags.lock_nonblocking) os.O.NONBLOCK @@ -1427,9 +1427,9 @@ pub const Dir = struct { const result = os.openatWasi(self.fd, sub_path, symlink_flags, w.O.DIRECTORY, 0x0, base, inheriting); const fd = result catch |err| switch (err) { error.FileTooBig => unreachable, // can't happen for directories - error.IsDir => unreachable, // we're providing O_DIRECTORY - error.NoSpaceLeft => unreachable, // not providing O_CREAT - error.PathAlreadyExists => unreachable, // not providing O_CREAT + error.IsDir => unreachable, // we're providing O.DIRECTORY + error.NoSpaceLeft => unreachable, // not providing O.CREAT + error.PathAlreadyExists => unreachable, // not providing O.CREAT error.FileLocksNotSupported => unreachable, // locking folders is not supported error.WouldBlock => unreachable, // can't happen for directories else => |e| return e, @@ -1463,7 +1463,7 @@ pub const Dir = struct { return self.openDirAccessMaskW(sub_path_w, flags, args.no_follow); } - /// `flags` must contain `os.O_DIRECTORY`. + /// `flags` must contain `os.O.DIRECTORY`. fn openDirFlagsZ(self: Dir, sub_path_c: [*:0]const u8, flags: u32) OpenError!Dir { const result = if (need_async_thread) std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, flags, 0) @@ -1471,9 +1471,9 @@ pub const Dir = struct { os.openatZ(self.fd, sub_path_c, flags, 0); const fd = result catch |err| switch (err) { error.FileTooBig => unreachable, // can't happen for directories - error.IsDir => unreachable, // we're providing O_DIRECTORY - error.NoSpaceLeft => unreachable, // not providing O_CREAT - error.PathAlreadyExists => unreachable, // not providing O_CREAT + error.IsDir => unreachable, // we're providing O.DIRECTORY + error.NoSpaceLeft => unreachable, // not providing O.CREAT + error.PathAlreadyExists => unreachable, // not providing O.CREAT error.FileLocksNotSupported => unreachable, // locking folders is not supported error.WouldBlock => unreachable, // can't happen for directories else => |e| return e, @@ -1559,7 +1559,7 @@ pub const Dir = struct { .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd => { // Don't follow symlinks to match unlinkat (which acts on symlinks rather than follows them) const fstat = os.fstatatZ(self.fd, sub_path_c, os.AT.SYMLINK_NOFOLLOW) catch return e; - const is_dir = fstat.mode & os.S_IFMT == os.S_IFDIR; + const is_dir = fstat.mode & os.S.IFMT == os.S.IFDIR; return if (is_dir) error.IsDir else e; }, else => return e, diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index e37fa1d65565fe3854fa3ef44f27378e13a4f13f..d08b743919701fbcd87b3179a8fb657a0f5a5d24 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -106,7 +106,7 @@ pub const File = struct { /// and `false` means `error.WouldBlock` is handled by the event loop. lock_nonblocking: bool = false, - /// Setting this to `.blocking` prevents `O_NONBLOCK` from being passed even + /// Setting this to `.blocking` prevents `O.NONBLOCK` from being passed even /// if `std.io.is_async`. It allows the use of `nosuspend` when calling functions /// related to opening the file, reading, writing, and locking. intended_io_mode: io.ModeOverride = io.default_mode, @@ -167,7 +167,7 @@ pub const File = struct { /// be created with. mode: Mode = default_mode, - /// Setting this to `.blocking` prevents `O_NONBLOCK` from being passed even + /// Setting this to `.blocking` prevents `O.NONBLOCK` from being passed even /// if `std.io.is_async`. It allows the use of `nosuspend` when calling functions /// related to opening the file, reading, writing, and locking. intended_io_mode: io.ModeOverride = io.default_mode, @@ -325,12 +325,12 @@ pub const File = struct { .size = @bitCast(u64, st.size), .mode = st.mode, .kind = if (builtin.os.tag == .wasi and !builtin.link_libc) switch (st.filetype) { - os.FILETYPE_BLOCK_DEVICE => Kind.BlockDevice, - os.FILETYPE_CHARACTER_DEVICE => Kind.CharacterDevice, - os.FILETYPE_DIRECTORY => Kind.Directory, - os.FILETYPE_SYMBOLIC_LINK => Kind.SymLink, - os.FILETYPE_REGULAR_FILE => Kind.File, - os.FILETYPE_SOCKET_STREAM, os.FILETYPE_SOCKET_DGRAM => Kind.UnixDomainSocket, + .BLOCK_DEVICE => Kind.BlockDevice, + .CHARACTER_DEVICE => Kind.CharacterDevice, + .DIRECTORY => Kind.Directory, + .SYMBOLIC_LINK => Kind.SymLink, + .REGULAR_FILE => Kind.File, + .SOCKET_STREAM, .SOCKET_DGRAM => Kind.UnixDomainSocket, else => Kind.Unknown, } else switch (st.mode & os.S.IFMT) { os.S.IFBLK => Kind.BlockDevice, diff --git a/lib/std/fs/watch.zig b/lib/std/fs/watch.zig index 7777793b29bd0b4498cba7f01f93d44a1a16d985..117843bf95b03098bba37b6bc1614e05efd0073e 100644 --- a/lib/std/fs/watch.zig +++ b/lib/std/fs/watch.zig @@ -250,7 +250,7 @@ pub fn Watch(comptime V: type) type { }; // @TODO Can I close this fd and get an error from bsdWaitKev? - const flags = if (comptime std.Target.current.isDarwin()) os.O_SYMLINK | os.O_EVTONLY else 0; + const flags = if (comptime std.Target.current.isDarwin()) os.O.SYMLINK | os.O.EVTONLY else 0; const fd = try os.open(realpath, flags, 0); gop.value_ptr.putter_frame = async self.kqPutEvents(fd, gop.key_ptr.*, gop.value_ptr.*); return null; diff --git a/lib/std/os.zig b/lib/std/os.zig index c688eedec820cd859a42cd2562d0087f48580ceb..1de4bac6446b2daef60e3e59c129cdb474ac5ada 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -72,7 +72,6 @@ pub const E = system.E; pub const Elf_Symndx = system.Elf_Symndx; pub const F = system.F; pub const FD_CLOEXEC = system.FD_CLOEXEC; -pub const F_OK = system.F_OK; pub const Flock = system.Flock; pub const HOST_NAME_MAX = system.HOST_NAME_MAX; pub const IFNAMESIZE = system.IFNAMESIZE; @@ -96,7 +95,6 @@ pub const REG = system.REG; pub const RIGHT = system.RIGHT; pub const RLIM = system.RLIM; pub const RR = system.RR; -pub const R_OK = system.R_OK; pub const S = system.S; pub const SA = system.SA; pub const SC = system.SC; @@ -116,8 +114,6 @@ pub const Stat = system.Stat; pub const TCSA = system.TCSA; pub const VDSO = system.VDSO; pub const W = system.W; -pub const W_OK = system.W_OK; -pub const X_OK = system.X_OK; pub const addrinfo = system.addrinfo; pub const blkcnt_t = system.blkcnt_t; pub const blksize_t = system.blksize_t; @@ -165,6 +161,11 @@ pub const uid_t = system.uid_t; pub const user_desc = system.user_desc; pub const utsname = system.utsname; +pub const F_OK = system.F_OK; +pub const R_OK = system.R_OK; +pub const W_OK = system.W_OK; +pub const X_OK = system.X_OK; + pub const iovec = extern struct { iov_base: [*]u8, iov_len: usize, @@ -4237,7 +4238,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { } if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; - switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), wasi.WHENCE_SET, &new_offset)) { + switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), .SET, &new_offset)) { .SUCCESS => return, .BADF => unreachable, // always a race condition .INVAL => return error.Unseekable, @@ -4285,7 +4286,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void { } if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; - switch (wasi.fd_seek(fd, offset, wasi.WHENCE_CUR, &new_offset)) { + switch (wasi.fd_seek(fd, offset, .CUR, &new_offset)) { .SUCCESS => return, .BADF => unreachable, // always a race condition .INVAL => return error.Unseekable, @@ -4332,7 +4333,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void { } if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; - switch (wasi.fd_seek(fd, offset, wasi.WHENCE_END, &new_offset)) { + switch (wasi.fd_seek(fd, offset, .END, &new_offset)) { .SUCCESS => return, .BADF => unreachable, // always a race condition .INVAL => return error.Unseekable, @@ -4379,7 +4380,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 { } if (builtin.os.tag == .wasi and !builtin.link_libc) { var new_offset: wasi.filesize_t = undefined; - switch (wasi.fd_seek(fd, 0, wasi.WHENCE_CUR, &new_offset)) { + switch (wasi.fd_seek(fd, 0, .CUR, &new_offset)) { .SUCCESS => return new_offset, .BADF => unreachable, // always a race condition .INVAL => return error.Unseekable, diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index ecfded41935abf0a37bc2f613bae2eae9bbf5690..33d640a9585d1c7e6047f99774b29678507744a8 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -57,24 +57,23 @@ pub const socketcall = syscall_bits.socketcall; pub const syscall_pipe = syscall_bits.syscall_pipe; pub const syscall_fork = syscall_bits.syscall_fork; -pub const clone = arch_bits.clone; pub const ARCH = arch_bits.ARCH; pub const Elf_Symndx = arch_bits.Elf_Symndx; pub const F = arch_bits.F; pub const Flock = arch_bits.Flock; +pub const HWCAP = arch_bits.HWCAP; pub const LOCK = arch_bits.LOCK; -pub const MAP = arch_bits.MAP; pub const MMAP2_UNIT = arch_bits.MMAP2_UNIT; -pub const O = arch_bits.O; pub const REG = arch_bits.REG; pub const SC = arch_bits.SC; pub const SYS = arch_bits.SYS; +pub const Stat = arch_bits.Stat; pub const VDSO = arch_bits.VDSO; pub const blkcnt_t = arch_bits.blkcnt_t; pub const blksize_t = arch_bits.blksize_t; +pub const clone = arch_bits.clone; pub const dev_t = arch_bits.dev_t; pub const ino_t = arch_bits.ino_t; -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; @@ -92,29 +91,46 @@ pub const tls = @import("linux/tls.zig"); pub const pie = @import("linux/start_pie.zig"); pub const BPF = @import("linux/bpf.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; +pub const MAP = struct { + pub usingnamespace arch_bits.MAP; + + /// Share changes + pub const SHARED = 0x01; + /// Changes are private + pub const PRIVATE = 0x02; + /// share + validate extension flags + pub const SHARED_VALIDATE = 0x03; + /// Mask for type of mapping + pub const TYPE = 0x0f; + /// Interpret addr exactly + pub const FIXED = 0x10; + /// don't use a file + pub const ANONYMOUS = 0x20; + /// populate (prefault) pagetables + pub const POPULATE = 0x8000; + /// do not block on IO + pub const NONBLOCK = 0x10000; + /// give out an address that is best suited for process/thread stacks + pub const STACK = 0x20000; + /// create a huge page mapping + pub const HUGETLB = 0x40000; + /// perform synchronous page faults for the mapping + pub const SYNC = 0x80000; + /// FIXED which doesn't unmap underlying mapping + pub const FIXED_NOREPLACE = 0x100000; + /// For anonymous mmap, memory could be uninitialized + pub const UNINITIALIZED = 0x4000000; +}; + +pub const O = struct { + pub usingnamespace arch_bits.O; + + pub const RDONLY = 0o0; + pub const WRONLY = 0o1; + pub const RDWR = 0o2; +}; + +pub usingnamespace @import("linux/io_uring.zig"); /// Set by startup code, used by `getauxval`. pub var elf_aux_maybe: ?[*]std.elf.Auxv = null; @@ -1725,26 +1741,20 @@ pub const FUTEX = struct { pub const PROT = struct { /// page can not be accessed pub const NONE = 0x0; - /// page can be read pub const READ = 0x1; - /// page can be written pub const WRITE = 0x2; - /// page can be executed pub const EXEC = 0x4; - /// page may be used for atomic ops pub const SEM = switch (native_arch) { // TODO: also xtensa .mips, .mipsel, .mips64, .mips64el => 0x10, else => 0x8, }; - /// mprotect flag: extend change to start of growsdown vma pub const GROWSDOWN = 0x01000000; - /// mprotect flag: extend change to end of growsup vma pub const GROWSUP = 0x02000000; }; @@ -1960,16 +1970,16 @@ pub const RWF = struct { /// high priority request, poll if possible pub const HIPRI: kernel_rwf = 0x00000001; - /// per-IO O_DSYNC + /// per-IO O.DSYNC pub const DSYNC: kernel_rwf = 0x00000002; - /// per-IO O_SYNC + /// per-IO O.SYNC pub const SYNC: kernel_rwf = 0x00000004; /// per-IO, return -EAGAIN if operation would block pub const NOWAIT: kernel_rwf = 0x00000008; - /// per-IO O_APPEND + /// per-IO O.APPEND pub const APPEND: kernel_rwf = 0x00000010; }; diff --git a/lib/std/os/linux/arm-eabi.zig b/lib/std/os/linux/arm-eabi.zig index 700761fe355a216b7af4174f3929c9d0b02fb430..7727e2ff2f1bf8401b0c4eba2c92b643ef5783db 100644 --- a/lib/std/os/linux/arm-eabi.zig +++ b/lib/std/os/linux/arm-eabi.zig @@ -532,26 +532,28 @@ pub const SYS = enum(usize) { pub const MMAP2_UNIT = 4096; -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 = 0o40000; -pub const O_NOFOLLOW = 0o100000; -pub const O_CLOEXEC = 0o2000000; +pub const O = struct { + pub const CREAT = 0o100; + pub const EXCL = 0o200; + pub const NOCTTY = 0o400; + pub const TRUNC = 0o1000; + pub const APPEND = 0o2000; + pub const NONBLOCK = 0o4000; + pub const DSYNC = 0o10000; + pub const SYNC = 0o4010000; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0o40000; + pub const NOFOLLOW = 0o100000; + pub const CLOEXEC = 0o2000000; -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o200000; -pub const O_LARGEFILE = 0o400000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20040000; -pub const O_NDELAY = O_NONBLOCK; + pub const ASYNC = 0o20000; + pub const DIRECT = 0o200000; + pub const LARGEFILE = 0o400000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20040000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -597,35 +599,38 @@ pub const MAP = struct { pub const LOCKED = 0x2000; /// don't check for reservations pub const NORESERVE = 0x4000; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; -pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6"; -pub const HWCAP_SWP = 1 << 0; -pub const HWCAP_HALF = 1 << 1; -pub const HWCAP_THUMB = 1 << 2; -pub const HWCAP_26BIT = 1 << 3; -pub const HWCAP_FAST_MULT = 1 << 4; -pub const HWCAP_FPA = 1 << 5; -pub const HWCAP_VFP = 1 << 6; -pub const HWCAP_EDSP = 1 << 7; -pub const HWCAP_JAVA = 1 << 8; -pub const HWCAP_IWMMXT = 1 << 9; -pub const HWCAP_CRUNCH = 1 << 10; -pub const HWCAP_THUMBEE = 1 << 11; -pub const HWCAP_NEON = 1 << 12; -pub const HWCAP_VFPv3 = 1 << 13; -pub const HWCAP_VFPv3D16 = 1 << 14; -pub const HWCAP_TLS = 1 << 15; -pub const HWCAP_VFPv4 = 1 << 16; -pub const HWCAP_IDIVA = 1 << 17; -pub const HWCAP_IDIVT = 1 << 18; -pub const HWCAP_VFPD32 = 1 << 19; -pub const HWCAP_IDIV = HWCAP_IDIVA | HWCAP_IDIVT; -pub const HWCAP_LPAE = 1 << 20; -pub const HWCAP_EVTSTRM = 1 << 21; +pub const VDSO = struct { + pub const CGT_SYM = "__vdso_clock_gettime"; + pub const CGT_VER = "LINUX_2.6"; +}; + +pub const HWCAP = struct { + pub const SWP = 1 << 0; + pub const HALF = 1 << 1; + pub const THUMB = 1 << 2; + pub const @"26BIT" = 1 << 3; + pub const FAST_MULT = 1 << 4; + pub const FPA = 1 << 5; + pub const VFP = 1 << 6; + pub const EDSP = 1 << 7; + pub const JAVA = 1 << 8; + pub const IWMMXT = 1 << 9; + pub const CRUNCH = 1 << 10; + pub const THUMBEE = 1 << 11; + pub const NEON = 1 << 12; + pub const VFPv3 = 1 << 13; + pub const VFPv3D16 = 1 << 14; + pub const TLS = 1 << 15; + pub const VFPv4 = 1 << 16; + pub const IDIVA = 1 << 17; + pub const IDIVT = 1 << 18; + pub const VFPD32 = 1 << 19; + pub const IDIV = IDIVA | IDIVT; + pub const LPAE = 1 << 20; + pub const EVTSTRM = 1 << 21; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/arm64.zig b/lib/std/os/linux/arm64.zig index 13321f45959365ebe1b1e79b573ab70c997c98de..7f0c2c12c5e3125520de8bf82c6437f1c9bff97d 100644 --- a/lib/std/os/linux/arm64.zig +++ b/lib/std/os/linux/arm64.zig @@ -410,26 +410,28 @@ pub const SYS = enum(usize) { _, }; -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 = 0o40000; -pub const O_NOFOLLOW = 0o100000; -pub const O_CLOEXEC = 0o2000000; +pub const O = struct { + pub const CREAT = 0o100; + pub const EXCL = 0o200; + pub const NOCTTY = 0o400; + pub const TRUNC = 0o1000; + pub const APPEND = 0o2000; + pub const NONBLOCK = 0o4000; + pub const DSYNC = 0o10000; + pub const SYNC = 0o4010000; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0o40000; + pub const NOFOLLOW = 0o100000; + pub const CLOEXEC = 0o2000000; -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o200000; -pub const O_LARGEFILE = 0o400000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20040000; -pub const O_NDELAY = O_NONBLOCK; + pub const ASYNC = 0o20000; + pub const DIRECT = 0o200000; + pub const LARGEFILE = 0o400000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20040000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -475,11 +477,12 @@ pub const MAP = struct { pub const LOCKED = 0x2000; /// don't check for reservations pub const NORESERVE = 0x4000; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; -pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6.39"; + +pub const VDSO = struct { + pub const CGT_SYM = "__kernel_clock_gettime"; + pub const CGT_VER = "LINUX_2.6.39"; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/i386.zig b/lib/std/os/linux/i386.zig index 8efe21a8e4485a7d88aa656a64f24ae63fa63cbd..eaa803768dd9c95e6f8026580eff33085193fa0e 100644 --- a/lib/std/os/linux/i386.zig +++ b/lib/std/os/linux/i386.zig @@ -572,10 +572,6 @@ pub const SYS = enum(usize) { }; pub const O = struct { - pub const RDONLY = 0o0; - pub const WRONLY = 0o1; - pub const RDWR = 0o2; - pub const CREAT = 0o100; pub const EXCL = 0o200; pub const NOCTTY = 0o400; @@ -628,42 +624,12 @@ pub const LOCK = struct { }; pub const MAP = struct { - /// Share changes - pub const SHARED = 0x01; - /// Changes are private - pub const PRIVATE = 0x02; - /// share + validate extension flags - pub const SHARED_VALIDATE = 0x03; - /// Mask for type of mapping - pub const TYPE = 0x0f; - /// Interpret addr exactly - pub const FIXED = 0x10; - /// don't use a file - pub const ANONYMOUS = 0x20; - /// populate (prefault) pagetables - pub const POPULATE = 0x8000; - /// do not block on IO - pub const NONBLOCK = 0x10000; - /// give out an address that is best suited for process/thread stacks - pub const STACK = 0x20000; - /// create a huge page mapping - pub const HUGETLB = 0x40000; - /// perform synchronous page faults for the mapping - pub const SYNC = 0x80000; - /// FIXED which doesn't unmap underlying mapping - pub const FIXED_NOREPLACE = 0x100000; - /// For anonymous mmap, memory could be uninitialized - pub const UNINITIALIZED = 0x4000000; - pub const NORESERVE = 0x4000; pub const GROWSDOWN = 0x0100; pub const DENYWRITE = 0x0800; pub const EXECUTABLE = 0x1000; pub const LOCKED = 0x2000; pub const @"32BIT" = 0x40; - - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; pub const MMAP2_UNIT = 4096; diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index bba9786a90461872029d7783d1dddbc4601c1cc9..716137f43beb6b3f42524fa9db12c33213832cb6 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -539,7 +539,7 @@ pub const IO_Uring = struct { pub fn timeout( self: *IO_Uring, user_data: u64, - ts: *const os.__kernel_timespec, + ts: *const os.linux.timespec, count: u32, flags: u32, ) !*io_uring_sqe { @@ -979,7 +979,7 @@ pub fn io_uring_prep_close(sqe: *io_uring_sqe, fd: os.fd_t) void { pub fn io_uring_prep_timeout( sqe: *io_uring_sqe, - ts: *const os.__kernel_timespec, + ts: *const os.linux.timespec, count: u32, flags: u32, ) void { @@ -1136,7 +1136,7 @@ test "readv" { }; defer ring.deinit(); - const fd = try os.openZ("/dev/zero", os.O_RDONLY | os.O_CLOEXEC, 0); + const fd = try os.openZ("/dev/zero", os.O.RDONLY | os.O.CLOEXEC, 0); defer os.close(fd); // Linux Kernel 5.4 supports IORING_REGISTER_FILES but not sparse fd sets (i.e. an fd of -1). @@ -1295,7 +1295,7 @@ test "openat" { const path = "test_io_uring_openat"; defer std.fs.cwd().deleteFile(path) catch {}; - const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT; + const flags: u32 = os.O.CLOEXEC | os.O.RDWR | os.O.CREAT; const mode: os.mode_t = 0o666; const sqe_openat = try ring.openat(0x33333333, linux.AT.FDCWD, path, flags, mode); try testing.expectEqual(io_uring_sqe{ @@ -1450,7 +1450,7 @@ test "timeout (after a relative time)" { const ms = 10; const margin = 5; - const ts = os.__kernel_timespec{ .tv_sec = 0, .tv_nsec = ms * 1000000 }; + const ts = os.linux.timespec{ .tv_sec = 0, .tv_nsec = ms * 1000000 }; const started = std.time.milliTimestamp(); const sqe = try ring.timeout(0x55555555, &ts, 0, 0); @@ -1479,7 +1479,7 @@ test "timeout (after a number of completions)" { }; defer ring.deinit(); - const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 }; + const ts = os.linux.timespec{ .tv_sec = 3, .tv_nsec = 0 }; const count_completions: u64 = 1; const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0); try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode); @@ -1512,7 +1512,7 @@ test "timeout_remove" { }; defer ring.deinit(); - const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 }; + const ts = os.linux.timespec{ .tv_sec = 3, .tv_nsec = 0 }; const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0); try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode); try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data); diff --git a/lib/std/os/linux/mips.zig b/lib/std/os/linux/mips.zig index f4bdef609daf07e7c35d3389b10c3aa8559a054b..427a1aa6c60ced3190869c4ccd80598ba77bf2c8 100644 --- a/lib/std/os/linux/mips.zig +++ b/lib/std/os/linux/mips.zig @@ -629,26 +629,28 @@ pub const SYS = enum(usize) { _, }; -pub const O_CREAT = 0o0400; -pub const O_EXCL = 0o02000; -pub const O_NOCTTY = 0o04000; -pub const O_TRUNC = 0o01000; -pub const O_APPEND = 0o0010; -pub const O_NONBLOCK = 0o0200; -pub const O_DSYNC = 0o0020; -pub const O_SYNC = 0o040020; -pub const O_RSYNC = 0o040020; -pub const O_DIRECTORY = 0o0200000; -pub const O_NOFOLLOW = 0o0400000; -pub const O_CLOEXEC = 0o02000000; +pub const O = struct { + pub const CREAT = 0o0400; + pub const EXCL = 0o02000; + pub const NOCTTY = 0o04000; + pub const TRUNC = 0o01000; + pub const APPEND = 0o0010; + pub const NONBLOCK = 0o0200; + pub const DSYNC = 0o0020; + pub const SYNC = 0o040020; + pub const RSYNC = 0o040020; + pub const DIRECTORY = 0o0200000; + pub const NOFOLLOW = 0o0400000; + pub const CLOEXEC = 0o02000000; -pub const O_ASYNC = 0o010000; -pub const O_DIRECT = 0o0100000; -pub const O_LARGEFILE = 0o020000; -pub const O_NOATIME = 0o01000000; -pub const O_PATH = 0o010000000; -pub const O_TMPFILE = 0o020200000; -pub const O_NDELAY = O_NONBLOCK; + pub const ASYNC = 0o010000; + pub const DIRECT = 0o0100000; + pub const LARGEFILE = 0o020000; + pub const NOATIME = 0o01000000; + pub const PATH = 0o010000000; + pub const TMPFILE = 0o020200000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -692,8 +694,6 @@ pub const MAP = struct { pub const EXECUTABLE = 0x4000; pub const LOCKED = 0x8000; pub const @"32BIT" = 0x40; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; pub const SO = struct { @@ -726,8 +726,10 @@ pub const SO = struct { pub const RCVBUFFORCE = 33; }; -pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6.39"; +pub const VDSO = struct { + pub const CGT_SYM = "__kernel_clock_gettime"; + pub const CGT_VER = "LINUX_2.6.39"; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/powerpc.zig b/lib/std/os/linux/powerpc.zig index e0c1d32390216d797a385e0fdaa7925010ae4576..e2473055d6cf056e02bba5445d04c52cce645305 100644 --- a/lib/std/os/linux/powerpc.zig +++ b/lib/std/os/linux/powerpc.zig @@ -562,26 +562,28 @@ pub const SYS = enum(usize) { process_madvise = 440, }; -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 = 0o40000; -pub const O_NOFOLLOW = 0o100000; -pub const O_CLOEXEC = 0o2000000; +pub const O = struct { + pub const CREAT = 0o100; + pub const EXCL = 0o200; + pub const NOCTTY = 0o400; + pub const TRUNC = 0o1000; + pub const APPEND = 0o2000; + pub const NONBLOCK = 0o4000; + pub const DSYNC = 0o10000; + pub const SYNC = 0o4010000; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0o40000; + pub const NOFOLLOW = 0o100000; + pub const CLOEXEC = 0o2000000; -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o400000; -pub const O_LARGEFILE = 0o200000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20040000; -pub const O_NDELAY = O_NONBLOCK; + pub const ASYNC = 0o20000; + pub const DIRECT = 0o400000; + pub const LARGEFILE = 0o200000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20040000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -627,11 +629,12 @@ pub const MAP = struct { pub const LOCKED = 0x0080; /// don't check for reservations pub const NORESERVE = 0x0040; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; -pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6.15"; + +pub const VDSO = struct { + pub const CGT_SYM = "__kernel_clock_gettime"; + pub const CGT_VER = "LINUX_2.6.15"; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/powerpc64.zig b/lib/std/os/linux/powerpc64.zig index 62586eb0f771f7d60bb73d3709e21bd2e4c8f991..63c4e6a2d93df983a71add5ac60a82938de8ee70 100644 --- a/lib/std/os/linux/powerpc64.zig +++ b/lib/std/os/linux/powerpc64.zig @@ -537,26 +537,28 @@ pub const SYS = enum(usize) { _, }; -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 = 0o40000; -pub const O_NOFOLLOW = 0o100000; -pub const O_CLOEXEC = 0o2000000; +pub const O = struct { + pub const CREAT = 0o100; + pub const EXCL = 0o200; + pub const NOCTTY = 0o400; + pub const TRUNC = 0o1000; + pub const APPEND = 0o2000; + pub const NONBLOCK = 0o4000; + pub const DSYNC = 0o10000; + pub const SYNC = 0o4010000; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0o40000; + pub const NOFOLLOW = 0o100000; + pub const CLOEXEC = 0o2000000; -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o400000; -pub const O_LARGEFILE = 0o200000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20200000; -pub const O_NDELAY = O_NONBLOCK; + pub const ASYNC = 0o20000; + pub const DIRECT = 0o400000; + pub const LARGEFILE = 0o200000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20200000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -602,12 +604,12 @@ pub const MAP = struct { pub const LOCKED = 0x0080; /// don't check for reservations pub const NORESERVE = 0x0040; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; -pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6.15"; +pub const VDSO = struct { + pub const CGT_SYM = "__kernel_clock_gettime"; + pub const CGT_VER = "LINUX_2.6.15"; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig index 0dd947506acec0660669839b559e97814ca187e4..424e6bc3de8cad6fafa92d41e076ab4d1f836976 100644 --- a/lib/std/os/linux/riscv64.zig +++ b/lib/std/os/linux/riscv64.zig @@ -406,26 +406,28 @@ pub const SYS = enum(usize) { _, }; -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 = struct { + pub const CREAT = 0o100; + pub const EXCL = 0o200; + pub const NOCTTY = 0o400; + pub const TRUNC = 0o1000; + pub const APPEND = 0o2000; + pub const NONBLOCK = 0o4000; + pub const DSYNC = 0o10000; + pub const SYNC = 0o4010000; + pub const RSYNC = 0o4010000; + pub const DIRECTORY = 0o200000; + pub const NOFOLLOW = 0o400000; + pub const CLOEXEC = 0o2000000; -pub const O_ASYNC = 0o20000; -pub const O_DIRECT = 0o40000; -pub const O_LARGEFILE = 0o100000; -pub const O_NOATIME = 0o1000000; -pub const O_PATH = 0o10000000; -pub const O_TMPFILE = 0o20200000; -pub const O_NDELAY = O_NONBLOCK; + pub const ASYNC = 0o20000; + pub const DIRECT = 0o40000; + pub const LARGEFILE = 0o100000; + pub const NOATIME = 0o1000000; + pub const PATH = 0o10000000; + pub const TMPFILE = 0o20200000; + pub const NDELAY = NONBLOCK; +}; pub const F = struct { pub const DUPFD = 0; @@ -518,3 +520,6 @@ pub const Stat = extern struct { }; pub const Elf_Symndx = u32; + +pub const VDSO = struct {}; +pub const MAP = struct {}; diff --git a/lib/std/os/linux/sparc64.zig b/lib/std/os/linux/sparc64.zig index aa50b8364bbf8c38a429a786c2a14d4a3f65e344..e3e32b659b4fc8e22d4d419d979624aa4a08943f 100644 --- a/lib/std/os/linux/sparc64.zig +++ b/lib/std/os/linux/sparc64.zig @@ -571,26 +571,28 @@ pub const SYS = enum(usize) { _, }; -pub const O_CREAT = 0x200; -pub const O_EXCL = 0x800; -pub const O_NOCTTY = 0x8000; -pub const O_TRUNC = 0x400; -pub const O_APPEND = 0x8; -pub const O_NONBLOCK = 0x4000; -pub const O_SYNC = 0x802000; -pub const O_DSYNC = 0x2000; -pub const O_RSYNC = O_SYNC; -pub const O_DIRECTORY = 0x10000; -pub const O_NOFOLLOW = 0x20000; -pub const O_CLOEXEC = 0x400000; +pub const O = struct { + pub const CREAT = 0x200; + pub const EXCL = 0x800; + pub const NOCTTY = 0x8000; + pub const TRUNC = 0x400; + pub const APPEND = 0x8; + pub const NONBLOCK = 0x4000; + pub const SYNC = 0x802000; + pub const DSYNC = 0x2000; + pub const RSYNC = SYNC; + pub const DIRECTORY = 0x10000; + pub const NOFOLLOW = 0x20000; + pub const CLOEXEC = 0x400000; -pub const O_ASYNC = 0x40; -pub const O_DIRECT = 0x100000; -pub const O_LARGEFILE = 0; -pub const O_NOATIME = 0x200000; -pub const O_PATH = 0x1000000; -pub const O_TMPFILE = 0x2010000; -pub const O_NDELAY = O_NONBLOCK | 0x4; + pub const ASYNC = 0x40; + pub const DIRECT = 0x100000; + pub const LARGEFILE = 0; + pub const NOATIME = 0x200000; + pub const PATH = 0x1000000; + pub const TMPFILE = 0x2010000; + pub const NDELAY = NONBLOCK | 0x4; +}; pub const F = struct { pub const DUPFD = 0; @@ -633,11 +635,12 @@ pub const MAP = struct { pub const LOCKED = 0x0100; /// don't check for reservations pub const NORESERVE = 0x0040; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; -pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; -pub const VDSO_CGT_VER = "LINUX_2.6"; + +pub const VDSO = struct { + pub const CGT_SYM = "__vdso_clock_gettime"; + pub const CGT_VER = "LINUX_2.6"; +}; pub const Flock = extern struct { l_type: i16, diff --git a/lib/std/os/linux/x86_64.zig b/lib/std/os/linux/x86_64.zig index 3f4106aa35bb30c0872059ef7cea84aeb63c90c9..1a50fb14c6c8d30e470090ac022ee268ec197ec7 100644 --- a/lib/std/os/linux/x86_64.zig +++ b/lib/std/os/linux/x86_64.zig @@ -476,10 +476,6 @@ pub const SYS = enum(usize) { }; pub const O = struct { - pub const RDONLY = 0o0; - pub const WRONLY = 0o1; - pub const RDWR = 0o2; - pub const CREAT = 0o100; pub const EXCL = 0o200; pub const NOCTTY = 0o400; @@ -526,32 +522,6 @@ pub const F = struct { }; pub const MAP = struct { - /// Share changes - pub const SHARED = 0x01; - /// Changes are private - pub const PRIVATE = 0x02; - /// share + validate extension flags - pub const SHARED_VALIDATE = 0x03; - /// Mask for type of mapping - pub const TYPE = 0x0f; - /// Interpret addr exactly - pub const FIXED = 0x10; - /// don't use a file - pub const ANONYMOUS = 0x20; - /// populate (prefault) pagetables - pub const POPULATE = 0x8000; - /// do not block on IO - pub const NONBLOCK = 0x10000; - /// give out an address that is best suited for process/thread stacks - pub const STACK = 0x20000; - /// create a huge page mapping - pub const HUGETLB = 0x40000; - /// perform synchronous page faults for the mapping - pub const SYNC = 0x80000; - /// FIXED which doesn't unmap underlying mapping - pub const FIXED_NOREPLACE = 0x100000; - /// For anonymous mmap, memory could be uninitialized - pub const UNINITIALIZED = 0x4000000; /// only give out 32bit addresses pub const @"32BIT" = 0x40; /// stack-like segment @@ -564,8 +534,6 @@ pub const MAP = struct { pub const LOCKED = 0x2000; /// don't check for reservations pub const NORESERVE = 0x4000; - /// Only used by libc to communicate failure. - pub const FAILED = @intToPtr(*c_void, maxInt(usize)); }; pub const VDSO = struct { diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 3face414adfd5a1321d355aeff365e87cd48faae..21a02a8c8f5bfed50c0b3d185f18f969095d43af 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -401,7 +401,7 @@ test "sigaltstack" { // If the type is not available use void to avoid erroring out when `iter_fn` is // analyzed -const dl_phdr_info = if (@hasDecl(os, "dl_phdr_info")) os.dl_phdr_info else c_void; +const dl_phdr_info = if (@hasDecl(os.system, "dl_phdr_info")) os.dl_phdr_info else c_void; const IterFnError = error{ MissingPtLoadSegment, @@ -676,7 +676,7 @@ test "fsync" { } test "getrlimit and setrlimit" { - if (native_os == .windows) { + if (!@hasDecl(os.system, "rlimit")) { return error.SkipZigTest; } diff --git a/lib/std/os/wasi.zig b/lib/std/os/wasi.zig index 07f56a191305fbef9b18a027a7137ccce0f53ce5..7cd0206402c4b59b42129a2744963c59ff453f55 100644 --- a/lib/std/os/wasi.zig +++ b/lib/std/os/wasi.zig @@ -337,6 +337,7 @@ pub const filestat_t = extern struct { } }; +/// Also known as `FILETYPE`. pub const filetype_t = enum(u8) { UNKNOWN, BLOCK_DEVICE, @@ -532,6 +533,7 @@ pub const timestamp_t = u64; pub const userdata_t = u64; +/// Also known as `WHENCE`. pub const whence_t = enum(u8) { SET, CUR, END }; pub const S = struct { diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 9fe4329ccc7f0cddb9b3d32a71e255e68a6e83da..3b1394202fc97ea6401fd6f45f2099456344bae5 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -3192,7 +3192,7 @@ pub usingnamespace switch (native_arch) { pub const EXCEPTION_POINTERS = extern struct { ExceptionRecord: *EXCEPTION_RECORD, - ContextRecord: *@This().CONTEXT, + ContextRecord: *std.os.windows.CONTEXT, }; pub const VECTORED_EXCEPTION_HANDLER = fn (ExceptionInfo: *EXCEPTION_POINTERS) callconv(WINAPI) c_long; diff --git a/lib/std/special/ssp.zig b/lib/std/special/ssp.zig index 7bc5cef8139637f84b5c13a732f8894b977c7770..94a66768388d5c23c9cfc1cb91b3fd613aa84ed4 100644 --- a/lib/std/special/ssp.zig +++ b/lib/std/special/ssp.zig @@ -25,9 +25,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn _ = msg; _ = error_return_trace; @setCold(true); - if (@hasDecl(std.os, "abort")) - std.os.abort(); - while (true) {} + std.os.abort(); } export fn __stack_chk_fail() callconv(.C) noreturn { diff --git a/lib/std/start.zig b/lib/std/start.zig index f16a5aba1e8392dd081093d830ccd3c38fafc666..ac592e26edc119926966aaed9f0f7bd88fd4e784 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -345,7 +345,7 @@ fn posixCallMainAndExit() noreturn { // FIXME: Elide the check for targets >= ARMv7 when the target feature API // becomes less verbose (and more usable). if (comptime native_arch.isARM()) { - if (at_hwcap & std.os.linux.HWCAP_TLS == 0) { + if (at_hwcap & std.os.linux.HWCAP.TLS == 0) { // FIXME: Make __aeabi_read_tp call the kernel helper kuser_get_tls // For the time being use a simple abort instead of a @panic call to // keep the binary bloat under control. diff --git a/lib/std/x/net/tcp.zig b/lib/std/x/net/tcp.zig index 740c2d434aef50292d4203d3a28a77d137e53307..4fbd07e00c8e8b695725794763c01ade194e3dae 100644 --- a/lib/std/x/net/tcp.zig +++ b/lib/std/x/net/tcp.zig @@ -193,7 +193,7 @@ pub const Client = struct { /// Disable Nagle's algorithm on a TCP socket. It returns `error.UnsupportedSocketOption` if /// the host does not support sockets disabling Nagle's algorithm. pub fn setNoDelay(self: Client, enabled: bool) !void { - if (comptime @hasDecl(os, "TCP_NODELAY")) { + if (@hasDecl(os.TCP, "NODELAY")) { const bytes = mem.asBytes(&@as(usize, @boolToInt(enabled))); return self.socket.setOption(os.IPPROTO.TCP, os.TCP_NODELAY, bytes); } @@ -203,7 +203,7 @@ pub const Client = struct { /// Enables TCP Quick ACK on a TCP socket to immediately send rather than delay ACKs when necessary. It returns /// `error.UnsupportedSocketOption` if the host does not support TCP Quick ACK. pub fn setQuickACK(self: Client, enabled: bool) !void { - if (comptime @hasDecl(os, "TCP_QUICKACK")) { + if (@hasDecl(os.TCP, "QUICKACK")) { return self.socket.setOption(os.IPPROTO.TCP, os.TCP_QUICKACK, mem.asBytes(&@as(u32, @boolToInt(enabled)))); } return error.UnsupportedSocketOption; @@ -304,7 +304,7 @@ pub const Listener = struct { /// Enables TCP Fast Open (RFC 7413) on a TCP socket. It returns `error.UnsupportedSocketOption` if the host does not /// support TCP Fast Open. pub fn setFastOpen(self: Listener, enabled: bool) !void { - if (comptime @hasDecl(os, "TCP_FASTOPEN")) { + if (@hasDecl(os.TCP, "FASTOPEN")) { return self.socket.setOption(os.IPPROTO.TCP, os.TCP_FASTOPEN, mem.asBytes(&@as(u32, @boolToInt(enabled)))); } return error.UnsupportedSocketOption; diff --git a/lib/std/x/os/net.zig b/lib/std/x/os/net.zig index 6a5b12dab641cd674b99474523b424d97613bada..08ecede3e5c193a73f1b9d4d4755fb24ebc570dd 100644 --- a/lib/std/x/os/net.zig +++ b/lib/std/x/os/net.zig @@ -6,12 +6,13 @@ const mem = std.mem; const math = std.math; const testing = std.testing; const native_os = std.Target.current.os; +const have_ifnamesize = @hasDecl(os.system, "IFNAMESIZE"); /// Resolves a network interface name into a scope/zone ID. It returns /// an error if either resolution fails, or if the interface name is /// too long. pub fn resolveScopeID(name: []const u8) !u32 { - if (@hasDecl(os, "IFNAMESIZE")) { + if (have_ifnamesize) { if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong; if (native_os.tag == .windows) { @@ -556,7 +557,7 @@ test "ipv6: parse & format" { } test "ipv6: parse & format addresses with scope ids" { - if (!@hasDecl(os, "IFNAMESIZE")) return error.SkipZigTest; + if (!have_ifnamesize) return error.SkipZigTest; const inputs = [_][]const u8{ "FF01::FB%lo", diff --git a/test/behavior/usingnamespace/a.zig b/test/behavior/usingnamespace/a.zig new file mode 100644 index 0000000000000000000000000000000000000000..21d4278e15eeca5021022c8b2a74de65c028f3d1 --- /dev/null +++ b/test/behavior/usingnamespace/a.zig @@ -0,0 +1,7 @@ +usingnamespace @import("b.zig"); + +pub const a_text = "OK\n"; + +pub fn ok() bool { + return @import("std").mem.eql(u8, @This().b_text, "OK\n"); +} diff --git a/test/behavior/usingnamespace/b.zig b/test/behavior/usingnamespace/b.zig new file mode 100644 index 0000000000000000000000000000000000000000..08dafa3c50159fee9df2d533b139eb8a466a6300 --- /dev/null +++ b/test/behavior/usingnamespace/b.zig @@ -0,0 +1,3 @@ +usingnamespace @import("a.zig"); + +pub const b_text = @This().a_text; diff --git a/test/behavior/usingnamespace/bar.zig b/test/behavior/usingnamespace/bar.zig new file mode 100644 index 0000000000000000000000000000000000000000..faa3f27dbe92deae30ebe2d194c278aeda965e62 --- /dev/null +++ b/test/behavior/usingnamespace/bar.zig @@ -0,0 +1,8 @@ +usingnamespace @import("other.zig"); + +pub var saw_bar_function = false; +pub fn bar_function() void { + if (@This().foo_function()) { + saw_bar_function = true; + } +} diff --git a/test/behavior/usingnamespace/foo.zig b/test/behavior/usingnamespace/foo.zig new file mode 100644 index 0000000000000000000000000000000000000000..6b2b14e51ce35fa39486837e853d7a249c8f9a53 --- /dev/null +++ b/test/behavior/usingnamespace/foo.zig @@ -0,0 +1,14 @@ +// purposefully conflicting function with main source file +// but it's private so it should be OK +fn privateFunction() bool { + return false; +} + +pub fn printText() bool { + return privateFunction(); +} + +pub var saw_foo_function = false; +pub fn foo_function() void { + saw_foo_function = true; +} diff --git a/test/behavior/usingnamespace/import_segregation.zig b/test/behavior/usingnamespace/import_segregation.zig new file mode 100644 index 0000000000000000000000000000000000000000..a509189be3e4eb77b42217ae06e2b29de7bd0f1c --- /dev/null +++ b/test/behavior/usingnamespace/import_segregation.zig @@ -0,0 +1,11 @@ +const expect = @import("std").testing.expect; + +usingnamespace @import("foo.zig"); +usingnamespace @import("bar.zig"); + +test "no clobbering happened" { + @This().foo_function(); + @This().bar_function(); + try expect(@This().saw_foo_function); + try expect(@This().saw_bar_function); +} diff --git a/test/behavior/usingnamespace/other.zig b/test/behavior/usingnamespace/other.zig new file mode 100644 index 0000000000000000000000000000000000000000..02e0f39e90108e9c856b7edb2a6f25124d05ecbf --- /dev/null +++ b/test/behavior/usingnamespace/other.zig @@ -0,0 +1,4 @@ +pub fn foo_function() bool { + // this one conflicts with the one from foo + return true; +} diff --git a/test/behavior/usingnamespace_stage1.zig b/test/behavior/usingnamespace_stage1.zig index 30babc53817d675a164fa6a8f732769d5a64def2..142df21549c1ac7af3dd705717f9675e1fdb8ca2 100644 --- a/test/behavior/usingnamespace_stage1.zig +++ b/test/behavior/usingnamespace_stage1.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const expect = std.testing.expect; fn Foo(comptime T: type) type { return struct { @@ -20,3 +21,21 @@ usingnamespace struct { test "usingnamespace does not redeclare an imported variable" { comptime try std.testing.expect(@This().foo == 42); } + +usingnamespace @import("usingnamespace/foo.zig"); +test "usingnamespace omits mixing in private functions" { + try expect(@This().privateFunction()); + try expect(!@This().printText()); +} +fn privateFunction() bool { + return true; +} + +test { + _ = @import("usingnamespace/import_segregation.zig"); +} + +usingnamespace @import("usingnamespace/a.zig"); +test "two files usingnamespace import each other" { + try expect(@This().ok()); +} diff --git a/test/cases.zig b/test/cases.zig index 2f3884de1ed1548ca3f1451f18209ec127ad9222..64fe39e07be08370fc5d35154baf69429c4aca23 100644 --- a/test/cases.zig +++ b/test/cases.zig @@ -1073,27 +1073,17 @@ pub fn addCases(ctx: *TestContext) !void { case.addError( \\pub fn main() void { \\ var i = 0; - \\ for (n) |_, i| { + \\ for ("n") |_, i| { \\ } \\} , &[_][]const u8{ - ":3:17: error: redeclaration of local variable 'i'", + ":3:19: error: redeclaration of local variable 'i'", ":2:9: note: previous declaration here", }); case.addError( \\pub fn main() void { \\ var i = 0; - \\ for (n) |i| { - \\ } - \\} - , &[_][]const u8{ - ":3:14: error: redeclaration of local variable 'i'", - ":2:9: note: previous declaration here", - }); - case.addError( - \\pub fn main() void { - \\ var i = 0; - \\ while (n) |i| { + \\ for ("n") |i| { \\ } \\} , &[_][]const u8{ @@ -1103,7 +1093,17 @@ pub fn addCases(ctx: *TestContext) !void { case.addError( \\pub fn main() void { \\ var i = 0; - \\ while (n) |bruh| { + \\ while ("n") |i| { + \\ } + \\} + , &[_][]const u8{ + ":3:18: error: redeclaration of local variable 'i'", + ":2:9: note: previous declaration here", + }); + case.addError( + \\pub fn main() void { + \\ var i = 0; + \\ while ("n") |bruh| { \\ _ = bruh; \\ } else |i| { \\ diff --git a/test/cli.zig b/test/cli.zig index e3a00fe735addd981c79e0ed269ad438209e656c..59fb7095af53bd0c5c06afb4bf68dbcc30115180 100644 --- a/test/cli.zig +++ b/test/cli.zig @@ -45,13 +45,6 @@ pub fn main() !void { } } -fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 { - return arg catch |err| { - warn("Unable to parse command line: {}\n", .{err}); - return err; - }; -} - fn printCmd(cwd: []const u8, argv: []const []const u8) void { std.debug.warn("cd {s} && ", .{cwd}); for (argv) |arg| { diff --git a/test/compare_output.zig b/test/compare_output.zig index c3da3cc4a5c0721f09ca28629f1c64c984a1fda6..7ff428fb336f67cf3bfb4a1a74ea9ae82644c719 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -17,111 +17,6 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\} , "Hello, world!" ++ std.cstr.line_sep); - cases.addCase(x: { - var tc = cases.create("multiple files with private function", - \\usingnamespace @import("std").io; - \\usingnamespace @import("foo.zig"); - \\ - \\pub fn main() void { - \\ privateFunction(); - \\ const stdout = getStdOut().writer(); - \\ stdout.print("OK 2\n", .{}) catch unreachable; - \\} - \\ - \\fn privateFunction() void { - \\ printText(); - \\} - , "OK 1\nOK 2\n"); - - tc.addSourceFile("foo.zig", - \\usingnamespace @import("std").io; - \\ - \\// purposefully conflicting function with main.zig - \\// but it's private so it should be OK - \\fn privateFunction() void { - \\ const stdout = getStdOut().writer(); - \\ stdout.print("OK 1\n", .{}) catch unreachable; - \\} - \\ - \\pub fn printText() void { - \\ privateFunction(); - \\} - ); - - break :x tc; - }); - - cases.addCase(x: { - var tc = cases.create("import segregation", - \\usingnamespace @import("foo.zig"); - \\usingnamespace @import("bar.zig"); - \\ - \\pub fn main() void { - \\ foo_function(); - \\ bar_function(); - \\} - , "OK\nOK\n"); - - tc.addSourceFile("foo.zig", - \\usingnamespace @import("std").io; - \\pub fn foo_function() void { - \\ const stdout = getStdOut().writer(); - \\ stdout.print("OK\n", .{}) catch unreachable; - \\} - ); - - tc.addSourceFile("bar.zig", - \\usingnamespace @import("other.zig"); - \\usingnamespace @import("std").io; - \\ - \\pub fn bar_function() void { - \\ if (foo_function()) { - \\ const stdout = getStdOut().writer(); - \\ stdout.print("OK\n", .{}) catch unreachable; - \\ } - \\} - ); - - tc.addSourceFile("other.zig", - \\pub fn foo_function() bool { - \\ // this one conflicts with the one from foo - \\ return true; - \\} - ); - - break :x tc; - }); - - cases.addCase(x: { - var tc = cases.create("two files usingnamespace import each other", - \\usingnamespace @import("a.zig"); - \\ - \\pub fn main() void { - \\ ok(); - \\} - , "OK\n"); - - tc.addSourceFile("a.zig", - \\usingnamespace @import("b.zig"); - \\const io = @import("std").io; - \\ - \\pub const a_text = "OK\n"; - \\ - \\pub fn ok() void { - \\ const stdout = io.getStdOut().writer(); - \\ stdout.print(b_text, .{}) catch unreachable; - \\} - ); - - tc.addSourceFile("b.zig", - \\usingnamespace @import("a.zig"); - \\ - \\pub const b_text = a_text; - ); - - break :x tc; - }); - cases.add("hello world without libc", \\const io = @import("std").io; \\ diff --git a/test/standalone/brace_expansion/main.zig b/test/standalone/brace_expansion/main.zig index 990c2b16600a0589d3d382509dc1446972887d35..35fe6e5c6a08ec626f327b7f13df911c5ad3ff0b 100644 --- a/test/standalone/brace_expansion/main.zig +++ b/test/standalone/brace_expansion/main.zig @@ -234,7 +234,7 @@ pub fn main() !void { var result_buf = ArrayList(u8).init(global_allocator); defer result_buf.deinit(); - try expandString(stdin_buf.items, &result_buf); + try expandString(stdin.items, &result_buf); try stdout_file.write(result_buf.items); } -- 2.54.0