authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-12 16:21:21-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-12 16:21:21-07:00
log0c88f927f161224f5c5ce2b12a76133a421af081
tree831c20b2d51a9beabe94700aea986a8be92c7961
parent9a643185540a3bba31e449fdf6f25643a2ea3394

std.os.termios: consolidate and correct


10 files changed, 135 insertions(+), 203 deletions(-)

lib/std/c.zig+78
...@@ -790,6 +790,84 @@ pub const NCCS = switch (native_os) {...@@ -790,6 +790,84 @@ pub const NCCS = switch (native_os) {
790 else => @compileError("target libc does not have NCCS"),790 else => @compileError("target libc does not have NCCS"),
791};791};
792792
793pub const termios = switch (native_os) {
794 .linux => std.os.linux.termios,
795 .macos, .ios, .tvos, .watchos => extern struct {
796 iflag: tcflag_t,
797 oflag: tcflag_t,
798 cflag: tcflag_t,
799 lflag: tcflag_t,
800 cc: [NCCS]cc_t,
801 ispeed: speed_t align(8),
802 ospeed: speed_t,
803 },
804 .freebsd, .kfreebsd, .netbsd, .dragonfly, .openbsd => extern struct {
805 iflag: tcflag_t,
806 oflag: tcflag_t,
807 cflag: tcflag_t,
808 lflag: tcflag_t,
809 cc: [NCCS]cc_t,
810 ispeed: speed_t,
811 ospeed: speed_t,
812 },
813 .haiku => extern struct {
814 iflag: tcflag_t,
815 oflag: tcflag_t,
816 cflag: tcflag_t,
817 lflag: tcflag_t,
818 line: cc_t,
819 ispeed: speed_t,
820 ospeed: speed_t,
821 cc: [NCCS]cc_t,
822 },
823 .solaris, .illumos => extern struct {
824 iflag: tcflag_t,
825 oflag: tcflag_t,
826 cflag: tcflag_t,
827 lflag: tcflag_t,
828 cc: [NCCS]cc_t,
829 },
830 .emscripten, .wasi => extern struct {
831 iflag: tcflag_t,
832 oflag: tcflag_t,
833 cflag: tcflag_t,
834 lflag: tcflag_t,
835 line: std.c.cc_t,
836 cc: [NCCS]cc_t,
837 ispeed: speed_t,
838 ospeed: speed_t,
839 },
840 else => @compileError("target libc does not have termios"),
841};
842
843pub const tcflag_t = switch (native_os) {
844 .linux => std.os.linux.tcflag_t,
845 .macos, .ios, .tvos, .watchos => u64,
846 .freebsd, .kfreebsd => c_uint,
847 .netbsd => c_uint,
848 .dragonfly => c_uint,
849 .openbsd => c_uint,
850 .haiku => u32,
851 .solaris, .illumos => c_uint,
852 .emscripten => u32,
853 .wasi => c_uint,
854 else => @compileError("target libc does not have tcflag_t"),
855};
856
857pub const speed_t = switch (native_os) {
858 .linux => std.os.linux.speed_t,
859 .macos, .ios, .tvos, .watchos => u64,
860 .freebsd, .kfreebsd => c_uint,
861 .netbsd => c_uint,
862 .dragonfly => c_uint,
863 .openbsd => c_uint,
864 .haiku => u8,
865 .solaris, .illumos => c_uint,
866 .emscripten => u32,
867 .wasi => c_uint,
868 else => @compileError("target libc does not have speed_t"),
869};
870
793pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int;871pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int;
794872
795// Unix-like systems873// Unix-like systems
lib/std/c/darwin.zig-13
...@@ -2692,9 +2692,6 @@ pub const SHUT = struct {...@@ -2692,9 +2692,6 @@ pub const SHUT = struct {
2692 pub const RDWR = 2;2692 pub const RDWR = 2;
2693};2693};
26942694
2695pub const speed_t = u64;
2696pub const tcflag_t = u64;
2697
2698pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition2695pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition
2699pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINTR2696pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINTR
2700pub const IGNPAR: tcflag_t = 0x00000004; // ignore (discard) parity errors2697pub const IGNPAR: tcflag_t = 0x00000004; // ignore (discard) parity errors
...@@ -2829,16 +2826,6 @@ pub const TCOON: tcflag_t = 2;...@@ -2829,16 +2826,6 @@ pub const TCOON: tcflag_t = 2;
2829pub const TCIOFF: tcflag_t = 3;2826pub const TCIOFF: tcflag_t = 3;
2830pub const TCION: tcflag_t = 4;2827pub const TCION: tcflag_t = 4;
28312828
2832pub const termios = extern struct {
2833 iflag: tcflag_t, // input flags
2834 oflag: tcflag_t, // output flags
2835 cflag: tcflag_t, // control flags
2836 lflag: tcflag_t, // local flags
2837 cc: [std.c.NCCS]std.c.cc_t, // control chars
2838 ispeed: speed_t align(8), // input speed
2839 ospeed: speed_t, // output speed
2840};
2841
2842pub const winsize = extern struct {2829pub const winsize = extern struct {
2843 ws_row: u16,2830 ws_row: u16,
2844 ws_col: u16,2831 ws_col: u16,
lib/std/c/emscripten.zig-14
...@@ -178,17 +178,3 @@ pub const dirent = struct {...@@ -178,17 +178,3 @@ pub const dirent = struct {
178 type: u8,178 type: u8,
179 name: [256]u8,179 name: [256]u8,
180};180};
181
182pub const speed_t = u32;
183pub const tcflag_t = u32;
184
185pub const termios = extern struct {
186 iflag: tcflag_t,
187 oflag: tcflag_t,
188 cflag: tcflag_t,
189 lflag: tcflag_t,
190 line: std.c.cc_t,
191 cc: [std.c.NCCS]std.c.cc_t,
192 ispeed: speed_t,
193 ospeed: speed_t,
194};
lib/std/c/haiku.zig-14
...@@ -950,18 +950,4 @@ pub const directory_which = enum(c_int) {...@@ -950,18 +950,4 @@ pub const directory_which = enum(c_int) {
950 _,950 _,
951};951};
952952
953pub const speed_t = u8;
954pub const tcflag_t = u32;
955
956pub const termios = extern struct {
957 c_iflag: tcflag_t,
958 c_oflag: tcflag_t,
959 c_cflag: tcflag_t,
960 c_lflag: tcflag_t,
961 c_line: std.c.cc_t,
962 c_ispeed: speed_t,
963 c_ospeed: speed_t,
964 cc_t: [std.c.NCCS]std.c.cc_t,
965};
966
967pub const MSG_NOSIGNAL = 0x0800;953pub const MSG_NOSIGNAL = 0x0800;
lib/std/c/linux.zig-2
...@@ -85,8 +85,6 @@ pub const sigset_t = linux.sigset_t;...@@ -85,8 +85,6 @@ pub const sigset_t = linux.sigset_t;
85pub const sockaddr = linux.sockaddr;85pub const sockaddr = linux.sockaddr;
86pub const socklen_t = linux.socklen_t;86pub const socklen_t = linux.socklen_t;
87pub const stack_t = linux.stack_t;87pub const stack_t = linux.stack_t;
88pub const tcflag_t = linux.tcflag_t;
89pub const termios = linux.termios;
90pub const time_t = linux.time_t;88pub const time_t = linux.time_t;
91pub const timespec = linux.timespec;89pub const timespec = linux.timespec;
92pub const timeval = linux.timeval;90pub const timeval = linux.timeval;
lib/std/c/netbsd.zig-13
...@@ -850,19 +850,6 @@ pub const CDTRCTS: tcflag_t = 0x00020000; // DTR/CTS full-duplex flow control...@@ -850,19 +850,6 @@ pub const CDTRCTS: tcflag_t = 0x00020000; // DTR/CTS full-duplex flow control
850pub const MDMBUF: tcflag_t = 0x00100000; // DTR/DCD hardware flow control850pub const MDMBUF: tcflag_t = 0x00100000; // DTR/DCD hardware flow control
851pub const CHWFLOW: tcflag_t = (MDMBUF | CRTSCTS | CDTRCTS); // all types of hw flow control851pub const CHWFLOW: tcflag_t = (MDMBUF | CRTSCTS | CDTRCTS); // all types of hw flow control
852852
853pub const tcflag_t = c_uint;
854pub const speed_t = c_uint;
855
856pub const termios = extern struct {
857 iflag: tcflag_t, // input flags
858 oflag: tcflag_t, // output flags
859 cflag: tcflag_t, // control flags
860 lflag: tcflag_t, // local flags
861 cc: [std.c.NCCS]std.c.cc_t, // control chars
862 ispeed: c_int, // input speed
863 ospeed: c_int, // output speed
864};
865
866// Commands passed to tcsetattr() for setting the termios structure.853// Commands passed to tcsetattr() for setting the termios structure.
867pub const TCSA = struct {854pub const TCSA = struct {
868 pub const NOW = 0; // make change immediate855 pub const NOW = 0; // make change immediate
lib/std/c/openbsd.zig-13
...@@ -768,9 +768,6 @@ pub const AUTH = struct {...@@ -768,9 +768,6 @@ pub const AUTH = struct {
768 pub const ALLOW: c_int = (OKAY | ROOTOKAY | SECURE);768 pub const ALLOW: c_int = (OKAY | ROOTOKAY | SECURE);
769};769};
770770
771pub const tcflag_t = c_uint;
772pub const speed_t = c_uint;
773
774// Input flags - software input processing771// Input flags - software input processing
775pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition772pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition
776pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINT773pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINT
...@@ -816,16 +813,6 @@ pub const CCTS_OFLOW: tcflag_t = CRTSCTS; // XXX compat...@@ -816,16 +813,6 @@ pub const CCTS_OFLOW: tcflag_t = CRTSCTS; // XXX compat
816pub const MDMBUF: tcflag_t = 0x00100000; // DTR/DCD hardware flow control813pub const MDMBUF: tcflag_t = 0x00100000; // DTR/DCD hardware flow control
817pub const CHWFLOW: tcflag_t = (MDMBUF | CRTSCTS); // all types of hw flow control814pub const CHWFLOW: tcflag_t = (MDMBUF | CRTSCTS); // all types of hw flow control
818815
819pub const termios = extern struct {
820 iflag: tcflag_t, // input flags
821 oflag: tcflag_t, // output flags
822 cflag: tcflag_t, // control flags
823 lflag: tcflag_t, // local flags
824 cc: [std.c.NCCS]std.c.cc_t, // control chars
825 ispeed: c_int, // input speed
826 ospeed: c_int, // output speed
827};
828
829// Commands passed to tcsetattr() for setting the termios structure.816// Commands passed to tcsetattr() for setting the termios structure.
830pub const TCSA = struct {817pub const TCSA = struct {
831 pub const NOW = 0; // make change immediate818 pub const NOW = 0; // make change immediate
lib/std/c/solaris.zig-11
...@@ -698,17 +698,6 @@ pub const SEEK = struct {...@@ -698,17 +698,6 @@ pub const SEEK = struct {
698 pub const HOLE = 4;698 pub const HOLE = 4;
699};699};
700700
701pub const tcflag_t = c_uint;
702pub const speed_t = c_uint;
703
704pub const termios = extern struct {
705 c_iflag: tcflag_t,
706 c_oflag: tcflag_t,
707 c_cflag: tcflag_t,
708 c_lflag: tcflag_t,
709 c_cc: [std.c.NCCS]std.c.cc_t,
710};
711
712fn tioc(t: u16, num: u8) u16 {701fn tioc(t: u16, num: u8) u16 {
713 return (t << 8) | num;702 return (t << 8) | num;
714}703}
lib/std/os.zig+2
...@@ -106,6 +106,7 @@ pub const MFD = system.MFD;...@@ -106,6 +106,7 @@ pub const MFD = system.MFD;
106pub const MMAP2_UNIT = system.MMAP2_UNIT;106pub const MMAP2_UNIT = system.MMAP2_UNIT;
107pub const MSG = system.MSG;107pub const MSG = system.MSG;
108pub const NAME_MAX = system.NAME_MAX;108pub const NAME_MAX = system.NAME_MAX;
109pub const NCCS = system.NCCS;
109pub const O = system.O;110pub const O = system.O;
110pub const PATH_MAX = system.PATH_MAX;111pub const PATH_MAX = system.PATH_MAX;
111pub const POLL = system.POLL;112pub const POLL = system.POLL;
...@@ -172,6 +173,7 @@ pub const siginfo_t = system.siginfo_t;...@@ -172,6 +173,7 @@ pub const siginfo_t = system.siginfo_t;
172pub const sigset_t = system.sigset_t;173pub const sigset_t = system.sigset_t;
173pub const sockaddr = system.sockaddr;174pub const sockaddr = system.sockaddr;
174pub const socklen_t = system.socklen_t;175pub const socklen_t = system.socklen_t;
176pub const speed_t = system.speed_t;
175pub const stack_t = system.stack_t;177pub const stack_t = system.stack_t;
176pub const tcflag_t = system.tcflag_t;178pub const tcflag_t = system.tcflag_t;
177pub const termios = system.termios;179pub const termios = system.termios;
lib/std/os/linux.zig+55-123
...@@ -5005,6 +5005,7 @@ pub const rusage = extern struct {...@@ -5005,6 +5005,7 @@ pub const rusage = extern struct {
5005};5005};
50065006
5007pub const speed_t = u32;5007pub const speed_t = u32;
5008pub const tcflag_t = u32;
50085009
5009pub const NCCS = switch (native_arch) {5010pub const NCCS = switch (native_arch) {
5010 .powerpc, .powerpcle, .powerpc64, .powerpc64le => 19,5011 .powerpc, .powerpcle, .powerpc64, .powerpc64le => 19,
...@@ -5044,88 +5045,7 @@ pub const B3000000 = 0o0010015;...@@ -5044,88 +5045,7 @@ pub const B3000000 = 0o0010015;
5044pub const B3500000 = 0o0010016;5045pub const B3500000 = 0o0010016;
5045pub const B4000000 = 0o0010017;5046pub const B4000000 = 0o0010017;
50465047
5047pub const V = switch (native_arch) {5048pub const tc_iflag_t = packed struct(u32) {
5048 .powerpc, .powerpc64, .powerpc64le => struct {
5049 pub const INTR = 0;
5050 pub const QUIT = 1;
5051 pub const ERASE = 2;
5052 pub const KILL = 3;
5053 pub const EOF = 4;
5054 pub const MIN = 5;
5055 pub const EOL = 6;
5056 pub const TIME = 7;
5057 pub const EOL2 = 8;
5058 pub const SWTC = 9;
5059 pub const WERASE = 10;
5060 pub const REPRINT = 11;
5061 pub const SUSP = 12;
5062 pub const START = 13;
5063 pub const STOP = 14;
5064 pub const LNEXT = 15;
5065 pub const DISCARD = 16;
5066 },
5067 .sparc, .sparc64 => struct {
5068 pub const INTR = 0;
5069 pub const QUIT = 1;
5070 pub const ERASE = 2;
5071 pub const KILL = 3;
5072 pub const EOF = 4;
5073 pub const EOL = 5;
5074 pub const EOL2 = 6;
5075 pub const SWTC = 7;
5076 pub const START = 8;
5077 pub const STOP = 9;
5078 pub const SUSP = 10;
5079 pub const DSUSP = 11;
5080 pub const REPRINT = 12;
5081 pub const DISCARD = 13;
5082 pub const WERASE = 14;
5083 pub const LNEXT = 15;
5084 pub const MIN = EOF;
5085 pub const TIME = EOL;
5086 },
5087 .mips, .mipsel, .mips64, .mips64el => struct {
5088 pub const INTR = 0;
5089 pub const QUIT = 1;
5090 pub const ERASE = 2;
5091 pub const KILL = 3;
5092 pub const MIN = 4;
5093 pub const TIME = 5;
5094 pub const EOL2 = 6;
5095 pub const SWTC = 7;
5096 pub const SWTCH = 7;
5097 pub const START = 8;
5098 pub const STOP = 9;
5099 pub const SUSP = 10;
5100 pub const REPRINT = 12;
5101 pub const DISCARD = 13;
5102 pub const WERASE = 14;
5103 pub const LNEXT = 15;
5104 pub const EOF = 16;
5105 pub const EOL = 17;
5106 },
5107 else => struct {
5108 pub const INTR = 0;
5109 pub const QUIT = 1;
5110 pub const ERASE = 2;
5111 pub const KILL = 3;
5112 pub const EOF = 4;
5113 pub const TIME = 5;
5114 pub const MIN = 6;
5115 pub const SWTC = 7;
5116 pub const START = 8;
5117 pub const STOP = 9;
5118 pub const SUSP = 10;
5119 pub const EOL = 11;
5120 pub const REPRINT = 12;
5121 pub const DISCARD = 13;
5122 pub const WERASE = 14;
5123 pub const LNEXT = 15;
5124 pub const EOL2 = 16;
5125 },
5126};
5127
5128pub const tc_iflag_t = packed struct (u32) {
5129 IGNBRK: bool = false,5049 IGNBRK: bool = false,
5130 BRKINT: bool = false,5050 BRKINT: bool = false,
5131 IGNPAR: bool = false,5051 IGNPAR: bool = false,
...@@ -5145,42 +5065,42 @@ pub const tc_iflag_t = packed struct (u32) {...@@ -5145,42 +5065,42 @@ pub const tc_iflag_t = packed struct (u32) {
5145};5065};
51465066
5147pub const cc_t = switch (native_arch) {5067pub const cc_t = switch (native_arch) {
5148 .mips, .mipsel, .mips64, .mips64el => enum(u8){5068 .mips, .mipsel, .mips64, .mips64el => enum(u8) {
5149 VINTR = 0,5069 VINTR = 0,
5150 VQUIT = 1,5070 VQUIT = 1,
5151 VERASE = 2,5071 VERASE = 2,
5152 VKILL = 3,5072 VKILL = 3,
5153 VMIN = 4,5073 VMIN = 4,
5154 VTIME = 5,5074 VTIME = 5,
5155 VEOL2 = 6,5075 VEOL2 = 6,
5156 VSWTC = 7,5076 VSWTC = 7,
5157 VSTART = 8,5077 VSTART = 8,
5158 VSTOP = 9,5078 VSTOP = 9,
5159 VSUSP = 10,5079 VSUSP = 10,
5160 VREPRINT = 12,5080 VREPRINT = 12,
5161 VDISCARD = 13,5081 VDISCARD = 13,
5162 VWERASE = 14,5082 VWERASE = 14,
5163 VLNEXT = 15,5083 VLNEXT = 15,
5164 VEOF = 16,5084 VEOF = 16,
5165 VEOL = 17,5085 VEOL = 17,
5166 },5086 },
5167 .powerpc, .powerpc64, .powerpc64le => enum(u8) {5087 .powerpc, .powerpcle, .powerpc64, .powerpc64le => enum(u8) {
5168 VINTR = 0,5088 VINTR = 0,
5169 VQUIT = 1,5089 VQUIT = 1,
5170 VERASE = 2,5090 VERASE = 2,
5171 VKILL = 3,5091 VKILL = 3,
5172 VEOF = 4,5092 VEOF = 4,
5173 VMIN = 5,5093 VMIN = 5,
5174 VEOL = 6,5094 VEOL = 6,
5175 VTIME = 7,5095 VTIME = 7,
5176 VEOL2 = 8,5096 VEOL2 = 8,
5177 VSWTC = 9,5097 VSWTC = 9,
5178 VWERASE = 10,5098 VWERASE = 10,
5179 VREPRINT = 11,5099 VREPRINT = 11,
5180 VSUSP = 12,5100 VSUSP = 12,
5181 VSTART = 13,5101 VSTART = 13,
5182 VSTOP = 14,5102 VSTOP = 14,
5183 VLNEXT = 15,5103 VLNEXT = 15,
5184 VDISCARD = 16,5104 VDISCARD = 16,
5185 },5105 },
5186 else => enum(u8) {5106 else => enum(u8) {
...@@ -5246,15 +5166,27 @@ pub const TCSA = enum(c_uint) {...@@ -5246,15 +5166,27 @@ pub const TCSA = enum(c_uint) {
5246 _,5166 _,
5247};5167};
52485168
5249pub const termios = extern struct {5169pub const termios = switch (native_arch) {
5250 iflag: tc_iflag_t,5170 .powerpc, .powerpcle, .powerpc64, .powerpc64le => extern struct {
5251 oflag: tc_oflag_t,5171 iflag: tcflag_t,
5252 cflag: tc_cflag_t,5172 oflag: tcflag_t,
5253 lflag: tc_lflag_t,5173 cflag: tcflag_t,
5254 line: cc_t,5174 lflag: tcflag_t,
5255 cc: [NCCS]cc_t,5175 cc: [NCCS]cc_t,
5256 ispeed: speed_t,5176 line: cc_t,
5257 ospeed: speed_t,5177 ispeed: speed_t,
5178 ospeed: speed_t,
5179 },
5180 else => extern struct {
5181 iflag: tcflag_t,
5182 oflag: tcflag_t,
5183 cflag: tcflag_t,
5184 lflag: tcflag_t,
5185 line: cc_t,
5186 cc: [NCCS]cc_t,
5187 ispeed: speed_t,
5188 ospeed: speed_t,
5189 },
5258};5190};
52595191
5260pub const SIOCGIFINDEX = 0x8933;5192pub const SIOCGIFINDEX = 0x8933;