authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-10-20 23:37:15-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-10-20 23:37:15-07:00
loge1f04b8d5976437f814e129486719d6e6043c04f
tree9c438cdc9ad33e3de8ae27095ebbb87cc24384cc
parent326939960399088e4fc89464eab2bfebca83793e
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

update for zig 0.17


5 files changed, 95 insertions(+), 54 deletions(-)

darwin.zig+5-5
......@@ -235,19 +235,19 @@ pub const errno = struct {
235235 // assert Enum is sequential
236236 var value: c_ushort = 0; // SUCCESS
237237 for (std.enums.values(Enum)) |val| {
238 std.debug.assert(@intFromEnum(val) > value);
239 value = @intFromEnum(val);
238 std.debug.assert(@backingInt(val) > value);
239 value = @backingInt(val);
240240 }
241241 }
242242 comptime {
243243 // sanity test
244 std.debug.assert(@intFromEnum(Enum.EPERM) == 1);
244 std.debug.assert(@backingInt(Enum.EPERM) == 1);
245245 }
246246 const list = blk: {
247247 const values = std.enums.values(Enum);
248 const len = @intFromEnum(values[values.len - 1]) + 1;
248 const len = @backingInt(values[values.len - 1]) + 1;
249249 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));
251251 const final = errors;
252252 break :blk final;
253253 };
freebsd.zig+10-12
......@@ -216,19 +216,19 @@ pub const errno = struct {
216216 // assert Enum is sequential
217217 var value: c_ushort = 0; // SUCCESS
218218 for (std.enums.values(Enum)) |val| {
219 std.debug.assert(@intFromEnum(val) > value);
220 value = @intFromEnum(val);
219 std.debug.assert(@backingInt(val) > value);
220 value = @backingInt(val);
221221 }
222222 }
223223 comptime {
224224 // sanity test
225 std.debug.assert(@intFromEnum(Enum.EPERM) == 1);
225 std.debug.assert(@backingInt(Enum.EPERM) == 1);
226226 }
227227 const list = blk: {
228228 const values = std.enums.values(Enum);
229 const len = @intFromEnum(values[values.len - 1]) + 1;
229 const len = @backingInt(values[values.len - 1]) + 1;
230230 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));
232232 const final = errors;
233233 break :blk final;
234234 };
......@@ -279,7 +279,7 @@ pub const eai = struct {
279279 };
280280
281281 pub fn fromInt(code: c_int) Error {
282 return switch (@as(Enum, @enumFromInt(code))) {
282 return switch (@as(Enum, @fromBackingInt(@intCast(code)))) {
283283 .EAI_ADDRFAMILY => error.EAI_ADDRFAMILY,
284284 .EAI_AGAIN => error.EAI_AGAIN,
285285 .EAI_BADFLAGS => error.EAI_BADFLAGS,
......@@ -423,9 +423,7 @@ pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktyp
423423pub 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 };
424424pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t };
425425
426const impdef = @cImport({
427 @cInclude("pthread.h");
428});
426const impdef = @import("c");
429427pub const pthread_t = impdef.pthread_t;
430428pub const pthread_attr_t = impdef.pthread_attr_t;
431429pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t;
......@@ -1085,7 +1083,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void {
10851083 return libc.freeaddrinfo(ai);
10861084}
10871085pub 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);
10891087 if (rc == -1) return errno.fromInt(errno.fromLibC());
10901088 std.debug.assert(rc > 0);
10911089 return @intCast(rc);
......@@ -1103,7 +1101,7 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 {
11031101}
11041102pub fn clock_gettime(clock_id: CLOCK) !struct_timespec {
11051103 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);
11071105 if (rc == -1) return errno.fromInt(errno.fromLibC());
11081106 std.debug.assert(rc == 0);
11091107 return tp;
......@@ -1200,7 +1198,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add
12001198 return @intCast(rc);
12011199}
12021200pub 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));
12041202 if (rc == -1) return errno.fromInt(errno.fromLibC());
12051203 std.debug.assert(rc == 0);
12061204}
linux.zig+12-13
......@@ -894,6 +894,9 @@ pub const errno = struct {
894894 .hppa,
895895 .hppa64,
896896 .kvx,
897 .ez80,
898 .m88k,
899 .spork8,
897900 => unreachable,
898901 };
899902
......@@ -910,19 +913,19 @@ pub const errno = struct {
910913 // assert Enum is sequential
911914 var value: c_ushort = 0; // SUCCESS
912915 for (std.enums.values(Enum)) |val| {
913 std.debug.assert(@intFromEnum(val) > value);
914 value = @intFromEnum(val);
916 std.debug.assert(@backingInt(val) > value);
917 value = @backingInt(val);
915918 }
916919 }
917920 comptime {
918921 // sanity test
919 std.debug.assert(@intFromEnum(Enum.EPERM) == 1);
922 std.debug.assert(@backingInt(Enum.EPERM) == 1);
920923 }
921924 const list = blk: {
922925 const values = std.enums.values(Enum);
923 const len = @intFromEnum(values[values.len - 1]) + 1;
926 const len = @backingInt(values[values.len - 1]) + 1;
924927 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));
926929 const final = errors;
927930 break :blk final;
928931 };
......@@ -969,7 +972,7 @@ pub const eai = struct {
969972 };
970973
971974 pub fn fromInt(code: c_int) Error {
972 return switch (@as(Enum, @enumFromInt(code))) {
975 return switch (@as(Enum, @fromBackingInt(@intCast(code)))) {
973976 .EAI_BADFLAGS => error.EAI_BADFLAGS,
974977 .EAI_NONAME => error.EAI_NONAME,
975978 .EAI_AGAIN => error.EAI_AGAIN,
......@@ -2906,10 +2909,7 @@ pub const nfds_t = c_ulong;
29062909pub const struct_pollfd = extern struct { fd: c_int, events: c_short, revents: c_short };
29072910pub 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 };
29082911
2909const impdef = @cImport({
2910 @cInclude("pthread.h");
2911 @cInclude("termios.h");
2912});
2912const impdef = @import("c");
29132913pub const pthread_t = impdef.pthread_t;
29142914pub const pthread_attr_t = impdef.pthread_attr_t;
29152915pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t;
......@@ -2918,7 +2918,6 @@ pub const pthread_condattr_t = impdef.pthread_condattr_t;
29182918pub const pthread_cond_t = impdef.pthread_cond_t;
29192919pub const pthread_rwlockattr_t = impdef.pthread_rwlockattr_t;
29202920pub const pthread_rwlock_t = impdef.pthread_rwlock_t;
2921pub const struct_termios = impdef.struct_termios;
29222921
29232922pub const AT = struct {
29242923 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
34803479 return buf;
34813480}
34823481pub 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);
34843483 if (rc == -1) return errno.fromInt(errno.fromLibC());
34853484 std.debug.assert(rc > 0);
34863485 return @intCast(rc);
......@@ -3501,7 +3500,7 @@ pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: s
35013500 std.debug.assert(rc == 0);
35023501}
35033502pub 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));
35053504 if (rc == -1) return errno.fromInt(errno.fromLibC());
35063505 std.debug.assert(rc == 0);
35073506}
netbsd.zig+58-12
......@@ -217,19 +217,19 @@ pub const errno = struct {
217217 // assert Enum is sequential
218218 var value: c_ushort = 0; // SUCCESS
219219 for (std.enums.values(Enum)) |val| {
220 std.debug.assert(@intFromEnum(val) > value);
221 value = @intFromEnum(val);
220 std.debug.assert(@backingInt(val) > value);
221 value = @backingInt(val);
222222 }
223223 }
224224 comptime {
225225 // sanity test
226 std.debug.assert(@intFromEnum(Enum.EPERM) == 1);
226 std.debug.assert(@backingInt(Enum.EPERM) == 1);
227227 }
228228 const list = blk: {
229229 const values = std.enums.values(Enum);
230 const len = @intFromEnum(values[values.len - 1]) + 1;
230 const len = @backingInt(values[values.len - 1]) + 1;
231231 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));
233233 const final = errors;
234234 break :blk final;
235235 };
......@@ -280,7 +280,7 @@ pub const eai = struct {
280280 };
281281
282282 pub fn fromInt(code: c_int) Error {
283 return switch (@as(Enum, @enumFromInt(code))) {
283 return switch (@as(Enum, @fromBackingInt(@intCast(code)))) {
284284 .EAI_ADDRFAMILY => error.EAI_ADDRFAMILY,
285285 .EAI_AGAIN => error.EAI_AGAIN,
286286 .EAI_BADFLAGS => error.EAI_BADFLAGS,
......@@ -368,6 +368,7 @@ pub const libc = struct {
368368 pub extern fn accept4(socket: c_int, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) c_int;
369369 pub extern fn shutdown(socket: c_int, how: c_int) c_int;
370370 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;
371372};
372373
373374pub const pid_t = i32;
......@@ -420,9 +421,7 @@ pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t };
420421pub const suseconds_t = c_int;
421422pub const useconds_t = c_uint;
422423
423const impdef = @cImport({
424 @cInclude("pthread.h");
425});
424const impdef = @import("c");
426425pub const pthread_t = impdef.pthread_t;
427426pub const pthread_attr_t = impdef.pthread_attr_t;
428427pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t;
......@@ -816,6 +815,48 @@ pub const PROT = struct {
816815 pub const EXEC = 0x04;
817816};
818817
818pub 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
854pub const SEEK = struct {
855 pub const SET = 0;
856 pub const CUR = 1;
857 pub const END = 2;
858};
859
819860pub fn pipe2(flag: c_int) ![2]c_int {
820861 var fildes: [2]c_int = @splat(-1);
821862 const rc = libc.pipe2(&fildes, flag);
......@@ -920,7 +961,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void {
920961 return libc.freeaddrinfo(ai);
921962}
922963pub 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);
924965 if (rc == -1) return errno.fromInt(errno.fromLibC());
925966 std.debug.assert(rc > 0);
926967 return @intCast(rc);
......@@ -938,7 +979,7 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 {
938979}
939980pub fn clock_gettime(clock_id: CLOCK) !struct_timespec {
940981 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);
942983 if (rc == -1) return errno.fromInt(errno.fromLibC());
943984 std.debug.assert(rc == 0);
944985 return tp;
......@@ -1034,7 +1075,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add
10341075 return @intCast(rc);
10351076}
10361077pub 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));
10381079 if (rc == -1) return errno.fromInt(errno.fromLibC());
10391080 std.debug.assert(rc == 0);
10401081}
......@@ -1043,3 +1084,8 @@ pub fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) !void {
10431084 if (rc == -1) return errno.fromInt(errno.fromLibC());
10441085 std.debug.assert(rc == 0);
10451086}
1087pub 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 {
211211 // assert Enum is sequential
212212 var value: c_ushort = 0; // SUCCESS
213213 for (std.enums.values(Enum)) |val| {
214 std.debug.assert(@intFromEnum(val) > value);
215 value = @intFromEnum(val);
214 std.debug.assert(@backingInt(val) > value);
215 value = @backingInt(val);
216216 }
217217 }
218218 comptime {
219219 // sanity test
220 std.debug.assert(@intFromEnum(Enum.EPERM) == 1);
220 std.debug.assert(@backingInt(Enum.EPERM) == 1);
221221 }
222222 const list = blk: {
223223 const values = std.enums.values(Enum);
224 const len = @intFromEnum(values[values.len - 1]) + 1;
224 const len = @backingInt(values[values.len - 1]) + 1;
225225 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));
227227 const final = errors;
228228 break :blk final;
229229 };
......@@ -274,7 +274,7 @@ pub const eai = struct {
274274 };
275275
276276 pub fn fromInt(code: c_int) Error {
277 return switch (@as(Enum, @enumFromInt(code))) {
277 return switch (@as(Enum, @fromBackingInt(@intCast(code)))) {
278278 .EAI_BADFLAGS => error.EAI_BADFLAGS,
279279 .EAI_NONAME => error.EAI_NONAME,
280280 .EAI_AGAIN => error.EAI_AGAIN,
......@@ -412,9 +412,7 @@ pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktyp
412412pub 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 };
413413pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t };
414414
415const impdef = @cImport({
416 @cInclude("pthread.h");
417});
415const impdef = @import("c");
418416pub const pthread_t = impdef.pthread_t;
419417pub const pthread_attr_t = impdef.pthread_attr_t;
420418pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t;
......@@ -931,7 +929,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void {
931929 return libc.freeaddrinfo(ai);
932930}
933931pub 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);
935933 if (rc == -1) return errno.fromInt(errno.fromLibC());
936934 std.debug.assert(rc > 0);
937935 return @intCast(rc);
......@@ -943,7 +941,7 @@ pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: s
943941}
944942pub fn clock_gettime(clock_id: CLOCK) !struct_timespec {
945943 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);
947945 if (rc == -1) return errno.fromInt(errno.fromLibC());
948946 std.debug.assert(rc == 0);
949947 return tp;
......@@ -1039,7 +1037,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add
10391037 return @intCast(rc);
10401038}
10411039pub 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));
10431041 if (rc == -1) return errno.fromInt(errno.fromLibC());
10441042 std.debug.assert(rc == 0);
10451043}