From 9a643185540a3bba31e449fdf6f25643a2ea3394 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Feb 2024 15:52:13 -0700 Subject: [PATCH] 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;