| author | |
| committer | |
| log | e1f04b8d5976437f814e129486719d6e6043c04f |
| tree | 9c438cdc9ad33e3de8ae27095ebbb87cc24384cc |
| parent | 326939960399088e4fc89464eab2bfebca83793e |
| signature | Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw |
5 files changed, 95 insertions(+), 54 deletions(-)
darwin.zig+5-5| ... | @@ -235,19 +235,19 @@ pub const errno = struct { | ... | @@ -235,19 +235,19 @@ pub const errno = struct { |
| 235 | // assert Enum is sequential | 235 | // assert Enum is sequential |
| 236 | var value: c_ushort = 0; // SUCCESS | 236 | var value: c_ushort = 0; // SUCCESS |
| 237 | for (std.enums.values(Enum)) |val| { | 237 | for (std.enums.values(Enum)) |val| { |
| 238 | std.debug.assert(@intFromEnum(val) > value); | 238 | std.debug.assert(@backingInt(val) > value); |
| 239 | value = @intFromEnum(val); | 239 | value = @backingInt(val); |
| 240 | } | 240 | } |
| 241 | } | 241 | } |
| 242 | comptime { | 242 | comptime { |
| 243 | // sanity test | 243 | // sanity test |
| 244 | std.debug.assert(@intFromEnum(Enum.EPERM) == 1); | 244 | std.debug.assert(@backingInt(Enum.EPERM) == 1); |
| 245 | } | 245 | } |
| 246 | const list = blk: { | 246 | const list = blk: { |
| 247 | const values = std.enums.values(Enum); | 247 | const values = std.enums.values(Enum); |
| 248 | const len = @intFromEnum(values[values.len - 1]) + 1; | 248 | const len = @backingInt(values[values.len - 1]) + 1; |
| 249 | var errors: [len]Error = @splat(error.Unexpected); | 249 | var errors: [len]Error = @splat(error.Unexpected); |
| 250 | for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f)); | 250 | for (values) |f| errors[@backingInt(f)] = @field(Error, @tagName(f)); |
| 251 | const final = errors; | 251 | const final = errors; |
| 252 | break :blk final; | 252 | break :blk final; |
| 253 | }; | 253 | }; |
freebsd.zig+10-12| ... | @@ -216,19 +216,19 @@ pub const errno = struct { | ... | @@ -216,19 +216,19 @@ pub const errno = struct { |
| 216 | // assert Enum is sequential | 216 | // assert Enum is sequential |
| 217 | var value: c_ushort = 0; // SUCCESS | 217 | var value: c_ushort = 0; // SUCCESS |
| 218 | for (std.enums.values(Enum)) |val| { | 218 | for (std.enums.values(Enum)) |val| { |
| 219 | std.debug.assert(@intFromEnum(val) > value); | 219 | std.debug.assert(@backingInt(val) > value); |
| 220 | value = @intFromEnum(val); | 220 | value = @backingInt(val); |
| 221 | } | 221 | } |
| 222 | } | 222 | } |
| 223 | comptime { | 223 | comptime { |
| 224 | // sanity test | 224 | // sanity test |
| 225 | std.debug.assert(@intFromEnum(Enum.EPERM) == 1); | 225 | std.debug.assert(@backingInt(Enum.EPERM) == 1); |
| 226 | } | 226 | } |
| 227 | const list = blk: { | 227 | const list = blk: { |
| 228 | const values = std.enums.values(Enum); | 228 | const values = std.enums.values(Enum); |
| 229 | const len = @intFromEnum(values[values.len - 1]) + 1; | 229 | const len = @backingInt(values[values.len - 1]) + 1; |
| 230 | var errors: [len]Error = @splat(error.Unexpected); | 230 | var errors: [len]Error = @splat(error.Unexpected); |
| 231 | for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f)); | 231 | for (values) |f| errors[@backingInt(f)] = @field(Error, @tagName(f)); |
| 232 | const final = errors; | 232 | const final = errors; |
| 233 | break :blk final; | 233 | break :blk final; |
| 234 | }; | 234 | }; |
| ... | @@ -279,7 +279,7 @@ pub const eai = struct { | ... | @@ -279,7 +279,7 @@ pub const eai = struct { |
| 279 | }; | 279 | }; |
| 280 | 280 | ||
| 281 | pub fn fromInt(code: c_int) Error { | 281 | pub fn fromInt(code: c_int) Error { |
| 282 | return switch (@as(Enum, @enumFromInt(code))) { | 282 | return switch (@as(Enum, @fromBackingInt(@intCast(code)))) { |
| 283 | .EAI_ADDRFAMILY => error.EAI_ADDRFAMILY, | 283 | .EAI_ADDRFAMILY => error.EAI_ADDRFAMILY, |
| 284 | .EAI_AGAIN => error.EAI_AGAIN, | 284 | .EAI_AGAIN => error.EAI_AGAIN, |
| 285 | .EAI_BADFLAGS => error.EAI_BADFLAGS, | 285 | .EAI_BADFLAGS => error.EAI_BADFLAGS, |
| ... | @@ -423,9 +423,7 @@ pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktyp | ... | @@ -423,9 +423,7 @@ pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktyp |
| 423 | pub const struct_dirent = extern struct { fileno: ino_t, off: off_t, reclen: u16, type: DT, pad0: u8, namlen: u16, pad1: u16, name: [NAME_MAX + 1]u8 }; | 423 | pub const struct_dirent = extern struct { fileno: ino_t, off: off_t, reclen: u16, type: DT, pad0: u8, namlen: u16, pad1: u16, name: [NAME_MAX + 1]u8 }; |
| 424 | pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t }; | 424 | pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t }; |
| 425 | 425 | ||
| 426 | const impdef = @cImport({ | 426 | const impdef = @import("c"); |
| 427 | @cInclude("pthread.h"); | ||
| 428 | }); | ||
| 429 | pub const pthread_t = impdef.pthread_t; | 427 | pub const pthread_t = impdef.pthread_t; |
| 430 | pub const pthread_attr_t = impdef.pthread_attr_t; | 428 | pub const pthread_attr_t = impdef.pthread_attr_t; |
| 431 | pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; | 429 | pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; |
| ... | @@ -1085,7 +1083,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void { | ... | @@ -1085,7 +1083,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void { |
| 1085 | return libc.freeaddrinfo(ai); | 1083 | return libc.freeaddrinfo(ai); |
| 1086 | } | 1084 | } |
| 1087 | pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { | 1085 | pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { |
| 1088 | const rc = libc.socket(@intFromEnum(domain), ty, protocol); | 1086 | const rc = libc.socket(@backingInt(domain), ty, protocol); |
| 1089 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 1087 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1090 | std.debug.assert(rc > 0); | 1088 | std.debug.assert(rc > 0); |
| 1091 | return @intCast(rc); | 1089 | return @intCast(rc); |
| ... | @@ -1103,7 +1101,7 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 { | ... | @@ -1103,7 +1101,7 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 { |
| 1103 | } | 1101 | } |
| 1104 | pub fn clock_gettime(clock_id: CLOCK) !struct_timespec { | 1102 | pub fn clock_gettime(clock_id: CLOCK) !struct_timespec { |
| 1105 | var tp: struct_timespec = undefined; | 1103 | var tp: struct_timespec = undefined; |
| 1106 | const rc = libc.clock_gettime(@intFromEnum(clock_id), &tp); | 1104 | const rc = libc.clock_gettime(@backingInt(clock_id), &tp); |
| 1107 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 1105 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1108 | std.debug.assert(rc == 0); | 1106 | std.debug.assert(rc == 0); |
| 1109 | return tp; | 1107 | return tp; |
| ... | @@ -1200,7 +1198,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add | ... | @@ -1200,7 +1198,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add |
| 1200 | return @intCast(rc); | 1198 | return @intCast(rc); |
| 1201 | } | 1199 | } |
| 1202 | pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { | 1200 | pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { |
| 1203 | const rc = libc.shutdown(@intCast(socketfd), @intFromEnum(how)); | 1201 | const rc = libc.shutdown(@intCast(socketfd), @backingInt(how)); |
| 1204 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 1202 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1205 | std.debug.assert(rc == 0); | 1203 | std.debug.assert(rc == 0); |
| 1206 | } | 1204 | } |
linux.zig+12-13| ... | @@ -894,6 +894,9 @@ pub const errno = struct { | ... | @@ -894,6 +894,9 @@ pub const errno = struct { |
| 894 | .hppa, | 894 | .hppa, |
| 895 | .hppa64, | 895 | .hppa64, |
| 896 | .kvx, | 896 | .kvx, |
| 897 | .ez80, | ||
| 898 | .m88k, | ||
| 899 | .spork8, | ||
| 897 | => unreachable, | 900 | => unreachable, |
| 898 | }; | 901 | }; |
| 899 | 902 | ||
| ... | @@ -910,19 +913,19 @@ pub const errno = struct { | ... | @@ -910,19 +913,19 @@ pub const errno = struct { |
| 910 | // assert Enum is sequential | 913 | // assert Enum is sequential |
| 911 | var value: c_ushort = 0; // SUCCESS | 914 | var value: c_ushort = 0; // SUCCESS |
| 912 | for (std.enums.values(Enum)) |val| { | 915 | for (std.enums.values(Enum)) |val| { |
| 913 | std.debug.assert(@intFromEnum(val) > value); | 916 | std.debug.assert(@backingInt(val) > value); |
| 914 | value = @intFromEnum(val); | 917 | value = @backingInt(val); |
| 915 | } | 918 | } |
| 916 | } | 919 | } |
| 917 | comptime { | 920 | comptime { |
| 918 | // sanity test | 921 | // sanity test |
| 919 | std.debug.assert(@intFromEnum(Enum.EPERM) == 1); | 922 | std.debug.assert(@backingInt(Enum.EPERM) == 1); |
| 920 | } | 923 | } |
| 921 | const list = blk: { | 924 | const list = blk: { |
| 922 | const values = std.enums.values(Enum); | 925 | const values = std.enums.values(Enum); |
| 923 | const len = @intFromEnum(values[values.len - 1]) + 1; | 926 | const len = @backingInt(values[values.len - 1]) + 1; |
| 924 | var errors: [len]Error = @splat(error.Unexpected); | 927 | var errors: [len]Error = @splat(error.Unexpected); |
| 925 | for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f)); | 928 | for (values) |f| errors[@backingInt(f)] = @field(Error, @tagName(f)); |
| 926 | const final = errors; | 929 | const final = errors; |
| 927 | break :blk final; | 930 | break :blk final; |
| 928 | }; | 931 | }; |
| ... | @@ -969,7 +972,7 @@ pub const eai = struct { | ... | @@ -969,7 +972,7 @@ pub const eai = struct { |
| 969 | }; | 972 | }; |
| 970 | 973 | ||
| 971 | pub fn fromInt(code: c_int) Error { | 974 | pub fn fromInt(code: c_int) Error { |
| 972 | return switch (@as(Enum, @enumFromInt(code))) { | 975 | return switch (@as(Enum, @fromBackingInt(@intCast(code)))) { |
| 973 | .EAI_BADFLAGS => error.EAI_BADFLAGS, | 976 | .EAI_BADFLAGS => error.EAI_BADFLAGS, |
| 974 | .EAI_NONAME => error.EAI_NONAME, | 977 | .EAI_NONAME => error.EAI_NONAME, |
| 975 | .EAI_AGAIN => error.EAI_AGAIN, | 978 | .EAI_AGAIN => error.EAI_AGAIN, |
| ... | @@ -2906,10 +2909,7 @@ pub const nfds_t = c_ulong; | ... | @@ -2906,10 +2909,7 @@ pub const nfds_t = c_ulong; |
| 2906 | pub const struct_pollfd = extern struct { fd: c_int, events: c_short, revents: c_short }; | 2909 | pub const struct_pollfd = extern struct { fd: c_int, events: c_short, revents: c_short }; |
| 2907 | pub const struct_tm = extern struct { sec: c_int, min: c_int, hour: c_int, mday: c_int, mon: c_int, year: c_int, wday: c_int, yday: c_int, isdst: c_int, gmtoff: c_long, zone: [*:0]const u8 }; | 2910 | pub const struct_tm = extern struct { sec: c_int, min: c_int, hour: c_int, mday: c_int, mon: c_int, year: c_int, wday: c_int, yday: c_int, isdst: c_int, gmtoff: c_long, zone: [*:0]const u8 }; |
| 2908 | 2911 | ||
| 2909 | const impdef = @cImport({ | 2912 | const impdef = @import("c"); |
| 2910 | @cInclude("pthread.h"); | ||
| 2911 | @cInclude("termios.h"); | ||
| 2912 | }); | ||
| 2913 | pub const pthread_t = impdef.pthread_t; | 2913 | pub const pthread_t = impdef.pthread_t; |
| 2914 | pub const pthread_attr_t = impdef.pthread_attr_t; | 2914 | pub const pthread_attr_t = impdef.pthread_attr_t; |
| 2915 | pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; | 2915 | pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; |
| ... | @@ -2918,7 +2918,6 @@ pub const pthread_condattr_t = impdef.pthread_condattr_t; | ... | @@ -2918,7 +2918,6 @@ pub const pthread_condattr_t = impdef.pthread_condattr_t; |
| 2918 | pub const pthread_cond_t = impdef.pthread_cond_t; | 2918 | pub const pthread_cond_t = impdef.pthread_cond_t; |
| 2919 | pub const pthread_rwlockattr_t = impdef.pthread_rwlockattr_t; | 2919 | pub const pthread_rwlockattr_t = impdef.pthread_rwlockattr_t; |
| 2920 | pub const pthread_rwlock_t = impdef.pthread_rwlock_t; | 2920 | pub const pthread_rwlock_t = impdef.pthread_rwlock_t; |
| 2921 | pub const struct_termios = impdef.struct_termios; | ||
| 2922 | 2921 | ||
| 2923 | pub const AT = struct { | 2922 | pub const AT = struct { |
| 2924 | pub const FDCWD = -100; | 2923 | pub const FDCWD = -100; |
| ... | @@ -3480,7 +3479,7 @@ pub fn fstatat(fd: c_int, path: [*:0]const u8, flag: c_int) errno.Error!struct_s | ... | @@ -3480,7 +3479,7 @@ pub fn fstatat(fd: c_int, path: [*:0]const u8, flag: c_int) errno.Error!struct_s |
| 3480 | return buf; | 3479 | return buf; |
| 3481 | } | 3480 | } |
| 3482 | pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { | 3481 | pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { |
| 3483 | const rc = libc.socket(@intFromEnum(domain), ty, protocol); | 3482 | const rc = libc.socket(@backingInt(domain), ty, protocol); |
| 3484 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 3483 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 3485 | std.debug.assert(rc > 0); | 3484 | std.debug.assert(rc > 0); |
| 3486 | return @intCast(rc); | 3485 | return @intCast(rc); |
| ... | @@ -3501,7 +3500,7 @@ pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: s | ... | @@ -3501,7 +3500,7 @@ pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: s |
| 3501 | std.debug.assert(rc == 0); | 3500 | std.debug.assert(rc == 0); |
| 3502 | } | 3501 | } |
| 3503 | pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { | 3502 | pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { |
| 3504 | const rc = libc.shutdown(@intCast(socketfd), @intFromEnum(how)); | 3503 | const rc = libc.shutdown(@intCast(socketfd), @backingInt(how)); |
| 3505 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 3504 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 3506 | std.debug.assert(rc == 0); | 3505 | std.debug.assert(rc == 0); |
| 3507 | } | 3506 | } |
netbsd.zig+58-12| ... | @@ -217,19 +217,19 @@ pub const errno = struct { | ... | @@ -217,19 +217,19 @@ pub const errno = struct { |
| 217 | // assert Enum is sequential | 217 | // assert Enum is sequential |
| 218 | var value: c_ushort = 0; // SUCCESS | 218 | var value: c_ushort = 0; // SUCCESS |
| 219 | for (std.enums.values(Enum)) |val| { | 219 | for (std.enums.values(Enum)) |val| { |
| 220 | std.debug.assert(@intFromEnum(val) > value); | 220 | std.debug.assert(@backingInt(val) > value); |
| 221 | value = @intFromEnum(val); | 221 | value = @backingInt(val); |
| 222 | } | 222 | } |
| 223 | } | 223 | } |
| 224 | comptime { | 224 | comptime { |
| 225 | // sanity test | 225 | // sanity test |
| 226 | std.debug.assert(@intFromEnum(Enum.EPERM) == 1); | 226 | std.debug.assert(@backingInt(Enum.EPERM) == 1); |
| 227 | } | 227 | } |
| 228 | const list = blk: { | 228 | const list = blk: { |
| 229 | const values = std.enums.values(Enum); | 229 | const values = std.enums.values(Enum); |
| 230 | const len = @intFromEnum(values[values.len - 1]) + 1; | 230 | const len = @backingInt(values[values.len - 1]) + 1; |
| 231 | var errors: [len]Error = @splat(error.Unexpected); | 231 | var errors: [len]Error = @splat(error.Unexpected); |
| 232 | for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f)); | 232 | for (values) |f| errors[@backingInt(f)] = @field(Error, @tagName(f)); |
| 233 | const final = errors; | 233 | const final = errors; |
| 234 | break :blk final; | 234 | break :blk final; |
| 235 | }; | 235 | }; |
| ... | @@ -280,7 +280,7 @@ pub const eai = struct { | ... | @@ -280,7 +280,7 @@ pub const eai = struct { |
| 280 | }; | 280 | }; |
| 281 | 281 | ||
| 282 | pub fn fromInt(code: c_int) Error { | 282 | pub fn fromInt(code: c_int) Error { |
| 283 | return switch (@as(Enum, @enumFromInt(code))) { | 283 | return switch (@as(Enum, @fromBackingInt(@intCast(code)))) { |
| 284 | .EAI_ADDRFAMILY => error.EAI_ADDRFAMILY, | 284 | .EAI_ADDRFAMILY => error.EAI_ADDRFAMILY, |
| 285 | .EAI_AGAIN => error.EAI_AGAIN, | 285 | .EAI_AGAIN => error.EAI_AGAIN, |
| 286 | .EAI_BADFLAGS => error.EAI_BADFLAGS, | 286 | .EAI_BADFLAGS => error.EAI_BADFLAGS, |
| ... | @@ -368,6 +368,7 @@ pub const libc = struct { | ... | @@ -368,6 +368,7 @@ pub const libc = struct { |
| 368 | pub extern fn accept4(socket: c_int, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) c_int; | 368 | pub extern fn accept4(socket: c_int, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) c_int; |
| 369 | pub extern fn shutdown(socket: c_int, how: c_int) c_int; | 369 | pub extern fn shutdown(socket: c_int, how: c_int) c_int; |
| 370 | pub extern fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) c_int; | 370 | pub extern fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) c_int; |
| 371 | pub extern fn lseek(fd: c_int, offset: off_t, whence: c_int) off_t; | ||
| 371 | }; | 372 | }; |
| 372 | 373 | ||
| 373 | pub const pid_t = i32; | 374 | pub const pid_t = i32; |
| ... | @@ -420,9 +421,7 @@ pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t }; | ... | @@ -420,9 +421,7 @@ pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t }; |
| 420 | pub const suseconds_t = c_int; | 421 | pub const suseconds_t = c_int; |
| 421 | pub const useconds_t = c_uint; | 422 | pub const useconds_t = c_uint; |
| 422 | 423 | ||
| 423 | const impdef = @cImport({ | 424 | const impdef = @import("c"); |
| 424 | @cInclude("pthread.h"); | ||
| 425 | }); | ||
| 426 | pub const pthread_t = impdef.pthread_t; | 425 | pub const pthread_t = impdef.pthread_t; |
| 427 | pub const pthread_attr_t = impdef.pthread_attr_t; | 426 | pub const pthread_attr_t = impdef.pthread_attr_t; |
| 428 | pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; | 427 | pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; |
| ... | @@ -816,6 +815,48 @@ pub const PROT = struct { | ... | @@ -816,6 +815,48 @@ pub const PROT = struct { |
| 816 | pub const EXEC = 0x04; | 815 | pub const EXEC = 0x04; |
| 817 | }; | 816 | }; |
| 818 | 817 | ||
| 818 | pub const IPV6 = struct { | ||
| 819 | pub const SOCKOPT_RESERVED1 = 3; | ||
| 820 | pub const UNICAST_HOPS = 4; | ||
| 821 | pub const MULTICAST_IF = 9; | ||
| 822 | pub const MULTICAST_HOPS = 10; | ||
| 823 | pub const MULTICAST_LOOP = 11; | ||
| 824 | pub const JOIN_GROUP = 12; | ||
| 825 | pub const LEAVE_GROUP = 13; | ||
| 826 | pub const PORTRANGE = 14; | ||
| 827 | pub const PORTALGO = 17; | ||
| 828 | pub const CHECKSUM = 26; | ||
| 829 | pub const V6ONLY = 27; | ||
| 830 | pub const IPSEC_POLICY = 28; | ||
| 831 | pub const FAITH = 29; | ||
| 832 | pub const RTHDRDSTOPTS = 35; | ||
| 833 | pub const RECVPKTINFO = 36; | ||
| 834 | pub const RECVHOPLIMIT = 37; | ||
| 835 | pub const RECVRTHDR = 38; | ||
| 836 | pub const RECVHOPOPTS = 39; | ||
| 837 | pub const RECVDSTOPTS = 40; | ||
| 838 | pub const USE_MIN_MTU = 42; | ||
| 839 | pub const RECVPATHMTU = 43; | ||
| 840 | pub const PATHMTU = 44; | ||
| 841 | pub const PKTINFO = 46; | ||
| 842 | pub const HOPLIMIT = 47; | ||
| 843 | pub const NEXTHOP = 48; | ||
| 844 | pub const HOPOPTS = 49; | ||
| 845 | pub const DSTOPTS = 50; | ||
| 846 | pub const RTHDR = 51; | ||
| 847 | pub const RECVTCLASS = 57; | ||
| 848 | pub const TCLASS = 61; | ||
| 849 | pub const DONTFRAG = 62; | ||
| 850 | pub const PREFER_TEMPADDR = 63; | ||
| 851 | pub const BINDANY = 64; | ||
| 852 | }; | ||
| 853 | |||
| 854 | pub const SEEK = struct { | ||
| 855 | pub const SET = 0; | ||
| 856 | pub const CUR = 1; | ||
| 857 | pub const END = 2; | ||
| 858 | }; | ||
| 859 | |||
| 819 | pub fn pipe2(flag: c_int) ![2]c_int { | 860 | pub fn pipe2(flag: c_int) ![2]c_int { |
| 820 | var fildes: [2]c_int = @splat(-1); | 861 | var fildes: [2]c_int = @splat(-1); |
| 821 | const rc = libc.pipe2(&fildes, flag); | 862 | const rc = libc.pipe2(&fildes, flag); |
| ... | @@ -920,7 +961,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void { | ... | @@ -920,7 +961,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void { |
| 920 | return libc.freeaddrinfo(ai); | 961 | return libc.freeaddrinfo(ai); |
| 921 | } | 962 | } |
| 922 | pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { | 963 | pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { |
| 923 | const rc = libc.socket(@intFromEnum(domain), ty, protocol); | 964 | const rc = libc.socket(@backingInt(domain), ty, protocol); |
| 924 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 965 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 925 | std.debug.assert(rc > 0); | 966 | std.debug.assert(rc > 0); |
| 926 | return @intCast(rc); | 967 | return @intCast(rc); |
| ... | @@ -938,7 +979,7 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 { | ... | @@ -938,7 +979,7 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 { |
| 938 | } | 979 | } |
| 939 | pub fn clock_gettime(clock_id: CLOCK) !struct_timespec { | 980 | pub fn clock_gettime(clock_id: CLOCK) !struct_timespec { |
| 940 | var tp: struct_timespec = undefined; | 981 | var tp: struct_timespec = undefined; |
| 941 | const rc = libc.clock_gettime(@intFromEnum(clock_id), &tp); | 982 | const rc = libc.clock_gettime(@backingInt(clock_id), &tp); |
| 942 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 983 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 943 | std.debug.assert(rc == 0); | 984 | std.debug.assert(rc == 0); |
| 944 | return tp; | 985 | return tp; |
| ... | @@ -1034,7 +1075,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add | ... | @@ -1034,7 +1075,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add |
| 1034 | return @intCast(rc); | 1075 | return @intCast(rc); |
| 1035 | } | 1076 | } |
| 1036 | pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { | 1077 | pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { |
| 1037 | const rc = libc.shutdown(@intCast(socketfd), @intFromEnum(how)); | 1078 | const rc = libc.shutdown(@intCast(socketfd), @backingInt(how)); |
| 1038 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 1079 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1039 | std.debug.assert(rc == 0); | 1080 | std.debug.assert(rc == 0); |
| 1040 | } | 1081 | } |
| ... | @@ -1043,3 +1084,8 @@ pub fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) !void { | ... | @@ -1043,3 +1084,8 @@ pub fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) !void { |
| 1043 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 1084 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1044 | std.debug.assert(rc == 0); | 1085 | std.debug.assert(rc == 0); |
| 1045 | } | 1086 | } |
| 1087 | pub fn lseek(fd: c_int, offset: off_t, whence: c_int) !void { | ||
| 1088 | const rc = libc.lseek(fd, offset, whence); | ||
| 1089 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | ||
| 1090 | std.debug.assert(rc >= 0); | ||
| 1091 | } |
openbsd.zig+10-12| ... | @@ -211,19 +211,19 @@ pub const errno = struct { | ... | @@ -211,19 +211,19 @@ pub const errno = struct { |
| 211 | // assert Enum is sequential | 211 | // assert Enum is sequential |
| 212 | var value: c_ushort = 0; // SUCCESS | 212 | var value: c_ushort = 0; // SUCCESS |
| 213 | for (std.enums.values(Enum)) |val| { | 213 | for (std.enums.values(Enum)) |val| { |
| 214 | std.debug.assert(@intFromEnum(val) > value); | 214 | std.debug.assert(@backingInt(val) > value); |
| 215 | value = @intFromEnum(val); | 215 | value = @backingInt(val); |
| 216 | } | 216 | } |
| 217 | } | 217 | } |
| 218 | comptime { | 218 | comptime { |
| 219 | // sanity test | 219 | // sanity test |
| 220 | std.debug.assert(@intFromEnum(Enum.EPERM) == 1); | 220 | std.debug.assert(@backingInt(Enum.EPERM) == 1); |
| 221 | } | 221 | } |
| 222 | const list = blk: { | 222 | const list = blk: { |
| 223 | const values = std.enums.values(Enum); | 223 | const values = std.enums.values(Enum); |
| 224 | const len = @intFromEnum(values[values.len - 1]) + 1; | 224 | const len = @backingInt(values[values.len - 1]) + 1; |
| 225 | var errors: [len]Error = @splat(error.Unexpected); | 225 | var errors: [len]Error = @splat(error.Unexpected); |
| 226 | for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f)); | 226 | for (values) |f| errors[@backingInt(f)] = @field(Error, @tagName(f)); |
| 227 | const final = errors; | 227 | const final = errors; |
| 228 | break :blk final; | 228 | break :blk final; |
| 229 | }; | 229 | }; |
| ... | @@ -274,7 +274,7 @@ pub const eai = struct { | ... | @@ -274,7 +274,7 @@ pub const eai = struct { |
| 274 | }; | 274 | }; |
| 275 | 275 | ||
| 276 | pub fn fromInt(code: c_int) Error { | 276 | pub fn fromInt(code: c_int) Error { |
| 277 | return switch (@as(Enum, @enumFromInt(code))) { | 277 | return switch (@as(Enum, @fromBackingInt(@intCast(code)))) { |
| 278 | .EAI_BADFLAGS => error.EAI_BADFLAGS, | 278 | .EAI_BADFLAGS => error.EAI_BADFLAGS, |
| 279 | .EAI_NONAME => error.EAI_NONAME, | 279 | .EAI_NONAME => error.EAI_NONAME, |
| 280 | .EAI_AGAIN => error.EAI_AGAIN, | 280 | .EAI_AGAIN => error.EAI_AGAIN, |
| ... | @@ -412,9 +412,7 @@ pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktyp | ... | @@ -412,9 +412,7 @@ pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktyp |
| 412 | pub const struct_dirent = extern struct { fileno: ino_t, off: off_t, reclen: u16, type: DT, namlen: u8, padding: [4]u8, name: [NAME_MAX + 1]u8 }; | 412 | pub const struct_dirent = extern struct { fileno: ino_t, off: off_t, reclen: u16, type: DT, namlen: u8, padding: [4]u8, name: [NAME_MAX + 1]u8 }; |
| 413 | pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t }; | 413 | pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t }; |
| 414 | 414 | ||
| 415 | const impdef = @cImport({ | 415 | const impdef = @import("c"); |
| 416 | @cInclude("pthread.h"); | ||
| 417 | }); | ||
| 418 | pub const pthread_t = impdef.pthread_t; | 416 | pub const pthread_t = impdef.pthread_t; |
| 419 | pub const pthread_attr_t = impdef.pthread_attr_t; | 417 | pub const pthread_attr_t = impdef.pthread_attr_t; |
| 420 | pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; | 418 | pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; |
| ... | @@ -931,7 +929,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void { | ... | @@ -931,7 +929,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void { |
| 931 | return libc.freeaddrinfo(ai); | 929 | return libc.freeaddrinfo(ai); |
| 932 | } | 930 | } |
| 933 | pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { | 931 | pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { |
| 934 | const rc = libc.socket(@intFromEnum(domain), ty, protocol); | 932 | const rc = libc.socket(@backingInt(domain), ty, protocol); |
| 935 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 933 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 936 | std.debug.assert(rc > 0); | 934 | std.debug.assert(rc > 0); |
| 937 | return @intCast(rc); | 935 | return @intCast(rc); |
| ... | @@ -943,7 +941,7 @@ pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: s | ... | @@ -943,7 +941,7 @@ pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: s |
| 943 | } | 941 | } |
| 944 | pub fn clock_gettime(clock_id: CLOCK) !struct_timespec { | 942 | pub fn clock_gettime(clock_id: CLOCK) !struct_timespec { |
| 945 | var tp: struct_timespec = undefined; | 943 | var tp: struct_timespec = undefined; |
| 946 | const rc = libc.clock_gettime(@intFromEnum(clock_id), &tp); | 944 | const rc = libc.clock_gettime(@backingInt(clock_id), &tp); |
| 947 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 945 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 948 | std.debug.assert(rc == 0); | 946 | std.debug.assert(rc == 0); |
| 949 | return tp; | 947 | return tp; |
| ... | @@ -1039,7 +1037,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add | ... | @@ -1039,7 +1037,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add |
| 1039 | return @intCast(rc); | 1037 | return @intCast(rc); |
| 1040 | } | 1038 | } |
| 1041 | pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { | 1039 | pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { |
| 1042 | const rc = libc.shutdown(@intCast(socketfd), @intFromEnum(how)); | 1040 | const rc = libc.shutdown(@intCast(socketfd), @backingInt(how)); |
| 1043 | if (rc == -1) return errno.fromInt(errno.fromLibC()); | 1041 | if (rc == -1) return errno.fromInt(errno.fromLibC()); |
| 1044 | std.debug.assert(rc == 0); | 1042 | std.debug.assert(rc == 0); |
| 1045 | } | 1043 | } |