mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.os.termios: consolidate and correct
This commit is contained in:
parent
9a64318554
commit
0c88f927f1
10 changed files with 135 additions and 203 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,87 +5045,6 @@ 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) {
|
||||
IGNBRK: bool = false,
|
||||
BRKINT: bool = false,
|
||||
|
|
@ -5164,7 +5084,7 @@ pub const cc_t = switch (native_arch) {
|
|||
VEOF = 16,
|
||||
VEOL = 17,
|
||||
},
|
||||
.powerpc, .powerpc64, .powerpc64le => enum(u8) {
|
||||
.powerpc, .powerpcle, .powerpc64, .powerpc64le => enum(u8) {
|
||||
VINTR = 0,
|
||||
VQUIT = 1,
|
||||
VERASE = 2,
|
||||
|
|
@ -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,
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue