std.os.speed_t: add type safety

and collect the missing flag bits from all the operating systems.
This commit is contained in:
Andrew Kelley 2024-02-12 21:49:09 -07:00
parent a280ff2767
commit ae107cf71b
4 changed files with 341 additions and 107 deletions

View File

@ -1287,15 +1287,277 @@ pub const tc_lflag_t = switch (native_os) {
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,
.macos, .ios, .tvos, .watchos => enum(u64) {
B0 = 0,
B50 = 50,
B75 = 75,
B110 = 110,
B134 = 134,
B150 = 150,
B200 = 200,
B300 = 300,
B600 = 600,
B1200 = 1200,
B1800 = 1800,
B2400 = 2400,
B4800 = 4800,
B9600 = 9600,
B19200 = 19200,
B38400 = 38400,
B7200 = 7200,
B14400 = 14400,
B28800 = 28800,
B57600 = 57600,
B76800 = 76800,
B115200 = 115200,
B230400 = 230400,
},
.freebsd, .kfreebsd => enum(c_uint) {
B0 = 0,
B50 = 50,
B75 = 75,
B110 = 110,
B134 = 134,
B150 = 150,
B200 = 200,
B300 = 300,
B600 = 600,
B1200 = 1200,
B1800 = 1800,
B2400 = 2400,
B4800 = 4800,
B9600 = 9600,
B19200 = 19200,
B38400 = 38400,
B7200 = 7200,
B14400 = 14400,
B28800 = 28800,
B57600 = 57600,
B76800 = 76800,
B115200 = 115200,
B230400 = 230400,
B460800 = 460800,
B500000 = 500000,
B921600 = 921600,
B1000000 = 1000000,
B1500000 = 1500000,
B2000000 = 2000000,
B2500000 = 2500000,
B3000000 = 3000000,
B3500000 = 3500000,
B4000000 = 4000000,
},
.netbsd => enum(c_uint) {
B0 = 0,
B50 = 50,
B75 = 75,
B110 = 110,
B134 = 134,
B150 = 150,
B200 = 200,
B300 = 300,
B600 = 600,
B1200 = 1200,
B1800 = 1800,
B2400 = 2400,
B4800 = 4800,
B9600 = 9600,
B19200 = 19200,
B38400 = 38400,
B7200 = 7200,
B14400 = 14400,
B28800 = 28800,
B57600 = 57600,
B76800 = 76800,
B115200 = 115200,
B230400 = 230400,
B460800 = 460800,
B500000 = 500000,
B921600 = 921600,
B1000000 = 1000000,
B1500000 = 1500000,
B2000000 = 2000000,
B2500000 = 2500000,
B3000000 = 3000000,
B3500000 = 3500000,
B4000000 = 4000000,
},
.dragonfly => enum(c_uint) {
B0 = 0,
B50 = 50,
B75 = 75,
B110 = 110,
B134 = 134,
B150 = 150,
B200 = 200,
B300 = 300,
B600 = 600,
B1200 = 1200,
B1800 = 1800,
B2400 = 2400,
B4800 = 4800,
B9600 = 9600,
B19200 = 19200,
B38400 = 38400,
B7200 = 7200,
B14400 = 14400,
B28800 = 28800,
B57600 = 57600,
B76800 = 76800,
B115200 = 115200,
B230400 = 230400,
B460800 = 460800,
B921600 = 921600,
},
.openbsd => enum(c_uint) {
B0 = 0,
B50 = 50,
B75 = 75,
B110 = 110,
B134 = 134,
B150 = 150,
B200 = 200,
B300 = 300,
B600 = 600,
B1200 = 1200,
B1800 = 1800,
B2400 = 2400,
B4800 = 4800,
B9600 = 9600,
B19200 = 19200,
B38400 = 38400,
B7200 = 7200,
B14400 = 14400,
B28800 = 28800,
B57600 = 57600,
B76800 = 76800,
B115200 = 115200,
B230400 = 230400,
},
.haiku => enum(u8) {
B0 = 0x00,
B50 = 0x01,
B75 = 0x02,
B110 = 0x03,
B134 = 0x04,
B150 = 0x05,
B200 = 0x06,
B300 = 0x07,
B600 = 0x08,
B1200 = 0x09,
B1800 = 0x0A,
B2400 = 0x0B,
B4800 = 0x0C,
B9600 = 0x0D,
B19200 = 0x0E,
B38400 = 0x0F,
B57600 = 0x10,
B115200 = 0x11,
B230400 = 0x12,
B31250 = 0x13,
},
.solaris, .illumos => enum(c_uint) {
B0 = 0,
B50 = 1,
B75 = 2,
B110 = 3,
B134 = 4,
B150 = 5,
B200 = 6,
B300 = 7,
B600 = 8,
B1200 = 9,
B1800 = 10,
B2400 = 11,
B4800 = 12,
B9600 = 13,
B19200 = 14,
B38400 = 15,
B57600 = 16,
B76800 = 17,
B115200 = 18,
B153600 = 19,
B230400 = 20,
B307200 = 21,
B460800 = 22,
B921600 = 23,
B1000000 = 24,
B1152000 = 25,
B1500000 = 26,
B2000000 = 27,
B2500000 = 28,
B3000000 = 29,
B3500000 = 30,
B4000000 = 31,
},
.emscripten => enum(u32) {
B0 = 0o0000000,
B50 = 0o0000001,
B75 = 0o0000002,
B110 = 0o0000003,
B134 = 0o0000004,
B150 = 0o0000005,
B200 = 0o0000006,
B300 = 0o0000007,
B600 = 0o0000010,
B1200 = 0o0000011,
B1800 = 0o0000012,
B2400 = 0o0000013,
B4800 = 0o0000014,
B9600 = 0o0000015,
B19200 = 0o0000016,
B38400 = 0o0000017,
B57600 = 0o0010001,
B115200 = 0o0010002,
B230400 = 0o0010003,
B460800 = 0o0010004,
B500000 = 0o0010005,
B576000 = 0o0010006,
B921600 = 0o0010007,
B1000000 = 0o0010010,
B1152000 = 0o0010011,
B1500000 = 0o0010012,
B2000000 = 0o0010013,
B2500000 = 0o0010014,
B3000000 = 0o0010015,
B3500000 = 0o0010016,
B4000000 = 0o0010017,
},
.wasi => enum(u32) {
B0 = 0o0000000,
B50 = 0o0000001,
B75 = 0o0000002,
B110 = 0o0000003,
B134 = 0o0000004,
B150 = 0o0000005,
B200 = 0o0000006,
B300 = 0o0000007,
B600 = 0o0000010,
B1200 = 0o0000011,
B1800 = 0o0000012,
B2400 = 0o0000013,
B4800 = 0o0000014,
B9600 = 0o0000015,
B19200 = 0o0000016,
B38400 = 0o0000017,
B57600 = 0o0010001,
B115200 = 0o0010002,
B230400 = 0o0010003,
B460800 = 0o0010004,
B500000 = 0o0010005,
B576000 = 0o0010006,
B921600 = 0o0010007,
B1000000 = 0o0010010,
B1152000 = 0o0010011,
B1500000 = 0o0010012,
B2000000 = 0o0010013,
B2500000 = 0o0010014,
B3000000 = 0o0010015,
B3500000 = 0o0010016,
B4000000 = 0o0010017,
},
else => @compileError("target libc does not have speed_t"),
};

View File

@ -814,43 +814,6 @@ pub const TCSA = struct {
pub const SOFT = 0x10; // flag - don't alter h.w. state
};
// Standard speeds
pub const B0: c_uint = 0;
pub const B50: c_uint = 50;
pub const B75: c_uint = 75;
pub const B110: c_uint = 110;
pub const B134: c_uint = 134;
pub const B150: c_uint = 150;
pub const B200: c_uint = 200;
pub const B300: c_uint = 300;
pub const B600: c_uint = 600;
pub const B1200: c_uint = 1200;
pub const B1800: c_uint = 1800;
pub const B2400: c_uint = 2400;
pub const B4800: c_uint = 4800;
pub const B9600: c_uint = 9600;
pub const B19200: c_uint = 19200;
pub const B38400: c_uint = 38400;
pub const B7200: c_uint = 7200;
pub const B14400: c_uint = 14400;
pub const B28800: c_uint = 28800;
pub const B57600: c_uint = 57600;
pub const B76800: c_uint = 76800;
pub const B115200: c_uint = 115200;
pub const B230400: c_uint = 230400;
pub const B460800: c_uint = 460800;
pub const B500000: c_uint = 500000;
pub const B921600: c_uint = 921600;
pub const B1000000: c_uint = 1000000;
pub const B1500000: c_uint = 1500000;
pub const B2000000: c_uint = 2000000;
pub const B2500000: c_uint = 2500000;
pub const B3000000: c_uint = 3000000;
pub const B3500000: c_uint = 3500000;
pub const B4000000: c_uint = 4000000;
pub const EXTA: c_uint = 19200;
pub const EXTB: c_uint = 38400;
pub const TCIFLUSH = 1;
pub const TCOFLUSH = 2;
pub const TCIOFLUSH = 3;

View File

@ -776,33 +776,6 @@ pub const TCSA = struct {
pub const SOFT = 0x10; // flag - don't alter h.w. state
};
// Standard speeds
pub const B0 = 0;
pub const B50 = 50;
pub const B75 = 75;
pub const B110 = 110;
pub const B134 = 134;
pub const B150 = 150;
pub const B200 = 200;
pub const B300 = 300;
pub const B600 = 600;
pub const B1200 = 1200;
pub const B1800 = 1800;
pub const B2400 = 2400;
pub const B4800 = 4800;
pub const B9600 = 9600;
pub const B19200 = 19200;
pub const B38400 = 38400;
pub const B7200 = 7200;
pub const B14400 = 14400;
pub const B28800 = 28800;
pub const B57600 = 57600;
pub const B76800 = 76800;
pub const B115200 = 115200;
pub const B230400 = 230400;
pub const EXTA = 19200;
pub const EXTB = 38400;
pub const TCIFLUSH = 1;
pub const TCOFLUSH = 2;
pub const TCIOFLUSH = 3;

View File

@ -5004,45 +5004,81 @@ pub const rusage = extern struct {
pub const THREAD = 1;
};
pub const speed_t = u32;
pub const NCCS = switch (native_arch) {
.powerpc, .powerpcle, .powerpc64, .powerpc64le => 19,
else => 32,
};
pub const B0 = 0o0000000;
pub const B50 = 0o0000001;
pub const B75 = 0o0000002;
pub const B110 = 0o0000003;
pub const B134 = 0o0000004;
pub const B150 = 0o0000005;
pub const B200 = 0o0000006;
pub const B300 = 0o0000007;
pub const B600 = 0o0000010;
pub const B1200 = 0o0000011;
pub const B1800 = 0o0000012;
pub const B2400 = 0o0000013;
pub const B4800 = 0o0000014;
pub const B9600 = 0o0000015;
pub const B19200 = 0o0000016;
pub const B38400 = 0o0000017;
pub const BOTHER = 0o0010000;
pub const B57600 = 0o0010001;
pub const B115200 = 0o0010002;
pub const B230400 = 0o0010003;
pub const B460800 = 0o0010004;
pub const B500000 = 0o0010005;
pub const B576000 = 0o0010006;
pub const B921600 = 0o0010007;
pub const B1000000 = 0o0010010;
pub const B1152000 = 0o0010011;
pub const B1500000 = 0o0010012;
pub const B2000000 = 0o0010013;
pub const B2500000 = 0o0010014;
pub const B3000000 = 0o0010015;
pub const B3500000 = 0o0010016;
pub const B4000000 = 0o0010017;
pub const speed_t = switch (native_arch) {
.powerpc, .powerpcle, .powerpc64, .powerpc64le => enum(u32) {
B0 = 0o0000000,
B50 = 0o0000001,
B75 = 0o0000002,
B110 = 0o0000003,
B134 = 0o0000004,
B150 = 0o0000005,
B200 = 0o0000006,
B300 = 0o0000007,
B600 = 0o0000010,
B1200 = 0o0000011,
B1800 = 0o0000012,
B2400 = 0o0000013,
B4800 = 0o0000014,
B9600 = 0o0000015,
B19200 = 0o0000016,
B38400 = 0o0000017,
B57600 = 0o00020,
B115200 = 0o00021,
B230400 = 0o00022,
B460800 = 0o00023,
B500000 = 0o00024,
B576000 = 0o00025,
B921600 = 0o00026,
B1000000 = 0o00027,
B1152000 = 0o00030,
B1500000 = 0o00031,
B2000000 = 0o00032,
B2500000 = 0o00033,
B3000000 = 0o00034,
B3500000 = 0o00035,
B4000000 = 0o00036,
},
else => enum(u32) {
B0 = 0o0000000,
B50 = 0o0000001,
B75 = 0o0000002,
B110 = 0o0000003,
B134 = 0o0000004,
B150 = 0o0000005,
B200 = 0o0000006,
B300 = 0o0000007,
B600 = 0o0000010,
B1200 = 0o0000011,
B1800 = 0o0000012,
B2400 = 0o0000013,
B4800 = 0o0000014,
B9600 = 0o0000015,
B19200 = 0o0000016,
B38400 = 0o0000017,
B57600 = 0o0010001,
B115200 = 0o0010002,
B230400 = 0o0010003,
B460800 = 0o0010004,
B500000 = 0o0010005,
B576000 = 0o0010006,
B921600 = 0o0010007,
B1000000 = 0o0010010,
B1152000 = 0o0010011,
B1500000 = 0o0010012,
B2000000 = 0o0010013,
B2500000 = 0o0010014,
B3000000 = 0o0010015,
B3500000 = 0o0010016,
B4000000 = 0o0010017,
},
};
pub const tc_iflag_t = switch (native_arch) {
.powerpc, .powerpcle, .powerpc64, .powerpc64le => packed struct(u32) {