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.
This commit is contained in:
Andrew Kelley
2024-02-12 16:43:51 -07:00
parent 0c88f927f1
commit 47643cc5cc
6 changed files with 161 additions and 72 deletions

View File

@@ -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,