From 5258c3caad3a914fd4d8276dc118428181b364ee Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 15:41:38 -0700 Subject: [PATCH 01/11] std: add type safety to cc_t --- lib/std/c.zig | 161 ++++++++++++++++++++++++++++++++++++++ lib/std/c/darwin.zig | 25 +----- lib/std/c/emscripten.zig | 18 ++++- lib/std/c/haiku.zig | 5 +- lib/std/c/netbsd.zig | 27 +------ lib/std/c/openbsd.zig | 27 +------ lib/std/c/solaris.zig | 3 +- lib/std/os.zig | 1 + lib/std/os/emscripten.zig | 17 ---- lib/std/os/linux.zig | 104 +++++++++++++++++++----- 10 files changed, 267 insertions(+), 121 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 0ee029ddfc..74a009d9ca 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -679,6 +679,167 @@ pub const MAP = switch (native_os) { /// Used by libc to communicate failure. Not actually part of the underlying syscall. pub const MAP_FAILED: *anyopaque = @ptrFromInt(std.math.maxInt(usize)); +pub const cc_t = switch (native_os) { + .linux => std.os.linux.cc_t, + .macos, .ios, .tvos, .watchos => enum(u8) { + VEOF = 0, + VEOL = 1, + VEOL2 = 2, + VERASE = 3, + VWERASE = 4, + VKILL = 5, + VREPRINT = 6, + VINTR = 8, + VQUIT = 9, + VSUSP = 10, + VDSUSP = 11, + VSTART = 12, + VSTOP = 13, + VLNEXT = 14, + VDISCARD = 15, + VMIN = 16, + VTIME = 17, + VSTATUS = 18, + }, + .freebsd, .kfreebsd => enum(u8) { + VEOF = 0, + VEOL = 1, + VEOL2 = 2, + VERASE = 3, + VWERASE = 4, + VKILL = 5, + VREPRINT = 6, + VERASE2 = 7, + VINTR = 8, + VQUIT = 9, + VSUSP = 10, + VDSUSP = 11, + VSTART = 12, + VSTOP = 13, + VLNEXT = 14, + VDISCARD = 15, + VMIN = 16, + VTIME = 17, + VSTATUS = 18, + }, + .netbsd => enum(u8) { + VEOF = 0, + VEOL = 1, + VEOL2 = 2, + VERASE = 3, + VWERASE = 4, + VKILL = 5, + VREPRINT = 6, + VINTR = 8, + VQUIT = 9, + VSUSP = 10, + VDSUSP = 11, + VSTART = 12, + VSTOP = 13, + VLNEXT = 14, + VDISCARD = 15, + VMIN = 16, + VTIME = 17, + VSTATUS = 18, + }, + .openbsd => enum(u8) { + VEOF = 0, + VEOL = 1, + VEOL2 = 2, + VERASE = 3, + VWERASE = 4, + VKILL = 5, + VREPRINT = 6, + VINTR = 8, + VQUIT = 9, + VSUSP = 10, + VDSUSP = 11, + VSTART = 12, + VSTOP = 13, + VLNEXT = 14, + VDISCARD = 15, + VMIN = 16, + VTIME = 17, + VSTATUS = 18, + }, + .haiku => enum(u8) { + VINTR = 0, + VQUIT = 1, + VERASE = 2, + VKILL = 3, + VEOF = 4, + VEOL = 5, + VMIN = 4, + VTIME = 5, + VEOL2 = 6, + VSWTCH = 7, + VSTART = 8, + VSTOP = 9, + VSUSP = 10, + }, + .solaris, .illumos => enum(u8) { + VINTR = 0, + VQUIT = 1, + VERASE = 2, + VKILL = 3, + VEOF = 4, + VEOL = 5, + VEOL2 = 6, + VMIN = 4, + VTIME = 5, + VSWTCH = 7, + VSTART = 8, + VSTOP = 9, + VSUSP = 10, + VDSUSP = 11, + VREPRINT = 12, + VDISCARD = 13, + VWERASE = 14, + VLNEXT = 15, + VSTATUS = 16, + VERASE2 = 17, + }, + .emscripten => enum(u8) { + VINTR = 0, + VQUIT = 1, + VERASE = 2, + VKILL = 3, + VEOF = 4, + VTIME = 5, + VMIN = 6, + VSWTC = 7, + VSTART = 8, + VSTOP = 9, + VSUSP = 10, + VEOL = 11, + VREPRINT = 12, + VDISCARD = 13, + VWERASE = 14, + VLNEXT = 15, + VEOL2 = 16, + }, + .wasi => enum(u8) { + VINTR = 0, + VQUIT = 1, + VERASE = 2, + VKILL = 3, + VEOF = 4, + VTIME = 5, + VMIN = 6, + VSWTC = 7, + VSTART = 8, + VSTOP = 9, + VSUSP = 10, + VEOL = 11, + VREPRINT = 12, + VDISCARD = 13, + VWERASE = 14, + VLNEXT = 15, + VEOL2 = 16, + }, + else => @compileError("target libc does not have cc_t"), +}; + pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int; // Unix-like systems diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index d598c7d7b8..930f53f83b 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -2692,31 +2692,8 @@ pub const SHUT = struct { pub const RDWR = 2; }; -// Term -pub const V = struct { - pub const EOF = 0; - pub const EOL = 1; - pub const EOL2 = 2; - pub const ERASE = 3; - pub const WERASE = 4; - pub const KILL = 5; - pub const REPRINT = 6; - pub const INTR = 8; - pub const QUIT = 9; - pub const SUSP = 10; - pub const DSUSP = 11; - pub const START = 12; - pub const STOP = 13; - pub const LNEXT = 14; - pub const DISCARD = 15; - pub const MIN = 16; - pub const TIME = 17; - pub const STATUS = 18; -}; - pub const NCCS = 20; // 2 spares (7, 19) -pub const cc_t = u8; pub const speed_t = u64; pub const tcflag_t = u64; @@ -2859,7 +2836,7 @@ pub const termios = extern struct { oflag: tcflag_t, // output flags cflag: tcflag_t, // control flags lflag: tcflag_t, // local flags - cc: [NCCS]cc_t, // control chars + cc: [NCCS]std.c.cc_t, // control chars ispeed: speed_t align(8), // input speed ospeed: speed_t, // output speed }; diff --git a/lib/std/c/emscripten.zig b/lib/std/c/emscripten.zig index ae72928eb9..094d5e49c5 100644 --- a/lib/std/c/emscripten.zig +++ b/lib/std/c/emscripten.zig @@ -72,8 +72,6 @@ pub const sigset_t = emscripten.sigset_t; pub const sockaddr = emscripten.sockaddr; pub const socklen_t = emscripten.socklen_t; pub const stack_t = emscripten.stack_t; -pub const tcflag_t = emscripten.tcflag_t; -pub const termios = emscripten.termios; pub const time_t = emscripten.time_t; pub const timespec = emscripten.timespec; pub const timeval = emscripten.timeval; @@ -180,3 +178,19 @@ pub const dirent = struct { type: u8, name: [256]u8, }; + +pub const speed_t = u32; +pub const tcflag_t = u32; + +pub const NCCS = 32; + +pub const termios = extern struct { + iflag: tcflag_t, + oflag: tcflag_t, + cflag: tcflag_t, + lflag: tcflag_t, + line: std.c.cc_t, + cc: [NCCS]std.c.cc_t, + ispeed: speed_t, + ospeed: speed_t, +}; diff --git a/lib/std/c/haiku.zig b/lib/std/c/haiku.zig index 63bfa6b82e..1152eb7470 100644 --- a/lib/std/c/haiku.zig +++ b/lib/std/c/haiku.zig @@ -950,7 +950,6 @@ pub const directory_which = enum(c_int) { _, }; -pub const cc_t = u8; pub const speed_t = u8; pub const tcflag_t = u32; @@ -961,10 +960,10 @@ pub const termios = extern struct { c_oflag: tcflag_t, c_cflag: tcflag_t, c_lflag: tcflag_t, - c_line: cc_t, + c_line: std.c.cc_t, c_ispeed: speed_t, c_ospeed: speed_t, - cc_t: [NCCS]cc_t, + cc_t: [NCCS]std.c.cc_t, }; pub const MSG_NOSIGNAL = 0x0800; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index b062090dd4..79f6a47620 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -806,30 +806,6 @@ pub const T = struct { pub const IOCXMTFRAME = 0x80087444; }; -// Term -const V = struct { - pub const EOF = 0; // ICANON - pub const EOL = 1; // ICANON - pub const EOL2 = 2; // ICANON - pub const ERASE = 3; // ICANON - pub const WERASE = 4; // ICANON - pub const KILL = 5; // ICANON - pub const REPRINT = 6; // ICANON - // 7 spare 1 - pub const INTR = 8; // ISIG - pub const QUIT = 9; // ISIG - pub const SUSP = 10; // ISIG - pub const DSUSP = 11; // ISIG - pub const START = 12; // IXON, IXOFF - pub const STOP = 13; // IXON, IXOFF - pub const LNEXT = 14; // IEXTEN - pub const DISCARD = 15; // IEXTEN - pub const MIN = 16; // !ICANON - pub const TIME = 17; // !ICANON - pub const STATUS = 18; // ICANON - // 19 spare 2 -}; - // Input flags - software input processing pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINT @@ -876,7 +852,6 @@ pub const CHWFLOW: tcflag_t = (MDMBUF | CRTSCTS | CDTRCTS); // all types of hw f pub const tcflag_t = c_uint; pub const speed_t = c_uint; -pub const cc_t = u8; pub const NCCS = 20; @@ -885,7 +860,7 @@ pub const termios = extern struct { oflag: tcflag_t, // output flags cflag: tcflag_t, // control flags lflag: tcflag_t, // local flags - cc: [NCCS]cc_t, // control chars + cc: [NCCS]std.c.cc_t, // control chars ispeed: c_int, // input speed ospeed: c_int, // output speed }; diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index adf37ce48e..42b88fe203 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -768,33 +768,8 @@ pub const AUTH = struct { pub const ALLOW: c_int = (OKAY | ROOTOKAY | SECURE); }; -// Term -pub const V = struct { - pub const EOF = 0; // ICANON - pub const EOL = 1; // ICANON - pub const EOL2 = 2; // ICANON - pub const ERASE = 3; // ICANON - pub const WERASE = 4; // ICANON - pub const KILL = 5; // ICANON - pub const REPRINT = 6; // ICANON - // 7 spare 1 - pub const INTR = 8; // ISIG - pub const QUIT = 9; // ISIG - pub const SUSP = 10; // ISIG - pub const DSUSP = 11; // ISIG - pub const START = 12; // IXON, IXOFF - pub const STOP = 13; // IXON, IXOFF - pub const LNEXT = 14; // IEXTEN - pub const DISCARD = 15; // IEXTEN - pub const MIN = 16; // !ICANON - pub const TIME = 17; // !ICANON - pub const STATUS = 18; // ICANON - // 19 spare 2 -}; - pub const tcflag_t = c_uint; pub const speed_t = c_uint; -pub const cc_t = u8; pub const NCCS = 20; @@ -848,7 +823,7 @@ pub const termios = extern struct { oflag: tcflag_t, // output flags cflag: tcflag_t, // control flags lflag: tcflag_t, // local flags - cc: [NCCS]cc_t, // control chars + cc: [NCCS]std.c.cc_t, // control chars ispeed: c_int, // input speed ospeed: c_int, // output speed }; diff --git a/lib/std/c/solaris.zig b/lib/std/c/solaris.zig index db4afbcced..8596dc0f04 100644 --- a/lib/std/c/solaris.zig +++ b/lib/std/c/solaris.zig @@ -699,7 +699,6 @@ pub const SEEK = struct { }; pub const tcflag_t = c_uint; -pub const cc_t = u8; pub const speed_t = c_uint; pub const NCCS = 19; @@ -709,7 +708,7 @@ pub const termios = extern struct { c_oflag: tcflag_t, c_cflag: tcflag_t, c_lflag: tcflag_t, - c_cc: [NCCS]cc_t, + c_cc: [NCCS]std.c.cc_t, }; fn tioc(t: u16, num: u8) u16 { diff --git a/lib/std/os.zig b/lib/std/os.zig index a5c8d8d35e..e948440994 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -139,6 +139,7 @@ pub const W = system.W; pub const addrinfo = system.addrinfo; pub const blkcnt_t = system.blkcnt_t; pub const blksize_t = system.blksize_t; +pub const cc_t = system.cc_t; pub const clock_t = system.clock_t; pub const cpu_set_t = system.cpu_set_t; pub const dev_t = system.dev_t; diff --git a/lib/std/os/emscripten.zig b/lib/std/os/emscripten.zig index d5ab74273b..9132b9e259 100644 --- a/lib/std/os/emscripten.zig +++ b/lib/std/os/emscripten.zig @@ -1098,23 +1098,6 @@ pub const stack_t = extern struct { size: usize, }; -pub const cc_t = u8; -pub const speed_t = u32; -pub const tcflag_t = u32; - -pub const NCCS = 32; - -pub const termios = extern struct { - iflag: tcflag_t, - oflag: tcflag_t, - cflag: tcflag_t, - lflag: tcflag_t, - line: cc_t, - cc: [NCCS]cc_t, - ispeed: speed_t, - ospeed: speed_t, -}; - pub const timespec = extern struct { tv_sec: time_t, tv_nsec: isize, diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 36932e5b19..e3975234de 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -5004,9 +5004,7 @@ pub const rusage = extern struct { pub const THREAD = 1; }; -pub const cc_t = u8; pub const speed_t = u32; -pub const tcflag_t = u32; pub const NCCS = 32; @@ -5124,21 +5122,84 @@ pub const V = switch (native_arch) { }, }; -pub const IGNBRK: tcflag_t = 1; -pub const BRKINT: tcflag_t = 2; -pub const IGNPAR: tcflag_t = 4; -pub const PARMRK: tcflag_t = 8; -pub const INPCK: tcflag_t = 16; -pub const ISTRIP: tcflag_t = 32; -pub const INLCR: tcflag_t = 64; -pub const IGNCR: tcflag_t = 128; -pub const ICRNL: tcflag_t = 256; -pub const IUCLC: tcflag_t = 512; -pub const IXON: tcflag_t = 1024; -pub const IXANY: tcflag_t = 2048; -pub const IXOFF: tcflag_t = 4096; -pub const IMAXBEL: tcflag_t = 8192; -pub const IUTF8: tcflag_t = 16384; +pub const tc_iflag_t = packed struct (u32) { + IGNBRK: bool = false, + BRKINT: bool = false, + IGNPAR: bool = false, + PARMRK: bool = false, + INPCK: bool = false, + ISTRIP: bool = false, + INLCR: bool = false, + IGNCR: bool = false, + ICRNL: bool = false, + IUCLC: bool = false, + IXON: bool = false, + IXANY: bool = false, + IXOFF: bool = false, + IMAXBEL: bool = false, + IUTF8: bool = false, + _: u17 = 0, +}; + +pub const cc_t = switch (native_arch) { + .mips, .mipsel, .mips64, .mips64el => enum(u8){ + VINTR = 0, + VQUIT = 1, + VERASE = 2, + VKILL = 3, + VMIN = 4, + VTIME = 5, + VEOL2 = 6, + VSWTC = 7, + VSTART = 8, + VSTOP = 9, + VSUSP = 10, + VREPRINT = 12, + VDISCARD = 13, + VWERASE = 14, + VLNEXT = 15, + VEOF = 16, + VEOL = 17, + }, + .powerpc, .powerpc64, .powerpc64le => enum(u8) { + VINTR = 0, + VQUIT = 1, + VERASE = 2, + VKILL = 3, + VEOF = 4, + VMIN = 5, + VEOL = 6, + VTIME = 7, + VEOL2 = 8, + VSWTC = 9, + VWERASE = 10, + VREPRINT = 11, + VSUSP = 12, + VSTART = 13, + VSTOP = 14, + VLNEXT = 15, + VDISCARD = 16, + }, + else => enum(u8) { + VINTR = 0, + VQUIT = 1, + VERASE = 2, + VKILL = 3, + VEOF = 4, + VTIME = 5, + VMIN = 6, + VSWTC = 7, + VSTART = 8, + VSTOP = 9, + VSUSP = 10, + VEOL = 11, + VREPRINT = 12, + VDISCARD = 13, + VWERASE = 14, + VLNEXT = 15, + VEOL2 = 16, + }, +}; pub const OPOST: tcflag_t = 1; pub const OLCUC: tcflag_t = 2; @@ -5148,6 +5209,7 @@ pub const ONOCR: tcflag_t = 16; pub const ONLRET: tcflag_t = 32; pub const OFILL: tcflag_t = 64; pub const OFDEL: tcflag_t = 128; + pub const VTDLY: tcflag_t = 16384; pub const VT0: tcflag_t = 0; pub const VT1: tcflag_t = 16384; @@ -5182,10 +5244,10 @@ pub const TCSA = enum(c_uint) { }; pub const termios = extern struct { - iflag: tcflag_t, - oflag: tcflag_t, - cflag: tcflag_t, - lflag: tcflag_t, + iflag: tc_iflag_t, + oflag: tc_oflag_t, + cflag: tc_cflag_t, + lflag: tc_lflag_t, line: cc_t, cc: [NCCS]cc_t, ispeed: speed_t, From 9bdf1ebe3644ee965aab152dd46534a036deaaa8 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 15:44:28 -0700 Subject: [PATCH 02/11] std.c.cc_t: consolidate same OS values --- lib/std/c.zig | 63 ++------------------------------------------------- 1 file changed, 2 insertions(+), 61 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 74a009d9ca..0f31987dc6 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -681,7 +681,7 @@ pub const MAP_FAILED: *anyopaque = @ptrFromInt(std.math.maxInt(usize)); pub const cc_t = switch (native_os) { .linux => std.os.linux.cc_t, - .macos, .ios, .tvos, .watchos => enum(u8) { + .macos, .ios, .tvos, .watchos, .netbsd, .openbsd => enum(u8) { VEOF = 0, VEOL = 1, VEOL2 = 2, @@ -722,46 +722,6 @@ pub const cc_t = switch (native_os) { VTIME = 17, VSTATUS = 18, }, - .netbsd => enum(u8) { - VEOF = 0, - VEOL = 1, - VEOL2 = 2, - VERASE = 3, - VWERASE = 4, - VKILL = 5, - VREPRINT = 6, - VINTR = 8, - VQUIT = 9, - VSUSP = 10, - VDSUSP = 11, - VSTART = 12, - VSTOP = 13, - VLNEXT = 14, - VDISCARD = 15, - VMIN = 16, - VTIME = 17, - VSTATUS = 18, - }, - .openbsd => enum(u8) { - VEOF = 0, - VEOL = 1, - VEOL2 = 2, - VERASE = 3, - VWERASE = 4, - VKILL = 5, - VREPRINT = 6, - VINTR = 8, - VQUIT = 9, - VSUSP = 10, - VDSUSP = 11, - VSTART = 12, - VSTOP = 13, - VLNEXT = 14, - VDISCARD = 15, - VMIN = 16, - VTIME = 17, - VSTATUS = 18, - }, .haiku => enum(u8) { VINTR = 0, VQUIT = 1, @@ -799,26 +759,7 @@ pub const cc_t = switch (native_os) { VSTATUS = 16, VERASE2 = 17, }, - .emscripten => enum(u8) { - VINTR = 0, - VQUIT = 1, - VERASE = 2, - VKILL = 3, - VEOF = 4, - VTIME = 5, - VMIN = 6, - VSWTC = 7, - VSTART = 8, - VSTOP = 9, - VSUSP = 10, - VEOL = 11, - VREPRINT = 12, - VDISCARD = 13, - VWERASE = 14, - VLNEXT = 15, - VEOL2 = 16, - }, - .wasi => enum(u8) { + .emscripten, .wasi => enum(u8) { VINTR = 0, VQUIT = 1, VERASE = 2, From 9a643185540a3bba31e449fdf6f25643a2ea3394 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 15:52:13 -0700 Subject: [PATCH 03/11] std.c.NCSS: consolidate and correct --- lib/std/c.zig | 9 +++++++++ lib/std/c/darwin.zig | 4 +--- lib/std/c/emscripten.zig | 4 +--- lib/std/c/haiku.zig | 4 +--- lib/std/c/netbsd.zig | 4 +--- lib/std/c/openbsd.zig | 4 +--- lib/std/c/solaris.zig | 4 +--- lib/std/os/linux.zig | 5 ++++- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 0f31987dc6..348d24b14b 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -781,6 +781,15 @@ pub const cc_t = switch (native_os) { else => @compileError("target libc does not have cc_t"), }; +pub const NCCS = switch (native_os) { + .linux => std.os.linux.NCCS, + .macos, .ios, .tvos, .watchos, .freebsd, .kfreebsd, .netbsd, .openbsd, .dragonfly => 20, + .haiku => 11, + .solaris, .illumos => 19, + .emscripten, .wasi => 32, + else => @compileError("target libc does not have NCCS"), +}; + pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int; // Unix-like systems diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 930f53f83b..66ac3e9855 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -2692,8 +2692,6 @@ pub const SHUT = struct { pub const RDWR = 2; }; -pub const NCCS = 20; // 2 spares (7, 19) - pub const speed_t = u64; pub const tcflag_t = u64; @@ -2836,7 +2834,7 @@ pub const termios = extern struct { oflag: tcflag_t, // output flags cflag: tcflag_t, // control flags lflag: tcflag_t, // local flags - cc: [NCCS]std.c.cc_t, // control chars + cc: [std.c.NCCS]std.c.cc_t, // control chars ispeed: speed_t align(8), // input speed ospeed: speed_t, // output speed }; diff --git a/lib/std/c/emscripten.zig b/lib/std/c/emscripten.zig index 094d5e49c5..8870e973f5 100644 --- a/lib/std/c/emscripten.zig +++ b/lib/std/c/emscripten.zig @@ -182,15 +182,13 @@ pub const dirent = struct { pub const speed_t = u32; pub const tcflag_t = u32; -pub const NCCS = 32; - pub const termios = extern struct { iflag: tcflag_t, oflag: tcflag_t, cflag: tcflag_t, lflag: tcflag_t, line: std.c.cc_t, - cc: [NCCS]std.c.cc_t, + cc: [std.c.NCCS]std.c.cc_t, ispeed: speed_t, ospeed: speed_t, }; diff --git a/lib/std/c/haiku.zig b/lib/std/c/haiku.zig index 1152eb7470..f91625a0c3 100644 --- a/lib/std/c/haiku.zig +++ b/lib/std/c/haiku.zig @@ -953,8 +953,6 @@ pub const directory_which = enum(c_int) { pub const speed_t = u8; pub const tcflag_t = u32; -pub const NCCS = 11; - pub const termios = extern struct { c_iflag: tcflag_t, c_oflag: tcflag_t, @@ -963,7 +961,7 @@ pub const termios = extern struct { c_line: std.c.cc_t, c_ispeed: speed_t, c_ospeed: speed_t, - cc_t: [NCCS]std.c.cc_t, + cc_t: [std.c.NCCS]std.c.cc_t, }; pub const MSG_NOSIGNAL = 0x0800; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index 79f6a47620..9e232b1608 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -853,14 +853,12 @@ pub const CHWFLOW: tcflag_t = (MDMBUF | CRTSCTS | CDTRCTS); // all types of hw f pub const tcflag_t = c_uint; pub const speed_t = c_uint; -pub const NCCS = 20; - pub const termios = extern struct { iflag: tcflag_t, // input flags oflag: tcflag_t, // output flags cflag: tcflag_t, // control flags lflag: tcflag_t, // local flags - cc: [NCCS]std.c.cc_t, // control chars + cc: [std.c.NCCS]std.c.cc_t, // control chars ispeed: c_int, // input speed ospeed: c_int, // output speed }; diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index 42b88fe203..135ad689a7 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -771,8 +771,6 @@ pub const AUTH = struct { pub const tcflag_t = c_uint; pub const speed_t = c_uint; -pub const NCCS = 20; - // Input flags - software input processing pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINT @@ -823,7 +821,7 @@ pub const termios = extern struct { oflag: tcflag_t, // output flags cflag: tcflag_t, // control flags lflag: tcflag_t, // local flags - cc: [NCCS]std.c.cc_t, // control chars + cc: [std.c.NCCS]std.c.cc_t, // control chars ispeed: c_int, // input speed ospeed: c_int, // output speed }; diff --git a/lib/std/c/solaris.zig b/lib/std/c/solaris.zig index 8596dc0f04..7c094d2969 100644 --- a/lib/std/c/solaris.zig +++ b/lib/std/c/solaris.zig @@ -701,14 +701,12 @@ pub const SEEK = struct { pub const tcflag_t = c_uint; pub const speed_t = c_uint; -pub const NCCS = 19; - pub const termios = extern struct { c_iflag: tcflag_t, c_oflag: tcflag_t, c_cflag: tcflag_t, c_lflag: tcflag_t, - c_cc: [NCCS]std.c.cc_t, + c_cc: [std.c.NCCS]std.c.cc_t, }; fn tioc(t: u16, num: u8) u16 { diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index e3975234de..1dae5a7cc8 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -5006,7 +5006,10 @@ pub const rusage = extern struct { pub const speed_t = u32; -pub const NCCS = 32; +pub const NCCS = switch (native_arch) { + .powerpc, .powerpcle, .powerpc64, .powerpc64le => 19, + else => 32, +}; pub const B0 = 0o0000000; pub const B50 = 0o0000001; From 0c88f927f161224f5c5ce2b12a76133a421af081 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 16:21:21 -0700 Subject: [PATCH 04/11] std.os.termios: consolidate and correct --- lib/std/c.zig | 78 +++++++++++++++++ lib/std/c/darwin.zig | 13 --- lib/std/c/emscripten.zig | 14 --- lib/std/c/haiku.zig | 14 --- lib/std/c/linux.zig | 2 - lib/std/c/netbsd.zig | 13 --- lib/std/c/openbsd.zig | 13 --- lib/std/c/solaris.zig | 11 --- lib/std/os.zig | 2 + lib/std/os/linux.zig | 178 ++++++++++++--------------------------- 10 files changed, 135 insertions(+), 203 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 348d24b14b..9794e3560b 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -790,6 +790,84 @@ pub const NCCS = switch (native_os) { else => @compileError("target libc does not have NCCS"), }; +pub const termios = switch (native_os) { + .linux => std.os.linux.termios, + .macos, .ios, .tvos, .watchos => extern struct { + iflag: tcflag_t, + oflag: tcflag_t, + cflag: tcflag_t, + lflag: tcflag_t, + cc: [NCCS]cc_t, + ispeed: speed_t align(8), + ospeed: speed_t, + }, + .freebsd, .kfreebsd, .netbsd, .dragonfly, .openbsd => extern struct { + iflag: tcflag_t, + oflag: tcflag_t, + cflag: tcflag_t, + lflag: tcflag_t, + cc: [NCCS]cc_t, + ispeed: speed_t, + ospeed: speed_t, + }, + .haiku => extern struct { + iflag: tcflag_t, + oflag: tcflag_t, + cflag: tcflag_t, + lflag: tcflag_t, + line: cc_t, + ispeed: speed_t, + ospeed: speed_t, + cc: [NCCS]cc_t, + }, + .solaris, .illumos => extern struct { + iflag: tcflag_t, + oflag: tcflag_t, + cflag: tcflag_t, + lflag: tcflag_t, + cc: [NCCS]cc_t, + }, + .emscripten, .wasi => extern struct { + iflag: tcflag_t, + oflag: tcflag_t, + cflag: tcflag_t, + lflag: tcflag_t, + line: std.c.cc_t, + cc: [NCCS]cc_t, + ispeed: speed_t, + ospeed: speed_t, + }, + else => @compileError("target libc does not have termios"), +}; + +pub const tcflag_t = switch (native_os) { + .linux => std.os.linux.tcflag_t, + .macos, .ios, .tvos, .watchos => u64, + .freebsd, .kfreebsd => c_uint, + .netbsd => c_uint, + .dragonfly => c_uint, + .openbsd => c_uint, + .haiku => u32, + .solaris, .illumos => c_uint, + .emscripten => u32, + .wasi => c_uint, + else => @compileError("target libc does not have tcflag_t"), +}; + +pub const speed_t = switch (native_os) { + .linux => std.os.linux.speed_t, + .macos, .ios, .tvos, .watchos => u64, + .freebsd, .kfreebsd => c_uint, + .netbsd => c_uint, + .dragonfly => c_uint, + .openbsd => c_uint, + .haiku => u8, + .solaris, .illumos => c_uint, + .emscripten => u32, + .wasi => c_uint, + else => @compileError("target libc does not have speed_t"), +}; + pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int; // Unix-like systems diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 66ac3e9855..715678de22 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -2692,9 +2692,6 @@ pub const SHUT = struct { pub const RDWR = 2; }; -pub const speed_t = u64; -pub const tcflag_t = u64; - pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINTR pub const IGNPAR: tcflag_t = 0x00000004; // ignore (discard) parity errors @@ -2829,16 +2826,6 @@ pub const TCOON: tcflag_t = 2; pub const TCIOFF: tcflag_t = 3; pub const TCION: tcflag_t = 4; -pub const termios = extern struct { - iflag: tcflag_t, // input flags - oflag: tcflag_t, // output flags - cflag: tcflag_t, // control flags - lflag: tcflag_t, // local flags - cc: [std.c.NCCS]std.c.cc_t, // control chars - ispeed: speed_t align(8), // input speed - ospeed: speed_t, // output speed -}; - pub const winsize = extern struct { ws_row: u16, ws_col: u16, diff --git a/lib/std/c/emscripten.zig b/lib/std/c/emscripten.zig index 8870e973f5..0031132855 100644 --- a/lib/std/c/emscripten.zig +++ b/lib/std/c/emscripten.zig @@ -178,17 +178,3 @@ pub const dirent = struct { type: u8, name: [256]u8, }; - -pub const speed_t = u32; -pub const tcflag_t = u32; - -pub const termios = extern struct { - iflag: tcflag_t, - oflag: tcflag_t, - cflag: tcflag_t, - lflag: tcflag_t, - line: std.c.cc_t, - cc: [std.c.NCCS]std.c.cc_t, - ispeed: speed_t, - ospeed: speed_t, -}; diff --git a/lib/std/c/haiku.zig b/lib/std/c/haiku.zig index f91625a0c3..723d953d2d 100644 --- a/lib/std/c/haiku.zig +++ b/lib/std/c/haiku.zig @@ -950,18 +950,4 @@ pub const directory_which = enum(c_int) { _, }; -pub const speed_t = u8; -pub const tcflag_t = u32; - -pub const termios = extern struct { - c_iflag: tcflag_t, - c_oflag: tcflag_t, - c_cflag: tcflag_t, - c_lflag: tcflag_t, - c_line: std.c.cc_t, - c_ispeed: speed_t, - c_ospeed: speed_t, - cc_t: [std.c.NCCS]std.c.cc_t, -}; - pub const MSG_NOSIGNAL = 0x0800; diff --git a/lib/std/c/linux.zig b/lib/std/c/linux.zig index dd26c9ccc3..45ced99e41 100644 --- a/lib/std/c/linux.zig +++ b/lib/std/c/linux.zig @@ -85,8 +85,6 @@ pub const sigset_t = linux.sigset_t; pub const sockaddr = linux.sockaddr; pub const socklen_t = linux.socklen_t; pub const stack_t = linux.stack_t; -pub const tcflag_t = linux.tcflag_t; -pub const termios = linux.termios; pub const time_t = linux.time_t; pub const timespec = linux.timespec; pub const timeval = linux.timeval; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index 9e232b1608..8f668beb63 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -850,19 +850,6 @@ pub const CDTRCTS: tcflag_t = 0x00020000; // DTR/CTS full-duplex flow control pub const MDMBUF: tcflag_t = 0x00100000; // DTR/DCD hardware flow control pub const CHWFLOW: tcflag_t = (MDMBUF | CRTSCTS | CDTRCTS); // all types of hw flow control -pub const tcflag_t = c_uint; -pub const speed_t = c_uint; - -pub const termios = extern struct { - iflag: tcflag_t, // input flags - oflag: tcflag_t, // output flags - cflag: tcflag_t, // control flags - lflag: tcflag_t, // local flags - cc: [std.c.NCCS]std.c.cc_t, // control chars - ispeed: c_int, // input speed - ospeed: c_int, // output speed -}; - // Commands passed to tcsetattr() for setting the termios structure. pub const TCSA = struct { pub const NOW = 0; // make change immediate diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index 135ad689a7..a8dc6e615d 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -768,9 +768,6 @@ pub const AUTH = struct { pub const ALLOW: c_int = (OKAY | ROOTOKAY | SECURE); }; -pub const tcflag_t = c_uint; -pub const speed_t = c_uint; - // Input flags - software input processing pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINT @@ -816,16 +813,6 @@ pub const CCTS_OFLOW: tcflag_t = CRTSCTS; // XXX compat pub const MDMBUF: tcflag_t = 0x00100000; // DTR/DCD hardware flow control pub const CHWFLOW: tcflag_t = (MDMBUF | CRTSCTS); // all types of hw flow control -pub const termios = extern struct { - iflag: tcflag_t, // input flags - oflag: tcflag_t, // output flags - cflag: tcflag_t, // control flags - lflag: tcflag_t, // local flags - cc: [std.c.NCCS]std.c.cc_t, // control chars - ispeed: c_int, // input speed - ospeed: c_int, // output speed -}; - // Commands passed to tcsetattr() for setting the termios structure. pub const TCSA = struct { pub const NOW = 0; // make change immediate diff --git a/lib/std/c/solaris.zig b/lib/std/c/solaris.zig index 7c094d2969..7cb35697d4 100644 --- a/lib/std/c/solaris.zig +++ b/lib/std/c/solaris.zig @@ -698,17 +698,6 @@ pub const SEEK = struct { pub const HOLE = 4; }; -pub const tcflag_t = c_uint; -pub const speed_t = c_uint; - -pub const termios = extern struct { - c_iflag: tcflag_t, - c_oflag: tcflag_t, - c_cflag: tcflag_t, - c_lflag: tcflag_t, - c_cc: [std.c.NCCS]std.c.cc_t, -}; - fn tioc(t: u16, num: u8) u16 { return (t << 8) | num; } diff --git a/lib/std/os.zig b/lib/std/os.zig index e948440994..f686e867ff 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -106,6 +106,7 @@ pub const MFD = system.MFD; pub const MMAP2_UNIT = system.MMAP2_UNIT; pub const MSG = system.MSG; pub const NAME_MAX = system.NAME_MAX; +pub const NCCS = system.NCCS; pub const O = system.O; pub const PATH_MAX = system.PATH_MAX; pub const POLL = system.POLL; @@ -172,6 +173,7 @@ pub const siginfo_t = system.siginfo_t; pub const sigset_t = system.sigset_t; pub const sockaddr = system.sockaddr; pub const socklen_t = system.socklen_t; +pub const speed_t = system.speed_t; pub const stack_t = system.stack_t; pub const tcflag_t = system.tcflag_t; pub const termios = system.termios; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 1dae5a7cc8..f2c3eaf3fd 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -5005,6 +5005,7 @@ pub const rusage = extern struct { }; pub const speed_t = u32; +pub const tcflag_t = u32; pub const NCCS = switch (native_arch) { .powerpc, .powerpcle, .powerpc64, .powerpc64le => 19, @@ -5044,88 +5045,7 @@ pub const B3000000 = 0o0010015; pub const B3500000 = 0o0010016; pub const B4000000 = 0o0010017; -pub const V = switch (native_arch) { - .powerpc, .powerpc64, .powerpc64le => struct { - pub const INTR = 0; - pub const QUIT = 1; - pub const ERASE = 2; - pub const KILL = 3; - pub const EOF = 4; - pub const MIN = 5; - pub const EOL = 6; - pub const TIME = 7; - pub const EOL2 = 8; - pub const SWTC = 9; - pub const WERASE = 10; - pub const REPRINT = 11; - pub const SUSP = 12; - pub const START = 13; - pub const STOP = 14; - pub const LNEXT = 15; - pub const DISCARD = 16; - }, - .sparc, .sparc64 => struct { - pub const INTR = 0; - pub const QUIT = 1; - pub const ERASE = 2; - pub const KILL = 3; - pub const EOF = 4; - pub const EOL = 5; - pub const EOL2 = 6; - pub const SWTC = 7; - pub const START = 8; - pub const STOP = 9; - pub const SUSP = 10; - pub const DSUSP = 11; - pub const REPRINT = 12; - pub const DISCARD = 13; - pub const WERASE = 14; - pub const LNEXT = 15; - pub const MIN = EOF; - pub const TIME = EOL; - }, - .mips, .mipsel, .mips64, .mips64el => struct { - pub const INTR = 0; - pub const QUIT = 1; - pub const ERASE = 2; - pub const KILL = 3; - pub const MIN = 4; - pub const TIME = 5; - pub const EOL2 = 6; - pub const SWTC = 7; - pub const SWTCH = 7; - pub const START = 8; - pub const STOP = 9; - pub const SUSP = 10; - pub const REPRINT = 12; - pub const DISCARD = 13; - pub const WERASE = 14; - pub const LNEXT = 15; - pub const EOF = 16; - pub const EOL = 17; - }, - else => struct { - pub const INTR = 0; - pub const QUIT = 1; - pub const ERASE = 2; - pub const KILL = 3; - pub const EOF = 4; - pub const TIME = 5; - pub const MIN = 6; - pub const SWTC = 7; - pub const START = 8; - pub const STOP = 9; - pub const SUSP = 10; - pub const EOL = 11; - pub const REPRINT = 12; - pub const DISCARD = 13; - pub const WERASE = 14; - pub const LNEXT = 15; - pub const EOL2 = 16; - }, -}; - -pub const tc_iflag_t = packed struct (u32) { +pub const tc_iflag_t = packed struct(u32) { IGNBRK: bool = false, BRKINT: bool = false, IGNPAR: bool = false, @@ -5145,42 +5065,42 @@ pub const tc_iflag_t = packed struct (u32) { }; pub const cc_t = switch (native_arch) { - .mips, .mipsel, .mips64, .mips64el => enum(u8){ - VINTR = 0, - VQUIT = 1, - VERASE = 2, - VKILL = 3, - VMIN = 4, - VTIME = 5, - VEOL2 = 6, - VSWTC = 7, - VSTART = 8, - VSTOP = 9, - VSUSP = 10, + .mips, .mipsel, .mips64, .mips64el => enum(u8) { + VINTR = 0, + VQUIT = 1, + VERASE = 2, + VKILL = 3, + VMIN = 4, + VTIME = 5, + VEOL2 = 6, + VSWTC = 7, + VSTART = 8, + VSTOP = 9, + VSUSP = 10, VREPRINT = 12, VDISCARD = 13, - VWERASE = 14, - VLNEXT = 15, - VEOF = 16, - VEOL = 17, + VWERASE = 14, + VLNEXT = 15, + VEOF = 16, + VEOL = 17, }, - .powerpc, .powerpc64, .powerpc64le => enum(u8) { - VINTR = 0, - VQUIT = 1, - VERASE = 2, - VKILL = 3, - VEOF = 4, - VMIN = 5, - VEOL = 6, - VTIME = 7, - VEOL2 = 8, - VSWTC = 9, - VWERASE = 10, + .powerpc, .powerpcle, .powerpc64, .powerpc64le => enum(u8) { + VINTR = 0, + VQUIT = 1, + VERASE = 2, + VKILL = 3, + VEOF = 4, + VMIN = 5, + VEOL = 6, + VTIME = 7, + VEOL2 = 8, + VSWTC = 9, + VWERASE = 10, VREPRINT = 11, - VSUSP = 12, - VSTART = 13, - VSTOP = 14, - VLNEXT = 15, + VSUSP = 12, + VSTART = 13, + VSTOP = 14, + VLNEXT = 15, VDISCARD = 16, }, else => enum(u8) { @@ -5246,15 +5166,27 @@ pub const TCSA = enum(c_uint) { _, }; -pub const termios = extern struct { - iflag: tc_iflag_t, - oflag: tc_oflag_t, - cflag: tc_cflag_t, - lflag: tc_lflag_t, - line: cc_t, - cc: [NCCS]cc_t, - ispeed: speed_t, - ospeed: speed_t, +pub const termios = switch (native_arch) { + .powerpc, .powerpcle, .powerpc64, .powerpc64le => extern struct { + iflag: tcflag_t, + oflag: tcflag_t, + cflag: tcflag_t, + lflag: tcflag_t, + cc: [NCCS]cc_t, + line: cc_t, + ispeed: speed_t, + ospeed: speed_t, + }, + else => extern struct { + iflag: tcflag_t, + oflag: tcflag_t, + cflag: tcflag_t, + lflag: tcflag_t, + line: cc_t, + cc: [NCCS]cc_t, + ispeed: speed_t, + ospeed: speed_t, + }, }; pub const SIOCGIFINDEX = 0x8933; From 47643cc5cc4db4c0fb2aaa7f37cedb049fce7def Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 16:43:51 -0700 Subject: [PATCH 05/11] std.os.termios: add type safety to iflag field This creates `tc_iflag_t` even though such a type is not defined by libc. I also collected the missing flag bits from all the operating systems. --- lib/std/c.zig | 120 ++++++++++++++++++++++++++++++++++++++++-- lib/std/c/darwin.zig | 15 ------ lib/std/c/netbsd.zig | 14 ----- lib/std/c/openbsd.zig | 15 ------ lib/std/os.zig | 8 +-- lib/std/os/linux.zig | 61 ++++++++++++++------- 6 files changed, 161 insertions(+), 72 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 9794e3560b..5a85d40b69 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -793,7 +793,7 @@ pub const NCCS = switch (native_os) { pub const termios = switch (native_os) { .linux => std.os.linux.termios, .macos, .ios, .tvos, .watchos => extern struct { - iflag: tcflag_t, + iflag: tc_iflag_t, oflag: tcflag_t, cflag: tcflag_t, lflag: tcflag_t, @@ -802,7 +802,7 @@ pub const termios = switch (native_os) { ospeed: speed_t, }, .freebsd, .kfreebsd, .netbsd, .dragonfly, .openbsd => extern struct { - iflag: tcflag_t, + iflag: tc_iflag_t, oflag: tcflag_t, cflag: tcflag_t, lflag: tcflag_t, @@ -811,7 +811,7 @@ pub const termios = switch (native_os) { ospeed: speed_t, }, .haiku => extern struct { - iflag: tcflag_t, + iflag: tc_iflag_t, oflag: tcflag_t, cflag: tcflag_t, lflag: tcflag_t, @@ -821,14 +821,14 @@ pub const termios = switch (native_os) { cc: [NCCS]cc_t, }, .solaris, .illumos => extern struct { - iflag: tcflag_t, + iflag: tc_iflag_t, oflag: tcflag_t, cflag: tcflag_t, lflag: tcflag_t, cc: [NCCS]cc_t, }, .emscripten, .wasi => extern struct { - iflag: tcflag_t, + iflag: tc_iflag_t, oflag: tcflag_t, cflag: tcflag_t, lflag: tcflag_t, @@ -840,6 +840,116 @@ pub const termios = switch (native_os) { else => @compileError("target libc does not have termios"), }; +pub const tc_iflag_t = switch (native_os) { + .linux => std.os.linux.tc_iflag_t, + .macos, .ios, .tvos, .watchos => packed struct(u32) { + IGNBRK: bool = false, + BRKINT: bool = false, + IGNPAR: bool = false, + PARMRK: bool = false, + INPCK: bool = false, + ISTRIP: bool = false, + INLCR: bool = false, + IGNCR: bool = false, + ICRNL: bool = false, + IXON: bool = false, + IXOFF: bool = false, + IXANY: bool = false, + _12: u1 = 0, + IMAXBEL: bool = false, + IUTF8: bool = false, + _: u17 = 0, + }, + .netbsd, .freebsd, .kfreebsd, .dragonfly => packed struct(u32) { + IGNBRK: bool = false, + BRKINT: bool = false, + IGNPAR: bool = false, + PARMRK: bool = false, + INPCK: bool = false, + ISTRIP: bool = false, + INLCR: bool = false, + IGNCR: bool = false, + ICRNL: bool = false, + IXON: bool = false, + IXOFF: bool = false, + IXANY: bool = false, + _12: u1 = 0, + IMAXBEL: bool = false, + _: u18 = 0, + }, + .openbsd => packed struct(u32) { + IGNBRK: bool = false, + BRKINT: bool = false, + IGNPAR: bool = false, + PARMRK: bool = false, + INPCK: bool = false, + ISTRIP: bool = false, + INLCR: bool = false, + IGNCR: bool = false, + ICRNL: bool = false, + IXON: bool = false, + IXOFF: bool = false, + IXANY: bool = false, + IUCLC: bool = false, + IMAXBEL: bool = false, + _: u18 = 0, + }, + .haiku => packed struct(u32) { + IGNBRK: bool = false, + BRKINT: bool = false, + IGNPAR: bool = false, + PARMRK: bool = false, + INPCK: bool = false, + ISTRIP: bool = false, + INLCR: bool = false, + IGNCR: bool = false, + ICRNL: bool = false, + IUCLC: bool = false, + IXON: bool = false, + IXANY: bool = false, + IXOFF: bool = false, + _: u19 = 0, + }, + .solaris, .illumos => packed struct(u32) { + IGNBRK: bool = false, + BRKINT: bool = false, + IGNPAR: bool = false, + PARMRK: bool = false, + INPCK: bool = false, + ISTRIP: bool = false, + INLCR: bool = false, + IGNCR: bool = false, + ICRNL: bool = false, + IUCLC: bool = false, + IXON: bool = false, + IXANY: bool = false, + _12: u1 = 0, + IMAXBEL: bool = false, + _14: u1 = 0, + DOSMODE: bool = false, + _: u16 = 0, + }, + .emscripten, .wasi => packed struct(u32) { + IGNBRK: bool = false, + BRKINT: bool = false, + IGNPAR: bool = false, + PARMRK: bool = false, + INPCK: bool = false, + ISTRIP: bool = false, + INLCR: bool = false, + IGNCR: bool = false, + ICRNL: bool = false, + IUCLC: bool = false, + IXON: bool = false, + IXANY: bool = false, + IXOFF: bool = false, + IMAXBEL: bool = false, + IUTF8: bool = false, + _: u17 = 0, + }, + else => @compileError("target libc does not have tc_iflag_t"), +}; + pub const tcflag_t = switch (native_os) { .linux => std.os.linux.tcflag_t, .macos, .ios, .tvos, .watchos => u64, diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 715678de22..d9e456921e 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -2692,21 +2692,6 @@ pub const SHUT = struct { pub const RDWR = 2; }; -pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition -pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINTR -pub const IGNPAR: tcflag_t = 0x00000004; // ignore (discard) parity errors -pub const PARMRK: tcflag_t = 0x00000008; // mark parity and framing errors -pub const INPCK: tcflag_t = 0x00000010; // enable checking of parity errors -pub const ISTRIP: tcflag_t = 0x00000020; // strip 8th bit off chars -pub const INLCR: tcflag_t = 0x00000040; // map NL into CR -pub const IGNCR: tcflag_t = 0x00000080; // ignore CR -pub const ICRNL: tcflag_t = 0x00000100; // map CR to NL (ala CRMOD) -pub const IXON: tcflag_t = 0x00000200; // enable output flow control -pub const IXOFF: tcflag_t = 0x00000400; // enable input flow control -pub const IXANY: tcflag_t = 0x00000800; // any char will restart after stop -pub const IMAXBEL: tcflag_t = 0x00002000; // ring bell on input queue full -pub const IUTF8: tcflag_t = 0x00004000; // maintain state for UTF-8 VERASE - pub const OPOST: tcflag_t = 0x00000001; //enable following output processing pub const ONLCR: tcflag_t = 0x00000002; // map NL to CR-NL (ala CRMOD) pub const OXTABS: tcflag_t = 0x00000004; // expand tabs to spaces diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index 8f668beb63..cdb0564973 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -806,20 +806,6 @@ pub const T = struct { pub const IOCXMTFRAME = 0x80087444; }; -// Input flags - software input processing -pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition -pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINT -pub const IGNPAR: tcflag_t = 0x00000004; // ignore (discard) parity errors -pub const PARMRK: tcflag_t = 0x00000008; // mark parity and framing errors -pub const INPCK: tcflag_t = 0x00000010; // enable checking of parity errors -pub const ISTRIP: tcflag_t = 0x00000020; // strip 8th bit off chars -pub const INLCR: tcflag_t = 0x00000040; // map NL into CR -pub const IGNCR: tcflag_t = 0x00000080; // ignore CR -pub const ICRNL: tcflag_t = 0x00000100; // map CR to NL (ala CRMOD) -pub const IXON: tcflag_t = 0x00000200; // enable output flow control -pub const IXOFF: tcflag_t = 0x00000400; // enable input flow control -pub const IXANY: tcflag_t = 0x00000800; // any char will restart after stop -pub const IMAXBEL: tcflag_t = 0x00002000; // ring bell on input queue full // Output flags - software output processing pub const OPOST: tcflag_t = 0x00000001; // enable following output processing diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index a8dc6e615d..1a0d788fb3 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -768,21 +768,6 @@ pub const AUTH = struct { pub const ALLOW: c_int = (OKAY | ROOTOKAY | SECURE); }; -// Input flags - software input processing -pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition -pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINT -pub const IGNPAR: tcflag_t = 0x00000004; // ignore (discard) parity errors -pub const PARMRK: tcflag_t = 0x00000008; // mark parity and framing errors -pub const INPCK: tcflag_t = 0x00000010; // enable checking of parity errors -pub const ISTRIP: tcflag_t = 0x00000020; // strip 8th bit off chars -pub const INLCR: tcflag_t = 0x00000040; // map NL into CR -pub const IGNCR: tcflag_t = 0x00000080; // ignore CR -pub const ICRNL: tcflag_t = 0x00000100; // map CR to NL (ala CRMOD) -pub const IXON: tcflag_t = 0x00000200; // enable output flow control -pub const IXOFF: tcflag_t = 0x00000400; // enable input flow control -pub const IXANY: tcflag_t = 0x00000800; // any char will restart after stop -pub const IUCLC: tcflag_t = 0x00001000; // translate upper to lower case -pub const IMAXBEL: tcflag_t = 0x00002000; // ring bell on input queue full // Output flags - software output processing pub const OPOST: tcflag_t = 0x00000001; // enable following output processing diff --git a/lib/std/os.zig b/lib/std/os.zig index f686e867ff..de994e4f14 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -106,7 +106,6 @@ pub const MFD = system.MFD; pub const MMAP2_UNIT = system.MMAP2_UNIT; pub const MSG = system.MSG; pub const NAME_MAX = system.NAME_MAX; -pub const NCCS = system.NCCS; pub const O = system.O; pub const PATH_MAX = system.PATH_MAX; pub const POLL = system.POLL; @@ -173,9 +172,7 @@ pub const siginfo_t = system.siginfo_t; pub const sigset_t = system.sigset_t; pub const sockaddr = system.sockaddr; pub const socklen_t = system.socklen_t; -pub const speed_t = system.speed_t; pub const stack_t = system.stack_t; -pub const tcflag_t = system.tcflag_t; pub const termios = system.termios; pub const time_t = system.time_t; pub const timespec = system.timespec; @@ -187,6 +184,11 @@ pub const uid_t = system.uid_t; pub const user_desc = system.user_desc; pub const utsname = system.utsname; +pub const NCCS = system.NCCS; +pub const speed_t = system.speed_t; +pub const tcflag_t = system.tcflag_t; +pub const tc_iflag_t = system.tc_iflag_t; + pub const F_OK = system.F_OK; pub const R_OK = system.R_OK; pub const W_OK = system.W_OK; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index f2c3eaf3fd..2c3254bd06 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -5005,7 +5005,6 @@ pub const rusage = extern struct { }; pub const speed_t = u32; -pub const tcflag_t = u32; pub const NCCS = switch (native_arch) { .powerpc, .powerpcle, .powerpc64, .powerpc64le => 19, @@ -5045,23 +5044,43 @@ pub const B3000000 = 0o0010015; pub const B3500000 = 0o0010016; pub const B4000000 = 0o0010017; -pub const tc_iflag_t = packed struct(u32) { - IGNBRK: bool = false, - BRKINT: bool = false, - IGNPAR: bool = false, - PARMRK: bool = false, - INPCK: bool = false, - ISTRIP: bool = false, - INLCR: bool = false, - IGNCR: bool = false, - ICRNL: bool = false, - IUCLC: bool = false, - IXON: bool = false, - IXANY: bool = false, - IXOFF: bool = false, - IMAXBEL: bool = false, - IUTF8: bool = false, - _: u17 = 0, +pub const tc_iflag_t = switch (native_arch) { + .powerpc, .powerpcle, .powerpc64, .powerpc64le => packed struct(u32) { + IGNBRK: bool = false, + BRKINT: bool = false, + IGNPAR: bool = false, + PARMRK: bool = false, + INPCK: bool = false, + ISTRIP: bool = false, + INLCR: bool = false, + IGNCR: bool = false, + ICRNL: bool = false, + IXON: bool = false, + IXOFF: bool = false, + IXANY: bool = false, + IUCLC: bool = false, + IMAXBEL: bool = false, + IUTF8: bool = false, + _: u17 = 0, + }, + else => packed struct(u32) { + IGNBRK: bool = false, + BRKINT: bool = false, + IGNPAR: bool = false, + PARMRK: bool = false, + INPCK: bool = false, + ISTRIP: bool = false, + INLCR: bool = false, + IGNCR: bool = false, + ICRNL: bool = false, + IUCLC: bool = false, + IXON: bool = false, + IXANY: bool = false, + IXOFF: bool = false, + IMAXBEL: bool = false, + IUTF8: bool = false, + _: u17 = 0, + }, }; pub const cc_t = switch (native_arch) { @@ -5124,6 +5143,8 @@ pub const cc_t = switch (native_arch) { }, }; +pub const tcflag_t = u32; + pub const OPOST: tcflag_t = 1; pub const OLCUC: tcflag_t = 2; pub const ONLCR: tcflag_t = 4; @@ -5168,7 +5189,7 @@ pub const TCSA = enum(c_uint) { pub const termios = switch (native_arch) { .powerpc, .powerpcle, .powerpc64, .powerpc64le => extern struct { - iflag: tcflag_t, + iflag: tc_iflag_t, oflag: tcflag_t, cflag: tcflag_t, lflag: tcflag_t, @@ -5178,7 +5199,7 @@ pub const termios = switch (native_arch) { ospeed: speed_t, }, else => extern struct { - iflag: tcflag_t, + iflag: tc_iflag_t, oflag: tcflag_t, cflag: tcflag_t, lflag: tcflag_t, From 20abc0caeeb8a9cc1cc1fe8c8ae318ec2906cc24 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 17:28:09 -0700 Subject: [PATCH 06/11] std.os.termios: add type safety to oflag field This creates `tc_oflag_t` even though such a type is not defined by libc. I also collected the missing flag bits from all the operating systems. --- lib/std/c.zig | 101 +++++++++++++++++++++++++++++++++++++++--- lib/std/c/darwin.zig | 36 --------------- lib/std/c/netbsd.zig | 9 ---- lib/std/c/openbsd.zig | 9 ---- lib/std/os.zig | 1 + lib/std/os/linux.zig | 54 +++++++++++++++------- 6 files changed, 136 insertions(+), 74 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 5a85d40b69..4333a191e6 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -794,7 +794,7 @@ pub const termios = switch (native_os) { .linux => std.os.linux.termios, .macos, .ios, .tvos, .watchos => extern struct { iflag: tc_iflag_t, - oflag: tcflag_t, + oflag: tc_oflag_t, cflag: tcflag_t, lflag: tcflag_t, cc: [NCCS]cc_t, @@ -803,7 +803,7 @@ pub const termios = switch (native_os) { }, .freebsd, .kfreebsd, .netbsd, .dragonfly, .openbsd => extern struct { iflag: tc_iflag_t, - oflag: tcflag_t, + oflag: tc_oflag_t, cflag: tcflag_t, lflag: tcflag_t, cc: [NCCS]cc_t, @@ -812,7 +812,7 @@ pub const termios = switch (native_os) { }, .haiku => extern struct { iflag: tc_iflag_t, - oflag: tcflag_t, + oflag: tc_oflag_t, cflag: tcflag_t, lflag: tcflag_t, line: cc_t, @@ -822,14 +822,14 @@ pub const termios = switch (native_os) { }, .solaris, .illumos => extern struct { iflag: tc_iflag_t, - oflag: tcflag_t, + oflag: tc_oflag_t, cflag: tcflag_t, lflag: tcflag_t, cc: [NCCS]cc_t, }, .emscripten, .wasi => extern struct { iflag: tc_iflag_t, - oflag: tcflag_t, + oflag: tc_oflag_t, cflag: tcflag_t, lflag: tcflag_t, line: std.c.cc_t, @@ -950,6 +950,97 @@ pub const tc_iflag_t = switch (native_os) { else => @compileError("target libc does not have tc_iflag_t"), }; +pub const tc_oflag_t = switch (native_os) { + .linux => std.os.linux.tc_oflag_t, + .macos, .ios, .tvos, .watchos => packed struct(u32) { + OPOST: bool = false, + ONLCR: bool = false, + OXTABS: bool = false, + ONOEOT: bool = false, + OCRNL: bool = false, + ONOCR: bool = false, + ONLRET: bool = false, + OFILL: bool = false, + NLDLY: u2 = 0, + TABDLY: u2 = 0, + CRDLY: u2 = 0, + FFDLY: u1 = 0, + BSDLY: u1 = 0, + VTDLY: u1 = 0, + OFDEL: bool = false, + _: u14 = 0, + }, + .netbsd => packed struct(u32) { + OPOST: bool = false, + ONLCR: bool = false, + OXTABS: bool = false, + ONOEOT: bool = false, + OCRNL: bool = false, + _5: u1 = 0, + ONOCR: bool = false, + ONLRET: bool = false, + _: u24 = 0, + }, + .openbsd => packed struct(u32) { + OPOST: bool = false, + ONLCR: bool = false, + OXTABS: bool = false, + ONOEOT: bool = false, + OCRNL: bool = false, + OLCUC: bool = false, + ONOCR: bool = false, + ONLRET: bool = false, + _: u24 = 0, + }, + .freebsd, .kfreebsd, .dragonfly => packed struct(u32) { + OPOST: bool = false, + ONLCR: bool = false, + _2: u1 = 0, + ONOEOT: bool = false, + OCRNL: bool = false, + ONOCR: bool = false, + ONLRET: bool = false, + _: u25 = 0, + }, + .solaris, .illumos => packed struct(u32) { + OPOST: bool = false, + OLCUC: bool = false, + ONLCR: bool = false, + OCRNL: bool = false, + ONOCR: bool = false, + ONLRET: bool = false, + OFILL: bool = false, + OFDEL: bool = false, + NLDLY: u1 = 0, + CRDLY: u2 = 0, + TABDLY: u2 = 0, + BSDLY: u1 = 0, + VTDLY: u1 = 0, + FFDLY: u1 = 0, + PAGEOUT: bool = false, + WRAP: bool = false, + _: u14 = 0, + }, + .haiku, .wasi, .emscripten => packed struct(u32) { + OPOST: bool = false, + OLCUC: bool = false, + ONLCR: bool = false, + OCRNL: bool = false, + ONOCR: bool = false, + ONLRET: bool = false, + OFILL: bool = false, + OFDEL: bool = false, + NLDLY: u1 = 0, + CRDLY: u2 = 0, + TABDLY: u2 = 0, + BSDLY: u1 = 0, + VTDLY: u1 = 0, + FFDLY: u1 = 0, + _: u16 = 0, + }, + else => @compileError("target libc does not have tc_oflag_t"), +}; + pub const tcflag_t = switch (native_os) { .linux => std.os.linux.tcflag_t, .macos, .ios, .tvos, .watchos => u64, diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index d9e456921e..489cdc8bc0 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -2692,42 +2692,6 @@ pub const SHUT = struct { pub const RDWR = 2; }; -pub const OPOST: tcflag_t = 0x00000001; //enable following output processing -pub const ONLCR: tcflag_t = 0x00000002; // map NL to CR-NL (ala CRMOD) -pub const OXTABS: tcflag_t = 0x00000004; // expand tabs to spaces -pub const ONOEOT: tcflag_t = 0x00000008; // discard EOT's (^D) on output) - -pub const OCRNL: tcflag_t = 0x00000010; // map CR to NL on output -pub const ONOCR: tcflag_t = 0x00000020; // no CR output at column 0 -pub const ONLRET: tcflag_t = 0x00000040; // NL performs CR function -pub const OFILL: tcflag_t = 0x00000080; // use fill characters for delay -pub const NLDLY: tcflag_t = 0x00000300; // \n delay -pub const TABDLY: tcflag_t = 0x00000c04; // horizontal tab delay -pub const CRDLY: tcflag_t = 0x00003000; // \r delay -pub const FFDLY: tcflag_t = 0x00004000; // form feed delay -pub const BSDLY: tcflag_t = 0x00008000; // \b delay -pub const VTDLY: tcflag_t = 0x00010000; // vertical tab delay -pub const OFDEL: tcflag_t = 0x00020000; // fill is DEL, else NUL - -pub const NL0: tcflag_t = 0x00000000; -pub const NL1: tcflag_t = 0x00000100; -pub const NL2: tcflag_t = 0x00000200; -pub const NL3: tcflag_t = 0x00000300; -pub const TAB0: tcflag_t = 0x00000000; -pub const TAB1: tcflag_t = 0x00000400; -pub const TAB2: tcflag_t = 0x00000800; -pub const TAB3: tcflag_t = 0x00000004; -pub const CR0: tcflag_t = 0x00000000; -pub const CR1: tcflag_t = 0x00001000; -pub const CR2: tcflag_t = 0x00002000; -pub const CR3: tcflag_t = 0x00003000; -pub const FF0: tcflag_t = 0x00000000; -pub const FF1: tcflag_t = 0x00004000; -pub const BS0: tcflag_t = 0x00000000; -pub const BS1: tcflag_t = 0x00008000; -pub const VT0: tcflag_t = 0x00000000; -pub const VT1: tcflag_t = 0x00010000; - pub const CIGNORE: tcflag_t = 0x00000001; // ignore control flags pub const CSIZE: tcflag_t = 0x00000300; // character size mask pub const CS5: tcflag_t = 0x00000000; // 5 bits (pseudo) diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index cdb0564973..989c579d0e 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -807,15 +807,6 @@ pub const T = struct { }; -// Output flags - software output processing -pub const OPOST: tcflag_t = 0x00000001; // enable following output processing -pub const ONLCR: tcflag_t = 0x00000002; // map NL to CR-NL (ala CRMOD) -pub const OXTABS: tcflag_t = 0x00000004; // expand tabs to spaces -pub const ONOEOT: tcflag_t = 0x00000008; // discard EOT's (^D) on output -pub const OCRNL: tcflag_t = 0x00000010; // map CR to NL -pub const ONOCR: tcflag_t = 0x00000040; // discard CR's when on column 0 -pub const ONLRET: tcflag_t = 0x00000080; // move to column 0 on CR - // Control flags - hardware control of terminal pub const CIGNORE: tcflag_t = 0x00000001; // ignore control flags pub const CSIZE: tcflag_t = 0x00000300; // character size mask diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index 1a0d788fb3..86130ed1a8 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -769,15 +769,6 @@ pub const AUTH = struct { }; -// Output flags - software output processing -pub const OPOST: tcflag_t = 0x00000001; // enable following output processing -pub const ONLCR: tcflag_t = 0x00000002; // map NL to CR-NL (ala CRMOD) -pub const OXTABS: tcflag_t = 0x00000004; // expand tabs to spaces -pub const ONOEOT: tcflag_t = 0x00000008; // discard EOT's (^D) on output -pub const OCRNL: tcflag_t = 0x00000010; // map CR to NL -pub const OLCUC: tcflag_t = 0x00000020; // translate lower case to upper case -pub const ONOCR: tcflag_t = 0x00000040; // No CR output at column 0 -pub const ONLRET: tcflag_t = 0x00000080; // NL performs the CR function // Control flags - hardware control of terminal pub const CIGNORE: tcflag_t = 0x00000001; // ignore control flags diff --git a/lib/std/os.zig b/lib/std/os.zig index de994e4f14..fcac0d1bb4 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -188,6 +188,7 @@ pub const NCCS = system.NCCS; pub const speed_t = system.speed_t; pub const tcflag_t = system.tcflag_t; pub const tc_iflag_t = system.tc_iflag_t; +pub const tc_oflag_t = system.tc_oflag_t; pub const F_OK = system.F_OK; pub const R_OK = system.R_OK; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 2c3254bd06..40a77d54e8 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -5083,6 +5083,43 @@ pub const tc_iflag_t = switch (native_arch) { }, }; +pub const tc_oflag_t = switch (native_arch) { + .powerpc, .powerpcle, .powerpc64, .powerpc64le => packed struct(u32) { + OPOST: bool = false, + ONLCR: bool = false, + OLCUC: bool = false, + OCRNL: bool = false, + ONOCR: bool = false, + ONLRET: bool = false, + OFILL: bool = false, + OFDEL: bool = false, + NLDLY: u2 = 0, + TABDLY: u2 = 0, + CRDLY: u2 = 0, + FFDLY: u1 = 0, + BSDLY: u1 = 0, + VTDLY: u1 = 0, + _: u15 = 0, + }, + else => packed struct(u32) { + OPOST: bool = false, + OLCUC: bool = false, + ONLCR: bool = false, + OCRNL: bool = false, + ONOCR: bool = false, + ONLRET: bool = false, + OFILL: bool = false, + OFDEL: bool = false, + NLDLY: u1 = 0, + CRDLY: u2 = 0, + TABDLY: u2 = 0, + BSDLY: u1 = 0, + VTDLY: u1 = 0, + FFDLY: u1 = 0, + _: u16 = 0, + }, +}; + pub const cc_t = switch (native_arch) { .mips, .mipsel, .mips64, .mips64el => enum(u8) { VINTR = 0, @@ -5145,19 +5182,6 @@ pub const cc_t = switch (native_arch) { pub const tcflag_t = u32; -pub const OPOST: tcflag_t = 1; -pub const OLCUC: tcflag_t = 2; -pub const ONLCR: tcflag_t = 4; -pub const OCRNL: tcflag_t = 8; -pub const ONOCR: tcflag_t = 16; -pub const ONLRET: tcflag_t = 32; -pub const OFILL: tcflag_t = 64; -pub const OFDEL: tcflag_t = 128; - -pub const VTDLY: tcflag_t = 16384; -pub const VT0: tcflag_t = 0; -pub const VT1: tcflag_t = 16384; - pub const CSIZE: tcflag_t = 48; pub const CS5: tcflag_t = 0; pub const CS6: tcflag_t = 16; @@ -5190,7 +5214,7 @@ pub const TCSA = enum(c_uint) { pub const termios = switch (native_arch) { .powerpc, .powerpcle, .powerpc64, .powerpc64le => extern struct { iflag: tc_iflag_t, - oflag: tcflag_t, + oflag: tc_oflag_t, cflag: tcflag_t, lflag: tcflag_t, cc: [NCCS]cc_t, @@ -5200,7 +5224,7 @@ pub const termios = switch (native_arch) { }, else => extern struct { iflag: tc_iflag_t, - oflag: tcflag_t, + oflag: tc_oflag_t, cflag: tcflag_t, lflag: tcflag_t, line: cc_t, From e97fa8b03803dfb5d2046d9b2ebecbee85a0e1f9 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 18:24:07 -0700 Subject: [PATCH 07/11] std.os.termios: add type safety to cflag field This creates `tc_cflag_t` even though such a type is not defined by libc. I also collected the missing flag bits from all the operating systems. --- lib/std/c.zig | 152 ++++++++++++++++++++++++++++++++++++++++-- lib/std/c/darwin.zig | 20 ------ lib/std/c/netbsd.zig | 21 ------ lib/std/c/openbsd.zig | 21 ------ lib/std/os.zig | 2 + lib/std/os/linux.zig | 43 ++++++++---- 6 files changed, 178 insertions(+), 81 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 4333a191e6..13d2605de0 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -795,7 +795,7 @@ pub const termios = switch (native_os) { .macos, .ios, .tvos, .watchos => extern struct { iflag: tc_iflag_t, oflag: tc_oflag_t, - cflag: tcflag_t, + cflag: tc_cflag_t, lflag: tcflag_t, cc: [NCCS]cc_t, ispeed: speed_t align(8), @@ -804,7 +804,7 @@ pub const termios = switch (native_os) { .freebsd, .kfreebsd, .netbsd, .dragonfly, .openbsd => extern struct { iflag: tc_iflag_t, oflag: tc_oflag_t, - cflag: tcflag_t, + cflag: tc_cflag_t, lflag: tcflag_t, cc: [NCCS]cc_t, ispeed: speed_t, @@ -813,7 +813,7 @@ pub const termios = switch (native_os) { .haiku => extern struct { iflag: tc_iflag_t, oflag: tc_oflag_t, - cflag: tcflag_t, + cflag: tc_cflag_t, lflag: tcflag_t, line: cc_t, ispeed: speed_t, @@ -823,14 +823,14 @@ pub const termios = switch (native_os) { .solaris, .illumos => extern struct { iflag: tc_iflag_t, oflag: tc_oflag_t, - cflag: tcflag_t, + cflag: tc_cflag_t, lflag: tcflag_t, cc: [NCCS]cc_t, }, .emscripten, .wasi => extern struct { iflag: tc_iflag_t, oflag: tc_oflag_t, - cflag: tcflag_t, + cflag: tc_cflag_t, lflag: tcflag_t, line: std.c.cc_t, cc: [NCCS]cc_t, @@ -1041,6 +1041,148 @@ pub const tc_oflag_t = switch (native_os) { else => @compileError("target libc does not have tc_oflag_t"), }; +pub const CSIZE = switch (native_os) { + .linux => std.os.linux.CSIZE, + .haiku => enum(u1) { CS7, CS8 }, + else => enum(u2) { CS5, CS6, CS7, CS8 }, +}; + +pub const tc_cflag_t = switch (native_os) { + .linux => std.os.linux.tc_cflag_t, + .macos, .ios, .tvos, .watchos => packed struct(u32) { + CIGNORE: bool = false, + _1: u5 = 0, + CSTOPB: bool = false, + _7: u1 = 0, + CSIZE: CSIZE = .CS5, + _10: u1 = 0, + CREAD: bool = false, + PARENB: bool = false, + PARODD: bool = false, + HUPCL: bool = false, + CLOCAL: bool = false, + CCTS_OFLOW: bool = false, + CRTS_IFLOW: bool = false, + CDTR_IFLOW: bool = false, + CDSR_OFLOW: bool = false, + CCAR_OFLOW: bool = false, + _: u11 = 0, + }, + .freebsd, .kfreebsd => packed struct(u32) { + CIGNORE: bool = false, + _1: u7 = 0, + CSIZE: CSIZE = .CS5, + CSTOPB: bool = false, + CREAD: bool = false, + PARENB: bool = false, + PARODD: bool = false, + HUPCL: bool = false, + CLOCAL: bool = false, + CCTS_OFLOW: bool = false, + CRTS_IFLOW: bool = false, + CDTR_IFLOW: bool = false, + CDSR_OFLOW: bool = false, + CCAR_OFLOW: bool = false, + CNO_RTSDTR: bool = false, + _: u10 = 0, + }, + .netbsd => packed struct(u32) { + CIGNORE: bool = false, + _1: u7 = 0, + CSIZE: CSIZE = .CS5, + CSTOPB: bool = false, + CREAD: bool = false, + PARENB: bool = false, + PARODD: bool = false, + HUPCL: bool = false, + CLOCAL: bool = false, + CRTSCTS: bool = false, + CDTRCTS: bool = false, + _18: u2 = 0, + MDMBUF: bool = false, + _: u11 = 0, + }, + .dragonfly => packed struct(u32) { + CIGNORE: bool = false, + _1: u7 = 0, + CSIZE: CSIZE = .CS5, + CSTOPB: bool = false, + CREAD: bool = false, + PARENB: bool = false, + PARODD: bool = false, + HUPCL: bool = false, + CLOCAL: bool = false, + CCTS_OFLOW: bool = false, + CRTS_IFLOW: bool = false, + CDTR_IFLOW: bool = false, + CDSR_OFLOW: bool = false, + CCAR_OFLOW: bool = false, + _: u11 = 0, + }, + .openbsd => packed struct(u32) { + CIGNORE: bool = false, + _1: u7 = 0, + CSIZE: CSIZE = .CS5, + CSTOPB: bool = false, + CREAD: bool = false, + PARENB: bool = false, + PARODD: bool = false, + HUPCL: bool = false, + CLOCAL: bool = false, + CRTSCTS: bool = false, + _17: u3 = 0, + MDMBUF: bool = false, + _: u11 = 0, + }, + .haiku => packed struct(u32) { + _0: u5 = 0, + CSIZE: CSIZE = .CS7, + CSTOPB: bool = false, + CREAD: bool = false, + PARENB: bool = false, + PARODD: bool = false, + HUPCL: bool = false, + CLOCAL: bool = false, + XLOBLK: bool = false, + CTSFLOW: bool = false, + RTSFLOW: bool = false, + _: u17 = 0, + }, + .solaris, .illumos => packed struct(u32) { + _0: u4 = 0, + CSIZE: CSIZE = .CS5, + CSTOPB: bool = false, + CREAD: bool = false, + PARENB: bool = false, + PARODD: bool = false, + HUPCL: bool = false, + CLOCAL: bool = false, + RCV1EN: bool = false, + XMT1EN: bool = false, + LOBLK: bool = false, + XCLUDE: bool = false, + _16: u4 = 0, + PAREXT: bool = false, + CBAUDEXT: bool = false, + CIBAUDEXT: bool = false, + _23: u7 = 0, + CRTSXOFF: bool = false, + CRTSCTS: bool = false, + }, + .wasi, .emscripten => packed struct(u32) { + _0: u4 = 0, + CSIZE: CSIZE = .CS5, + CSTOPB: bool = false, + CREAD: bool = false, + PARENB: bool = false, + PARODD: bool = false, + HUPCL: bool = false, + CLOCAL: bool = false, + _: u20 = 0, + }, + else => @compileError("target libc does not have tc_cflag_t"), +}; + pub const tcflag_t = switch (native_os) { .linux => std.os.linux.tcflag_t, .macos, .ios, .tvos, .watchos => u64, diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 489cdc8bc0..27ad3d68e6 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -2692,26 +2692,6 @@ pub const SHUT = struct { pub const RDWR = 2; }; -pub const CIGNORE: tcflag_t = 0x00000001; // ignore control flags -pub const CSIZE: tcflag_t = 0x00000300; // character size mask -pub const CS5: tcflag_t = 0x00000000; // 5 bits (pseudo) -pub const CS6: tcflag_t = 0x00000100; // 6 bits -pub const CS7: tcflag_t = 0x00000200; // 7 bits -pub const CS8: tcflag_t = 0x00000300; // 8 bits -pub const CSTOPB: tcflag_t = 0x0000040; // send 2 stop bits -pub const CREAD: tcflag_t = 0x00000800; // enable receiver -pub const PARENB: tcflag_t = 0x00001000; // parity enable -pub const PARODD: tcflag_t = 0x00002000; // odd parity, else even -pub const HUPCL: tcflag_t = 0x00004000; // hang up on last close -pub const CLOCAL: tcflag_t = 0x00008000; // ignore modem status lines -pub const CCTS_OFLOW: tcflag_t = 0x00010000; // CTS flow control of output -pub const CRTSCTS: tcflag_t = (CCTS_OFLOW | CRTS_IFLOW); -pub const CRTS_IFLOW: tcflag_t = 0x00020000; // RTS flow control of input -pub const CDTR_IFLOW: tcflag_t = 0x00040000; // DTR flow control of input -pub const CDSR_OFLOW: tcflag_t = 0x00080000; // DSR flow control of output -pub const CCAR_OFLOW: tcflag_t = 0x00100000; // DCD flow control of output -pub const MDMBUF: tcflag_t = 0x00100000; // old name for CCAR_OFLOW - pub const ECHOKE: tcflag_t = 0x00000001; // visual erase for line kill pub const ECHOE: tcflag_t = 0x00000002; // visually erase chars pub const ECHOK: tcflag_t = 0x00000004; // echo NL after line kill diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index 989c579d0e..b5c132df12 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -806,27 +806,6 @@ pub const T = struct { pub const IOCXMTFRAME = 0x80087444; }; - -// Control flags - hardware control of terminal -pub const CIGNORE: tcflag_t = 0x00000001; // ignore control flags -pub const CSIZE: tcflag_t = 0x00000300; // character size mask -pub const CS5: tcflag_t = 0x00000000; // 5 bits (pseudo) -pub const CS6: tcflag_t = 0x00000100; // 6 bits -pub const CS7: tcflag_t = 0x00000200; // 7 bits -pub const CS8: tcflag_t = 0x00000300; // 8 bits -pub const CSTOPB: tcflag_t = 0x00000400; // send 2 stop bits -pub const CREAD: tcflag_t = 0x00000800; // enable receiver -pub const PARENB: tcflag_t = 0x00001000; // parity enable -pub const PARODD: tcflag_t = 0x00002000; // odd parity, else even -pub const HUPCL: tcflag_t = 0x00004000; // hang up on last close -pub const CLOCAL: tcflag_t = 0x00008000; // ignore modem status lines -pub const CRTSCTS: tcflag_t = 0x00010000; // RTS/CTS full-duplex flow control -pub const CRTS_IFLOW: tcflag_t = CRTSCTS; // XXX compat -pub const CCTS_OFLOW: tcflag_t = CRTSCTS; // XXX compat -pub const CDTRCTS: tcflag_t = 0x00020000; // DTR/CTS full-duplex flow control -pub const MDMBUF: tcflag_t = 0x00100000; // DTR/DCD hardware flow control -pub const CHWFLOW: tcflag_t = (MDMBUF | CRTSCTS | CDTRCTS); // all types of hw flow control - // Commands passed to tcsetattr() for setting the termios structure. pub const TCSA = struct { pub const NOW = 0; // make change immediate diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index 86130ed1a8..8d1df592d7 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -768,27 +768,6 @@ pub const AUTH = struct { pub const ALLOW: c_int = (OKAY | ROOTOKAY | SECURE); }; - - -// Control flags - hardware control of terminal -pub const CIGNORE: tcflag_t = 0x00000001; // ignore control flags -pub const CSIZE: tcflag_t = 0x00000300; // character size mask -pub const CS5: tcflag_t = 0x00000000; // 5 bits (pseudo) -pub const CS6: tcflag_t = 0x00000100; // 6 bits -pub const CS7: tcflag_t = 0x00000200; // 7 bits -pub const CS8: tcflag_t = 0x00000300; // 8 bits -pub const CSTOPB: tcflag_t = 0x00000400; // send 2 stop bits -pub const CREAD: tcflag_t = 0x00000800; // enable receiver -pub const PARENB: tcflag_t = 0x00001000; // parity enable -pub const PARODD: tcflag_t = 0x00002000; // odd parity, else even -pub const HUPCL: tcflag_t = 0x00004000; // hang up on last close -pub const CLOCAL: tcflag_t = 0x00008000; // ignore modem status lines -pub const CRTSCTS: tcflag_t = 0x00010000; // RTS/CTS full-duplex flow control -pub const CRTS_IFLOW: tcflag_t = CRTSCTS; // XXX compat -pub const CCTS_OFLOW: tcflag_t = CRTSCTS; // XXX compat -pub const MDMBUF: tcflag_t = 0x00100000; // DTR/DCD hardware flow control -pub const CHWFLOW: tcflag_t = (MDMBUF | CRTSCTS); // all types of hw flow control - // Commands passed to tcsetattr() for setting the termios structure. pub const TCSA = struct { pub const NOW = 0; // make change immediate diff --git a/lib/std/os.zig b/lib/std/os.zig index fcac0d1bb4..2db77ea980 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -184,11 +184,13 @@ pub const uid_t = system.uid_t; pub const user_desc = system.user_desc; pub const utsname = system.utsname; +pub const CSIZE = system.CSIZE; pub const NCCS = system.NCCS; pub const speed_t = system.speed_t; pub const tcflag_t = system.tcflag_t; pub const tc_iflag_t = system.tc_iflag_t; pub const tc_oflag_t = system.tc_oflag_t; +pub const tc_cflag_t = system.tc_cflag_t; pub const F_OK = system.F_OK; pub const R_OK = system.R_OK; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 40a77d54e8..42ab82b2ab 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -5120,6 +5120,33 @@ pub const tc_oflag_t = switch (native_arch) { }, }; +pub const CSIZE = enum(u2) { CS5, CS6, CS7, CS8 }; + +pub const tc_cflag_t = switch (native_arch) { + .powerpc, .powerpcle, .powerpc64, .powerpc64le => packed struct(u32) { + _0: u8 = 0, + CSIZE: CSIZE = .CS5, + CSTOPB: bool = false, + CREAD: bool = false, + PARENB: bool = false, + PARODD: bool = false, + HUPCL: bool = false, + CLOCAL: bool = false, + _: u16 = 0, + }, + else => packed struct(u32) { + _0: u4 = 0, + CSIZE: CSIZE = .CS5, + CSTOPB: bool = false, + CREAD: bool = false, + PARENB: bool = false, + PARODD: bool = false, + HUPCL: bool = false, + CLOCAL: bool = false, + _: u20 = 0, + }, +}; + pub const cc_t = switch (native_arch) { .mips, .mipsel, .mips64, .mips64el => enum(u8) { VINTR = 0, @@ -5182,18 +5209,6 @@ pub const cc_t = switch (native_arch) { pub const tcflag_t = u32; -pub const CSIZE: tcflag_t = 48; -pub const CS5: tcflag_t = 0; -pub const CS6: tcflag_t = 16; -pub const CS7: tcflag_t = 32; -pub const CS8: tcflag_t = 48; -pub const CSTOPB: tcflag_t = 64; -pub const CREAD: tcflag_t = 128; -pub const PARENB: tcflag_t = 256; -pub const PARODD: tcflag_t = 512; -pub const HUPCL: tcflag_t = 1024; -pub const CLOCAL: tcflag_t = 2048; - pub const ISIG: tcflag_t = 1; pub const ICANON: tcflag_t = 2; pub const ECHO: tcflag_t = 8; @@ -5215,7 +5230,7 @@ pub const termios = switch (native_arch) { .powerpc, .powerpcle, .powerpc64, .powerpc64le => extern struct { iflag: tc_iflag_t, oflag: tc_oflag_t, - cflag: tcflag_t, + cflag: tc_cflag_t, lflag: tcflag_t, cc: [NCCS]cc_t, line: cc_t, @@ -5225,7 +5240,7 @@ pub const termios = switch (native_arch) { else => extern struct { iflag: tc_iflag_t, oflag: tc_oflag_t, - cflag: tcflag_t, + cflag: tc_cflag_t, lflag: tcflag_t, line: cc_t, cc: [NCCS]cc_t, From a280ff2767cbb8da1a10d70eaddb0d6c0730443f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 21:21:45 -0700 Subject: [PATCH 08/11] std.os.termios: add type safety to lflag field This creates `tc_cflag_t` even though such a type is not defined by libc. I also collected the missing flag bits from all the operating systems. --- lib/std/c.zig | 122 +++++++++++++++++++++++++++++++++++++------ lib/std/c/darwin.zig | 56 -------------------- lib/std/os.zig | 2 +- lib/std/os/linux.zig | 63 +++++++++++++++++----- 4 files changed, 155 insertions(+), 88 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 13d2605de0..23e586fd20 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -796,7 +796,7 @@ pub const termios = switch (native_os) { iflag: tc_iflag_t, oflag: tc_oflag_t, cflag: tc_cflag_t, - lflag: tcflag_t, + lflag: tc_lflag_t, cc: [NCCS]cc_t, ispeed: speed_t align(8), ospeed: speed_t, @@ -805,7 +805,7 @@ pub const termios = switch (native_os) { iflag: tc_iflag_t, oflag: tc_oflag_t, cflag: tc_cflag_t, - lflag: tcflag_t, + lflag: tc_lflag_t, cc: [NCCS]cc_t, ispeed: speed_t, ospeed: speed_t, @@ -814,7 +814,7 @@ pub const termios = switch (native_os) { iflag: tc_iflag_t, oflag: tc_oflag_t, cflag: tc_cflag_t, - lflag: tcflag_t, + lflag: tc_lflag_t, line: cc_t, ispeed: speed_t, ospeed: speed_t, @@ -824,14 +824,14 @@ pub const termios = switch (native_os) { iflag: tc_iflag_t, oflag: tc_oflag_t, cflag: tc_cflag_t, - lflag: tcflag_t, + lflag: tc_lflag_t, cc: [NCCS]cc_t, }, .emscripten, .wasi => extern struct { iflag: tc_iflag_t, oflag: tc_oflag_t, cflag: tc_cflag_t, - lflag: tcflag_t, + lflag: tc_lflag_t, line: std.c.cc_t, cc: [NCCS]cc_t, ispeed: speed_t, @@ -1183,18 +1183,106 @@ pub const tc_cflag_t = switch (native_os) { else => @compileError("target libc does not have tc_cflag_t"), }; -pub const tcflag_t = switch (native_os) { - .linux => std.os.linux.tcflag_t, - .macos, .ios, .tvos, .watchos => u64, - .freebsd, .kfreebsd => c_uint, - .netbsd => c_uint, - .dragonfly => c_uint, - .openbsd => c_uint, - .haiku => u32, - .solaris, .illumos => c_uint, - .emscripten => u32, - .wasi => c_uint, - else => @compileError("target libc does not have tcflag_t"), +pub const tc_lflag_t = switch (native_os) { + .linux => std.os.linux.tc_lflag_t, + .macos, .ios, .tvos, .watchos, .netbsd, .freebsd, .kfreebsd, .dragonfly => packed struct(u32) { + ECHOKE: bool = false, + ECHOE: bool = false, + ECHOK: bool = false, + ECHO: bool = false, + ECHONL: bool = false, + ECHOPRT: bool = false, + ECHOCTL: bool = false, + ISIG: bool = false, + ICANON: bool = false, + ALTWERASE: bool = false, + IEXTEN: bool = false, + EXTPROC: bool = false, + _12: u10 = 0, + TOSTOP: bool = false, + FLUSHO: bool = false, + _24: u1 = 0, + NOKERNINFO: bool = false, + _26: u3 = 0, + PENDIN: bool = false, + _30: u1 = 0, + NOFLSH: bool = false, + }, + .openbsd => packed struct(u32) { + ECHOKE: bool = false, + ECHOE: bool = false, + ECHOK: bool = false, + ECHO: bool = false, + ECHONL: bool = false, + ECHOPRT: bool = false, + ECHOCTL: bool = false, + ISIG: bool = false, + ICANON: bool = false, + ALTWERASE: bool = false, + IEXTEN: bool = false, + EXTPROC: bool = false, + _12: u10 = 0, + TOSTOP: bool = false, + FLUSHO: bool = false, + XCASE: bool = false, + NOKERNINFO: bool = false, + _26: u3 = 0, + PENDIN: bool = false, + _30: u1 = 0, + NOFLSH: bool = false, + }, + .haiku => packed struct(u32) { + ISIG: bool = false, + ICANON: bool = false, + XCASE: bool = false, + ECHO: bool = false, + ECHOE: bool = false, + ECHOK: bool = false, + ECHONL: bool = false, + NOFLSH: bool = false, + TOSTOP: bool = false, + IEXTEN: bool = false, + ECHOCTL: bool = false, + ECHOPRT: bool = false, + ECHOKE: bool = false, + FLUSHO: bool = false, + PENDIN: bool = false, + _: u17 = 0, + }, + .solaris, .illumos => packed struct(u32) { + ISIG: bool = false, + ICANON: bool = false, + XCASE: bool = false, + ECHO: bool = false, + ECHOE: bool = false, + ECHOK: bool = false, + ECHONL: bool = false, + NOFLSH: bool = false, + TOSTOP: bool = false, + ECHOCTL: bool = false, + ECHOPRT: bool = false, + ECHOKE: bool = false, + DEFECHO: bool = false, + FLUSHO: bool = false, + PENDIN: bool = false, + IEXTEN: bool = false, + _: u16 = 0, + }, + .wasi, .emscripten => packed struct(u32) { + ISIG: bool = false, + ICANON: bool = false, + _2: u1 = 0, + ECHO: bool = false, + ECHOE: bool = false, + ECHOK: bool = false, + ECHONL: bool = false, + NOFLSH: bool = false, + TOSTOP: bool = false, + _9: u6 = 0, + IEXTEN: bool = false, + _: u16 = 0, + }, + else => @compileError("target libc does not have tc_lflag_t"), }; pub const speed_t = switch (native_os) { diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 27ad3d68e6..947abe58c9 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -2692,28 +2692,6 @@ pub const SHUT = struct { pub const RDWR = 2; }; -pub const ECHOKE: tcflag_t = 0x00000001; // visual erase for line kill -pub const ECHOE: tcflag_t = 0x00000002; // visually erase chars -pub const ECHOK: tcflag_t = 0x00000004; // echo NL after line kill -pub const ECHO: tcflag_t = 0x00000008; // enable echoing -pub const ECHONL: tcflag_t = 0x00000010; // echo NL even if ECHO is off -pub const ECHOPRT: tcflag_t = 0x00000020; // visual erase mode for hardcopy -pub const ECHOCTL: tcflag_t = 0x00000040; // echo control chars as ^(Char) -pub const ISIG: tcflag_t = 0x00000080; // enable signals INTR, QUIT, [D]SUSP -pub const ICANON: tcflag_t = 0x00000100; // canonicalize input lines -pub const ALTWERASE: tcflag_t = 0x00000200; // use alternate WERASE algorithm -pub const IEXTEN: tcflag_t = 0x00000400; // enable DISCARD and LNEXT -pub const EXTPROC: tcflag_t = 0x00000800; // external processing -pub const TOSTOP: tcflag_t = 0x00400000; // stop background jobs from output -pub const FLUSHO: tcflag_t = 0x00800000; // output being flushed (state) -pub const NOKERNINFO: tcflag_t = 0x02000000; // no kernel output from VSTATUS -pub const PENDIN: tcflag_t = 0x20000000; // XXX retype pending input (state) -pub const NOFLSH: tcflag_t = 0x80000000; // don't flush after interrupt - -pub const TCSANOW: tcflag_t = 0; // make change immediate -pub const TCSADRAIN: tcflag_t = 1; // drain output, then change -pub const TCSAFLUSH: tcflag_t = 2; // drain output, flush input -pub const TCSASOFT: tcflag_t = 0x10; // flag - don't alter h.w. state pub const TCSA = enum(c_uint) { NOW, DRAIN, @@ -2721,40 +2699,6 @@ pub const TCSA = enum(c_uint) { _, }; -pub const B0: tcflag_t = 0; -pub const B50: tcflag_t = 50; -pub const B75: tcflag_t = 75; -pub const B110: tcflag_t = 110; -pub const B134: tcflag_t = 134; -pub const B150: tcflag_t = 150; -pub const B200: tcflag_t = 200; -pub const B300: tcflag_t = 300; -pub const B600: tcflag_t = 600; -pub const B1200: tcflag_t = 1200; -pub const B1800: tcflag_t = 1800; -pub const B2400: tcflag_t = 2400; -pub const B4800: tcflag_t = 4800; -pub const B9600: tcflag_t = 9600; -pub const B19200: tcflag_t = 19200; -pub const B38400: tcflag_t = 38400; -pub const B7200: tcflag_t = 7200; -pub const B14400: tcflag_t = 14400; -pub const B28800: tcflag_t = 28800; -pub const B57600: tcflag_t = 57600; -pub const B76800: tcflag_t = 76800; -pub const B115200: tcflag_t = 115200; -pub const B230400: tcflag_t = 230400; -pub const EXTA: tcflag_t = 19200; -pub const EXTB: tcflag_t = 38400; - -pub const TCIFLUSH: tcflag_t = 1; -pub const TCOFLUSH: tcflag_t = 2; -pub const TCIOFLUSH: tcflag_t = 3; -pub const TCOOFF: tcflag_t = 1; -pub const TCOON: tcflag_t = 2; -pub const TCIOFF: tcflag_t = 3; -pub const TCION: tcflag_t = 4; - pub const winsize = extern struct { ws_row: u16, ws_col: u16, diff --git a/lib/std/os.zig b/lib/std/os.zig index 2db77ea980..5ed36b353e 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -187,10 +187,10 @@ pub const utsname = system.utsname; pub const CSIZE = system.CSIZE; pub const NCCS = system.NCCS; pub const speed_t = system.speed_t; -pub const tcflag_t = system.tcflag_t; pub const tc_iflag_t = system.tc_iflag_t; pub const tc_oflag_t = system.tc_oflag_t; pub const tc_cflag_t = system.tc_cflag_t; +pub const tc_lflag_t = system.tc_lflag_t; pub const F_OK = system.F_OK; pub const R_OK = system.R_OK; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 42ab82b2ab..4a3ed67cc5 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -5147,6 +5147,53 @@ pub const tc_cflag_t = switch (native_arch) { }, }; +pub const tc_lflag_t = switch (native_arch) { + .powerpc, .powerpcle, .powerpc64, .powerpc64le => packed struct(u32) { + _0: u1 = 0, + ECHOE: bool = false, + ECHOK: bool = false, + ECHO: bool = false, + ECHONL: bool = false, + _5: u2 = 0, + ISIG: bool = false, + ICANON: bool = false, + _9: u1 = 0, + IEXTEN: bool = false, + _11: u11 = 0, + TOSTOP: bool = false, + _23: u8 = 0, + NOFLSH: bool = false, + }, + .mips, .mipsel, .mips64, .mips64el => packed struct(u32) { + ISIG: bool = false, + ICANON: bool = false, + _2: u1 = 0, + ECHO: bool = false, + ECHOE: bool = false, + ECHOK: bool = false, + ECHONL: bool = false, + NOFLSH: bool = false, + IEXTEN: bool = false, + _9: u6 = 0, + TOSTOP: bool = false, + _: u16 = 0, + }, + else => packed struct(u32) { + ISIG: bool = false, + ICANON: bool = false, + _2: u1 = 0, + ECHO: bool = false, + ECHOE: bool = false, + ECHOK: bool = false, + ECHONL: bool = false, + NOFLSH: bool = false, + TOSTOP: bool = false, + _9: u6 = 0, + IEXTEN: bool = false, + _: u16 = 0, + }, +}; + pub const cc_t = switch (native_arch) { .mips, .mipsel, .mips64, .mips64el => enum(u8) { VINTR = 0, @@ -5207,18 +5254,6 @@ pub const cc_t = switch (native_arch) { }, }; -pub const tcflag_t = u32; - -pub const ISIG: tcflag_t = 1; -pub const ICANON: tcflag_t = 2; -pub const ECHO: tcflag_t = 8; -pub const ECHOE: tcflag_t = 16; -pub const ECHOK: tcflag_t = 32; -pub const ECHONL: tcflag_t = 64; -pub const NOFLSH: tcflag_t = 128; -pub const TOSTOP: tcflag_t = 256; -pub const IEXTEN: tcflag_t = 32768; - pub const TCSA = enum(c_uint) { NOW, DRAIN, @@ -5231,7 +5266,7 @@ pub const termios = switch (native_arch) { iflag: tc_iflag_t, oflag: tc_oflag_t, cflag: tc_cflag_t, - lflag: tcflag_t, + lflag: tc_lflag_t, cc: [NCCS]cc_t, line: cc_t, ispeed: speed_t, @@ -5241,7 +5276,7 @@ pub const termios = switch (native_arch) { iflag: tc_iflag_t, oflag: tc_oflag_t, cflag: tc_cflag_t, - lflag: tcflag_t, + lflag: tc_lflag_t, line: cc_t, cc: [NCCS]cc_t, ispeed: speed_t, From ae107cf71bd7bb79ed25ce76999b70936ee2a5ec Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 21:49:09 -0700 Subject: [PATCH 09/11] std.os.speed_t: add type safety and collect the missing flag bits from all the operating systems. --- lib/std/c.zig | 280 ++++++++++++++++++++++++++++++++++++++++-- lib/std/c/netbsd.zig | 37 ------ lib/std/c/openbsd.zig | 27 ---- lib/std/os/linux.zig | 104 +++++++++++----- 4 files changed, 341 insertions(+), 107 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 23e586fd20..140ff011aa 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -1287,15 +1287,277 @@ pub const tc_lflag_t = switch (native_os) { pub const speed_t = switch (native_os) { .linux => std.os.linux.speed_t, - .macos, .ios, .tvos, .watchos => u64, - .freebsd, .kfreebsd => c_uint, - .netbsd => c_uint, - .dragonfly => c_uint, - .openbsd => c_uint, - .haiku => u8, - .solaris, .illumos => c_uint, - .emscripten => u32, - .wasi => c_uint, + .macos, .ios, .tvos, .watchos => enum(u64) { + B0 = 0, + B50 = 50, + B75 = 75, + B110 = 110, + B134 = 134, + B150 = 150, + B200 = 200, + B300 = 300, + B600 = 600, + B1200 = 1200, + B1800 = 1800, + B2400 = 2400, + B4800 = 4800, + B9600 = 9600, + B19200 = 19200, + B38400 = 38400, + B7200 = 7200, + B14400 = 14400, + B28800 = 28800, + B57600 = 57600, + B76800 = 76800, + B115200 = 115200, + B230400 = 230400, + }, + .freebsd, .kfreebsd => enum(c_uint) { + B0 = 0, + B50 = 50, + B75 = 75, + B110 = 110, + B134 = 134, + B150 = 150, + B200 = 200, + B300 = 300, + B600 = 600, + B1200 = 1200, + B1800 = 1800, + B2400 = 2400, + B4800 = 4800, + B9600 = 9600, + B19200 = 19200, + B38400 = 38400, + B7200 = 7200, + B14400 = 14400, + B28800 = 28800, + B57600 = 57600, + B76800 = 76800, + B115200 = 115200, + B230400 = 230400, + B460800 = 460800, + B500000 = 500000, + B921600 = 921600, + B1000000 = 1000000, + B1500000 = 1500000, + B2000000 = 2000000, + B2500000 = 2500000, + B3000000 = 3000000, + B3500000 = 3500000, + B4000000 = 4000000, + }, + .netbsd => enum(c_uint) { + B0 = 0, + B50 = 50, + B75 = 75, + B110 = 110, + B134 = 134, + B150 = 150, + B200 = 200, + B300 = 300, + B600 = 600, + B1200 = 1200, + B1800 = 1800, + B2400 = 2400, + B4800 = 4800, + B9600 = 9600, + B19200 = 19200, + B38400 = 38400, + B7200 = 7200, + B14400 = 14400, + B28800 = 28800, + B57600 = 57600, + B76800 = 76800, + B115200 = 115200, + B230400 = 230400, + B460800 = 460800, + B500000 = 500000, + B921600 = 921600, + B1000000 = 1000000, + B1500000 = 1500000, + B2000000 = 2000000, + B2500000 = 2500000, + B3000000 = 3000000, + B3500000 = 3500000, + B4000000 = 4000000, + }, + .dragonfly => enum(c_uint) { + B0 = 0, + B50 = 50, + B75 = 75, + B110 = 110, + B134 = 134, + B150 = 150, + B200 = 200, + B300 = 300, + B600 = 600, + B1200 = 1200, + B1800 = 1800, + B2400 = 2400, + B4800 = 4800, + B9600 = 9600, + B19200 = 19200, + B38400 = 38400, + B7200 = 7200, + B14400 = 14400, + B28800 = 28800, + B57600 = 57600, + B76800 = 76800, + B115200 = 115200, + B230400 = 230400, + B460800 = 460800, + B921600 = 921600, + }, + .openbsd => enum(c_uint) { + B0 = 0, + B50 = 50, + B75 = 75, + B110 = 110, + B134 = 134, + B150 = 150, + B200 = 200, + B300 = 300, + B600 = 600, + B1200 = 1200, + B1800 = 1800, + B2400 = 2400, + B4800 = 4800, + B9600 = 9600, + B19200 = 19200, + B38400 = 38400, + B7200 = 7200, + B14400 = 14400, + B28800 = 28800, + B57600 = 57600, + B76800 = 76800, + B115200 = 115200, + B230400 = 230400, + }, + .haiku => enum(u8) { + B0 = 0x00, + B50 = 0x01, + B75 = 0x02, + B110 = 0x03, + B134 = 0x04, + B150 = 0x05, + B200 = 0x06, + B300 = 0x07, + B600 = 0x08, + B1200 = 0x09, + B1800 = 0x0A, + B2400 = 0x0B, + B4800 = 0x0C, + B9600 = 0x0D, + B19200 = 0x0E, + B38400 = 0x0F, + B57600 = 0x10, + B115200 = 0x11, + B230400 = 0x12, + B31250 = 0x13, + }, + .solaris, .illumos => enum(c_uint) { + B0 = 0, + B50 = 1, + B75 = 2, + B110 = 3, + B134 = 4, + B150 = 5, + B200 = 6, + B300 = 7, + B600 = 8, + B1200 = 9, + B1800 = 10, + B2400 = 11, + B4800 = 12, + B9600 = 13, + B19200 = 14, + B38400 = 15, + B57600 = 16, + B76800 = 17, + B115200 = 18, + B153600 = 19, + B230400 = 20, + B307200 = 21, + B460800 = 22, + B921600 = 23, + B1000000 = 24, + B1152000 = 25, + B1500000 = 26, + B2000000 = 27, + B2500000 = 28, + B3000000 = 29, + B3500000 = 30, + B4000000 = 31, + }, + .emscripten => enum(u32) { + B0 = 0o0000000, + B50 = 0o0000001, + B75 = 0o0000002, + B110 = 0o0000003, + B134 = 0o0000004, + B150 = 0o0000005, + B200 = 0o0000006, + B300 = 0o0000007, + B600 = 0o0000010, + B1200 = 0o0000011, + B1800 = 0o0000012, + B2400 = 0o0000013, + B4800 = 0o0000014, + B9600 = 0o0000015, + B19200 = 0o0000016, + B38400 = 0o0000017, + + B57600 = 0o0010001, + B115200 = 0o0010002, + B230400 = 0o0010003, + B460800 = 0o0010004, + B500000 = 0o0010005, + B576000 = 0o0010006, + B921600 = 0o0010007, + B1000000 = 0o0010010, + B1152000 = 0o0010011, + B1500000 = 0o0010012, + B2000000 = 0o0010013, + B2500000 = 0o0010014, + B3000000 = 0o0010015, + B3500000 = 0o0010016, + B4000000 = 0o0010017, + }, + .wasi => enum(u32) { + B0 = 0o0000000, + B50 = 0o0000001, + B75 = 0o0000002, + B110 = 0o0000003, + B134 = 0o0000004, + B150 = 0o0000005, + B200 = 0o0000006, + B300 = 0o0000007, + B600 = 0o0000010, + B1200 = 0o0000011, + B1800 = 0o0000012, + B2400 = 0o0000013, + B4800 = 0o0000014, + B9600 = 0o0000015, + B19200 = 0o0000016, + B38400 = 0o0000017, + + B57600 = 0o0010001, + B115200 = 0o0010002, + B230400 = 0o0010003, + B460800 = 0o0010004, + B500000 = 0o0010005, + B576000 = 0o0010006, + B921600 = 0o0010007, + B1000000 = 0o0010010, + B1152000 = 0o0010011, + B1500000 = 0o0010012, + B2000000 = 0o0010013, + B2500000 = 0o0010014, + B3000000 = 0o0010015, + B3500000 = 0o0010016, + B4000000 = 0o0010017, + }, else => @compileError("target libc does not have speed_t"), }; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index b5c132df12..46997c5d75 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -814,43 +814,6 @@ pub const TCSA = struct { pub const SOFT = 0x10; // flag - don't alter h.w. state }; -// Standard speeds -pub const B0: c_uint = 0; -pub const B50: c_uint = 50; -pub const B75: c_uint = 75; -pub const B110: c_uint = 110; -pub const B134: c_uint = 134; -pub const B150: c_uint = 150; -pub const B200: c_uint = 200; -pub const B300: c_uint = 300; -pub const B600: c_uint = 600; -pub const B1200: c_uint = 1200; -pub const B1800: c_uint = 1800; -pub const B2400: c_uint = 2400; -pub const B4800: c_uint = 4800; -pub const B9600: c_uint = 9600; -pub const B19200: c_uint = 19200; -pub const B38400: c_uint = 38400; -pub const B7200: c_uint = 7200; -pub const B14400: c_uint = 14400; -pub const B28800: c_uint = 28800; -pub const B57600: c_uint = 57600; -pub const B76800: c_uint = 76800; -pub const B115200: c_uint = 115200; -pub const B230400: c_uint = 230400; -pub const B460800: c_uint = 460800; -pub const B500000: c_uint = 500000; -pub const B921600: c_uint = 921600; -pub const B1000000: c_uint = 1000000; -pub const B1500000: c_uint = 1500000; -pub const B2000000: c_uint = 2000000; -pub const B2500000: c_uint = 2500000; -pub const B3000000: c_uint = 3000000; -pub const B3500000: c_uint = 3500000; -pub const B4000000: c_uint = 4000000; -pub const EXTA: c_uint = 19200; -pub const EXTB: c_uint = 38400; - pub const TCIFLUSH = 1; pub const TCOFLUSH = 2; pub const TCIOFLUSH = 3; diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index 8d1df592d7..9b37aef05a 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -776,33 +776,6 @@ pub const TCSA = struct { pub const SOFT = 0x10; // flag - don't alter h.w. state }; -// Standard speeds -pub const B0 = 0; -pub const B50 = 50; -pub const B75 = 75; -pub const B110 = 110; -pub const B134 = 134; -pub const B150 = 150; -pub const B200 = 200; -pub const B300 = 300; -pub const B600 = 600; -pub const B1200 = 1200; -pub const B1800 = 1800; -pub const B2400 = 2400; -pub const B4800 = 4800; -pub const B9600 = 9600; -pub const B19200 = 19200; -pub const B38400 = 38400; -pub const B7200 = 7200; -pub const B14400 = 14400; -pub const B28800 = 28800; -pub const B57600 = 57600; -pub const B76800 = 76800; -pub const B115200 = 115200; -pub const B230400 = 230400; -pub const EXTA = 19200; -pub const EXTB = 38400; - pub const TCIFLUSH = 1; pub const TCOFLUSH = 2; pub const TCIOFLUSH = 3; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 4a3ed67cc5..6b092763d1 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -5004,45 +5004,81 @@ pub const rusage = extern struct { pub const THREAD = 1; }; -pub const speed_t = u32; - pub const NCCS = switch (native_arch) { .powerpc, .powerpcle, .powerpc64, .powerpc64le => 19, else => 32, }; -pub const B0 = 0o0000000; -pub const B50 = 0o0000001; -pub const B75 = 0o0000002; -pub const B110 = 0o0000003; -pub const B134 = 0o0000004; -pub const B150 = 0o0000005; -pub const B200 = 0o0000006; -pub const B300 = 0o0000007; -pub const B600 = 0o0000010; -pub const B1200 = 0o0000011; -pub const B1800 = 0o0000012; -pub const B2400 = 0o0000013; -pub const B4800 = 0o0000014; -pub const B9600 = 0o0000015; -pub const B19200 = 0o0000016; -pub const B38400 = 0o0000017; -pub const BOTHER = 0o0010000; -pub const B57600 = 0o0010001; -pub const B115200 = 0o0010002; -pub const B230400 = 0o0010003; -pub const B460800 = 0o0010004; -pub const B500000 = 0o0010005; -pub const B576000 = 0o0010006; -pub const B921600 = 0o0010007; -pub const B1000000 = 0o0010010; -pub const B1152000 = 0o0010011; -pub const B1500000 = 0o0010012; -pub const B2000000 = 0o0010013; -pub const B2500000 = 0o0010014; -pub const B3000000 = 0o0010015; -pub const B3500000 = 0o0010016; -pub const B4000000 = 0o0010017; +pub const speed_t = switch (native_arch) { + .powerpc, .powerpcle, .powerpc64, .powerpc64le => enum(u32) { + B0 = 0o0000000, + B50 = 0o0000001, + B75 = 0o0000002, + B110 = 0o0000003, + B134 = 0o0000004, + B150 = 0o0000005, + B200 = 0o0000006, + B300 = 0o0000007, + B600 = 0o0000010, + B1200 = 0o0000011, + B1800 = 0o0000012, + B2400 = 0o0000013, + B4800 = 0o0000014, + B9600 = 0o0000015, + B19200 = 0o0000016, + B38400 = 0o0000017, + + B57600 = 0o00020, + B115200 = 0o00021, + B230400 = 0o00022, + B460800 = 0o00023, + B500000 = 0o00024, + B576000 = 0o00025, + B921600 = 0o00026, + B1000000 = 0o00027, + B1152000 = 0o00030, + B1500000 = 0o00031, + B2000000 = 0o00032, + B2500000 = 0o00033, + B3000000 = 0o00034, + B3500000 = 0o00035, + B4000000 = 0o00036, + }, + else => enum(u32) { + B0 = 0o0000000, + B50 = 0o0000001, + B75 = 0o0000002, + B110 = 0o0000003, + B134 = 0o0000004, + B150 = 0o0000005, + B200 = 0o0000006, + B300 = 0o0000007, + B600 = 0o0000010, + B1200 = 0o0000011, + B1800 = 0o0000012, + B2400 = 0o0000013, + B4800 = 0o0000014, + B9600 = 0o0000015, + B19200 = 0o0000016, + B38400 = 0o0000017, + + B57600 = 0o0010001, + B115200 = 0o0010002, + B230400 = 0o0010003, + B460800 = 0o0010004, + B500000 = 0o0010005, + B576000 = 0o0010006, + B921600 = 0o0010007, + B1000000 = 0o0010010, + B1152000 = 0o0010011, + B1500000 = 0o0010012, + B2000000 = 0o0010013, + B2500000 = 0o0010014, + B3000000 = 0o0010015, + B3500000 = 0o0010016, + B4000000 = 0o0010017, + }, +}; pub const tc_iflag_t = switch (native_arch) { .powerpc, .powerpcle, .powerpc64, .powerpc64le => packed struct(u32) { From e1ab57337fc5ee5f420602340e082af3121c594c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 21:53:54 -0700 Subject: [PATCH 10/11] std.c.speed_t: consolidate common across os --- lib/std/c.zig | 100 ++------------------------------------------------ 1 file changed, 3 insertions(+), 97 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 140ff011aa..1fe1269abd 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -1287,7 +1287,7 @@ pub const tc_lflag_t = switch (native_os) { pub const speed_t = switch (native_os) { .linux => std.os.linux.speed_t, - .macos, .ios, .tvos, .watchos => enum(u64) { + .macos, .ios, .tvos, .watchos, .openbsd => enum(u64) { B0 = 0, B50 = 50, B75 = 75, @@ -1312,42 +1312,7 @@ pub const speed_t = switch (native_os) { B115200 = 115200, B230400 = 230400, }, - .freebsd, .kfreebsd => enum(c_uint) { - B0 = 0, - B50 = 50, - B75 = 75, - B110 = 110, - B134 = 134, - B150 = 150, - B200 = 200, - B300 = 300, - B600 = 600, - B1200 = 1200, - B1800 = 1800, - B2400 = 2400, - B4800 = 4800, - B9600 = 9600, - B19200 = 19200, - B38400 = 38400, - B7200 = 7200, - B14400 = 14400, - B28800 = 28800, - B57600 = 57600, - B76800 = 76800, - B115200 = 115200, - B230400 = 230400, - B460800 = 460800, - B500000 = 500000, - B921600 = 921600, - B1000000 = 1000000, - B1500000 = 1500000, - B2000000 = 2000000, - B2500000 = 2500000, - B3000000 = 3000000, - B3500000 = 3500000, - B4000000 = 4000000, - }, - .netbsd => enum(c_uint) { + .freebsd, .kfreebsd, .netbsd => enum(c_uint) { B0 = 0, B50 = 50, B75 = 75, @@ -1409,31 +1374,6 @@ pub const speed_t = switch (native_os) { B460800 = 460800, B921600 = 921600, }, - .openbsd => enum(c_uint) { - B0 = 0, - B50 = 50, - B75 = 75, - B110 = 110, - B134 = 134, - B150 = 150, - B200 = 200, - B300 = 300, - B600 = 600, - B1200 = 1200, - B1800 = 1800, - B2400 = 2400, - B4800 = 4800, - B9600 = 9600, - B19200 = 19200, - B38400 = 38400, - B7200 = 7200, - B14400 = 14400, - B28800 = 28800, - B57600 = 57600, - B76800 = 76800, - B115200 = 115200, - B230400 = 230400, - }, .haiku => enum(u8) { B0 = 0x00, B50 = 0x01, @@ -1490,41 +1430,7 @@ pub const speed_t = switch (native_os) { B3500000 = 30, B4000000 = 31, }, - .emscripten => enum(u32) { - B0 = 0o0000000, - B50 = 0o0000001, - B75 = 0o0000002, - B110 = 0o0000003, - B134 = 0o0000004, - B150 = 0o0000005, - B200 = 0o0000006, - B300 = 0o0000007, - B600 = 0o0000010, - B1200 = 0o0000011, - B1800 = 0o0000012, - B2400 = 0o0000013, - B4800 = 0o0000014, - B9600 = 0o0000015, - B19200 = 0o0000016, - B38400 = 0o0000017, - - B57600 = 0o0010001, - B115200 = 0o0010002, - B230400 = 0o0010003, - B460800 = 0o0010004, - B500000 = 0o0010005, - B576000 = 0o0010006, - B921600 = 0o0010007, - B1000000 = 0o0010010, - B1152000 = 0o0010011, - B1500000 = 0o0010012, - B2000000 = 0o0010013, - B2500000 = 0o0010014, - B3000000 = 0o0010015, - B3500000 = 0o0010016, - B4000000 = 0o0010017, - }, - .wasi => enum(u32) { + .emscripten, .wasi => enum(u32) { B0 = 0o0000000, B50 = 0o0000001, B75 = 0o0000002, From ce3bd515973c45ef755da04bc83585b7ce6b87b8 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 21:58:37 -0700 Subject: [PATCH 11/11] std.os.termios: move it to be with the group --- lib/std/os.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/os.zig b/lib/std/os.zig index 5ed36b353e..fba751d628 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -173,7 +173,6 @@ pub const sigset_t = system.sigset_t; pub const sockaddr = system.sockaddr; pub const socklen_t = system.socklen_t; pub const stack_t = system.stack_t; -pub const termios = system.termios; pub const time_t = system.time_t; pub const timespec = system.timespec; pub const timestamp_t = system.timestamp_t; @@ -184,6 +183,7 @@ pub const uid_t = system.uid_t; pub const user_desc = system.user_desc; pub const utsname = system.utsname; +pub const termios = system.termios; pub const CSIZE = system.CSIZE; pub const NCCS = system.NCCS; pub const speed_t = system.speed_t;