Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

W

c.W
pub const W = switch (native_os)

File

lib/std/c.zig:3710

Code

pub const W = switch (native_os) {
    .linux => linux.W,
    .emscripten => emscripten.W,
    .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
        /// [XSI] no hang in wait/no child to reap
        pub const NOHANG = 0x00000001;
        /// [XSI] notify on stop, untraced child
        pub const UNTRACED = 0x00000002;

        pub fn EXITSTATUS(x: u32) u8 {
            return @as(u8, @intCast(x >> 8));
        }
        pub fn TERMSIG(x: u32) SIG {
            return @fromBackingInt(@intCast(status(x)));
        }
        pub fn STOPSIG(x: u32) SIG {
            return @fromBackingInt(@intCast(x >> 8));
        }
        pub fn IFEXITED(x: u32) bool {
            return status(x) == 0;
        }
        pub fn IFSTOPPED(x: u32) bool {
            return status(x) == stopped and @as(u32, @backingInt(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;
    },
    .freebsd => struct {
        pub const NOHANG = 1;
        pub const UNTRACED = 2;
        pub const STOPPED = UNTRACED;
        pub const CONTINUED = 4;
        pub const NOWAIT = 8;
        pub const EXITED = 16;
        pub const TRAPPED = 32;

        pub fn EXITSTATUS(s: u32) u8 {
            return @as(u8, @intCast((s & 0xff00) >> 8));
        }
        pub fn TERMSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(s & 0x7f));
        }
        pub fn STOPSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(EXITSTATUS(s)));
        }
        pub fn IFEXITED(s: u32) bool {
            return (s & 0x7f) == 0;
        }
        pub fn IFSTOPPED(s: u32) bool {
            return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
        }
        pub fn IFSIGNALED(s: u32) bool {
            return (s & 0xffff) -% 1 < 0xff;
        }
    },
    .illumos => struct {
        pub const EXITED = 0o001;
        pub const TRAPPED = 0o002;
        pub const UNTRACED = 0o004;
        pub const STOPPED = UNTRACED;
        pub const CONTINUED = 0o010;
        pub const NOHANG = 0o100;
        pub const NOWAIT = 0o200;

        pub fn EXITSTATUS(s: u32) u8 {
            return @as(u8, @intCast((s >> 8) & 0xff));
        }
        pub fn TERMSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(s & 0x7f));
        }
        pub fn STOPSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(EXITSTATUS(s)));
        }
        pub fn IFEXITED(s: u32) bool {
            return (s & 0x7f) == 0;
        }

        pub fn IFCONTINUED(s: u32) bool {
            return ((s & 0o177777) == 0o177777);
        }

        pub fn IFSTOPPED(s: u32) bool {
            return (s & 0x00ff != 0o177) and !(s & 0xff00 != 0);
        }

        pub fn IFSIGNALED(s: u32) bool {
            return s & 0x00ff > 0 and s & 0xff00 == 0;
        }
    },
    .netbsd => struct {
        pub const NOHANG = 0x00000001;
        pub const UNTRACED = 0x00000002;
        pub const STOPPED = UNTRACED;
        pub const CONTINUED = 0x00000010;
        pub const NOWAIT = 0x00010000;
        pub const EXITED = 0x00000020;
        pub const TRAPPED = 0x00000040;

        pub fn EXITSTATUS(s: u32) u8 {
            return @as(u8, @intCast((s >> 8) & 0xff));
        }
        pub fn TERMSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(s & 0x7f));
        }
        pub fn STOPSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(EXITSTATUS(s)));
        }
        pub fn IFEXITED(s: u32) bool {
            return (s & 0x7f) == 0;
        }

        pub fn IFCONTINUED(s: u32) bool {
            return (s == CONTINUED);
        }

        pub fn IFSTOPPED(s: u32) bool {
            return (((s & 0x7f) == STOPPED) and !IFCONTINUED(s));
        }

        pub fn IFSIGNALED(s: u32) bool {
            return !IFSTOPPED(s) and !IFCONTINUED(s) and !IFEXITED(s);
        }
    },
    .dragonfly => struct {
        pub const NOHANG = 0x0001;
        pub const UNTRACED = 0x0002;
        pub const CONTINUED = 0x0004;
        pub const STOPPED = UNTRACED;
        pub const NOWAIT = 0x0008;
        pub const EXITED = 0x0010;
        pub const TRAPPED = 0x0020;

        pub fn EXITSTATUS(s: u32) u8 {
            return @as(u8, @intCast((s & 0xff00) >> 8));
        }
        pub fn TERMSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(s & 0x7f));
        }
        pub fn STOPSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(EXITSTATUS(s)));
        }
        pub fn IFEXITED(s: u32) bool {
            return (s & 0x7f) == 0;
        }
        pub fn IFSTOPPED(s: u32) bool {
            return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
        }
        pub fn IFSIGNALED(s: u32) bool {
            return (s & 0xffff) -% 1 < 0xff;
        }
    },
    .haiku => struct {
        pub const NOHANG = 0x1;
        pub const UNTRACED = 0x2;
        pub const CONTINUED = 0x4;
        pub const EXITED = 0x08;
        pub const STOPPED = 0x10;
        pub const NOWAIT = 0x20;

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

        pub fn TERMSIG(s: u32) SIG {
            return @fromBackingInt(@intCast((s >> 8) & 0xff));
        }

        pub fn STOPSIG(s: u32) SIG {
            return @fromBackingInt(@intCast((s >> 16) & 0xff));
        }

        pub fn IFEXITED(s: u32) bool {
            return (s & ~@as(u32, 0xff)) == 0;
        }

        pub fn IFSTOPPED(s: u32) bool {
            return ((s >> 16) & 0xff) != 0;
        }

        pub fn IFSIGNALED(s: u32) bool {
            return ((s >> 8) & 0xff) != 0;
        }
    },
    .openbsd => struct {
        pub const NOHANG = 1;
        pub const UNTRACED = 2;
        pub const CONTINUED = 8;

        pub fn EXITSTATUS(s: u32) u8 {
            return @as(u8, @intCast((s >> 8) & 0xff));
        }
        pub fn TERMSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(s & 0x7f));
        }
        pub fn STOPSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(EXITSTATUS(s)));
        }
        pub fn IFEXITED(s: u32) bool {
            return (s & 0x7f) == 0;
        }

        pub fn IFCONTINUED(s: u32) bool {
            return ((s & 0o177777) == 0o177777);
        }

        pub fn IFSTOPPED(s: u32) bool {
            return (s & 0xff == 0o177);
        }

        pub fn IFSIGNALED(s: u32) bool {
            return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);
        }
    },
    // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/sys/wait.h
    .serenity => struct {
        pub const NOHANG = 1;
        pub const UNTRACED = 2;
        pub const STOPPED = UNTRACED;
        pub const EXITED = 4;
        pub const CONTINUED = 8;
        pub const NOWAIT = 0x1000000;

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

        pub fn STOPSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(EXITSTATUS(s)));
        }

        pub fn TERMSIG(s: u32) SIG {
            return @fromBackingInt(@intCast(s & 0x7f));
        }

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

        pub fn IFSTOPPED(s: u32) bool {
            return (s & 0xff) == 0x7f;
        }

        pub fn IFSIGNALED(s: u32) bool {
            return (((s & 0x7f) + 1) >> 1) > 0;
        }

        pub fn IFCONTINUED(s: u32) bool {
            return s == 0xffff;
        }
    },
    else => void,
}