Commit 9a64318554

Andrew Kelley <andrew@ziglang.org>
2024-02-12 23:52:13
std.c.NCSS: consolidate and correct
1 parent 9bdf1eb
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
 };
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,
 };
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;
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
 };
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
 };
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 {
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;
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