From e1f04b8d5976437f814e129486719d6e6043c04f Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 20 Oct 2026 23:37:15 -0700 Subject: [PATCH] update for zig 0.17 --- darwin.zig | 10 ++++---- freebsd.zig | 22 ++++++++--------- linux.zig | 25 +++++++++---------- netbsd.zig | 70 ++++++++++++++++++++++++++++++++++++++++++++--------- openbsd.zig | 22 ++++++++--------- 5 files changed, 95 insertions(+), 54 deletions(-) diff --git a/darwin.zig b/darwin.zig index 84046605bdea423ac37ec440812d9d3d39359a48..370ede90550de9eb8966da1fb2b2069d6e9f56bb 100644 --- a/darwin.zig +++ b/darwin.zig @@ -235,19 +235,19 @@ pub const errno = struct { // assert Enum is sequential var value: c_ushort = 0; // SUCCESS for (std.enums.values(Enum)) |val| { - std.debug.assert(@intFromEnum(val) > value); - value = @intFromEnum(val); + std.debug.assert(@backingInt(val) > value); + value = @backingInt(val); } } comptime { // sanity test - std.debug.assert(@intFromEnum(Enum.EPERM) == 1); + std.debug.assert(@backingInt(Enum.EPERM) == 1); } const list = blk: { const values = std.enums.values(Enum); - const len = @intFromEnum(values[values.len - 1]) + 1; + const len = @backingInt(values[values.len - 1]) + 1; var errors: [len]Error = @splat(error.Unexpected); - for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f)); + for (values) |f| errors[@backingInt(f)] = @field(Error, @tagName(f)); const final = errors; break :blk final; }; diff --git a/freebsd.zig b/freebsd.zig index 71dd9540278762b90ae5cec546ee7da41ecdcbce..ff8eb3cbebe247863b7e32f7fd3e3668ac4345f5 100644 --- a/freebsd.zig +++ b/freebsd.zig @@ -216,19 +216,19 @@ pub const errno = struct { // assert Enum is sequential var value: c_ushort = 0; // SUCCESS for (std.enums.values(Enum)) |val| { - std.debug.assert(@intFromEnum(val) > value); - value = @intFromEnum(val); + std.debug.assert(@backingInt(val) > value); + value = @backingInt(val); } } comptime { // sanity test - std.debug.assert(@intFromEnum(Enum.EPERM) == 1); + std.debug.assert(@backingInt(Enum.EPERM) == 1); } const list = blk: { const values = std.enums.values(Enum); - const len = @intFromEnum(values[values.len - 1]) + 1; + const len = @backingInt(values[values.len - 1]) + 1; var errors: [len]Error = @splat(error.Unexpected); - for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f)); + for (values) |f| errors[@backingInt(f)] = @field(Error, @tagName(f)); const final = errors; break :blk final; }; @@ -279,7 +279,7 @@ pub const eai = struct { }; pub fn fromInt(code: c_int) Error { - return switch (@as(Enum, @enumFromInt(code))) { + return switch (@as(Enum, @fromBackingInt(@intCast(code)))) { .EAI_ADDRFAMILY => error.EAI_ADDRFAMILY, .EAI_AGAIN => error.EAI_AGAIN, .EAI_BADFLAGS => error.EAI_BADFLAGS, @@ -423,9 +423,7 @@ pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktyp 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 }; pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t }; -const impdef = @cImport({ - @cInclude("pthread.h"); -}); +const impdef = @import("c"); pub const pthread_t = impdef.pthread_t; pub const pthread_attr_t = impdef.pthread_attr_t; pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; @@ -1085,7 +1083,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void { return libc.freeaddrinfo(ai); } pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { - const rc = libc.socket(@intFromEnum(domain), ty, protocol); + const rc = libc.socket(@backingInt(domain), ty, protocol); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc > 0); return @intCast(rc); @@ -1103,7 +1101,7 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 { } pub fn clock_gettime(clock_id: CLOCK) !struct_timespec { var tp: struct_timespec = undefined; - const rc = libc.clock_gettime(@intFromEnum(clock_id), &tp); + const rc = libc.clock_gettime(@backingInt(clock_id), &tp); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc == 0); return tp; @@ -1200,7 +1198,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add return @intCast(rc); } pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { - const rc = libc.shutdown(@intCast(socketfd), @intFromEnum(how)); + const rc = libc.shutdown(@intCast(socketfd), @backingInt(how)); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc == 0); } diff --git a/linux.zig b/linux.zig index bea5a9174761ac53d75dcf59a5971781385960fd..96e9ea17a69b8c4d53d3d07f6e2d44d66be4151d 100644 --- a/linux.zig +++ b/linux.zig @@ -894,6 +894,9 @@ pub const errno = struct { .hppa, .hppa64, .kvx, + .ez80, + .m88k, + .spork8, => unreachable, }; @@ -910,19 +913,19 @@ pub const errno = struct { // assert Enum is sequential var value: c_ushort = 0; // SUCCESS for (std.enums.values(Enum)) |val| { - std.debug.assert(@intFromEnum(val) > value); - value = @intFromEnum(val); + std.debug.assert(@backingInt(val) > value); + value = @backingInt(val); } } comptime { // sanity test - std.debug.assert(@intFromEnum(Enum.EPERM) == 1); + std.debug.assert(@backingInt(Enum.EPERM) == 1); } const list = blk: { const values = std.enums.values(Enum); - const len = @intFromEnum(values[values.len - 1]) + 1; + const len = @backingInt(values[values.len - 1]) + 1; var errors: [len]Error = @splat(error.Unexpected); - for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f)); + for (values) |f| errors[@backingInt(f)] = @field(Error, @tagName(f)); const final = errors; break :blk final; }; @@ -969,7 +972,7 @@ pub const eai = struct { }; pub fn fromInt(code: c_int) Error { - return switch (@as(Enum, @enumFromInt(code))) { + return switch (@as(Enum, @fromBackingInt(@intCast(code)))) { .EAI_BADFLAGS => error.EAI_BADFLAGS, .EAI_NONAME => error.EAI_NONAME, .EAI_AGAIN => error.EAI_AGAIN, @@ -2906,10 +2909,7 @@ pub const nfds_t = c_ulong; pub const struct_pollfd = extern struct { fd: c_int, events: c_short, revents: c_short }; 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 }; -const impdef = @cImport({ - @cInclude("pthread.h"); - @cInclude("termios.h"); -}); +const impdef = @import("c"); pub const pthread_t = impdef.pthread_t; pub const pthread_attr_t = impdef.pthread_attr_t; pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; @@ -2918,7 +2918,6 @@ pub const pthread_condattr_t = impdef.pthread_condattr_t; pub const pthread_cond_t = impdef.pthread_cond_t; pub const pthread_rwlockattr_t = impdef.pthread_rwlockattr_t; pub const pthread_rwlock_t = impdef.pthread_rwlock_t; -pub const struct_termios = impdef.struct_termios; pub const AT = struct { 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 return buf; } pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { - const rc = libc.socket(@intFromEnum(domain), ty, protocol); + const rc = libc.socket(@backingInt(domain), ty, protocol); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc > 0); return @intCast(rc); @@ -3501,7 +3500,7 @@ pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: s std.debug.assert(rc == 0); } pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { - const rc = libc.shutdown(@intCast(socketfd), @intFromEnum(how)); + const rc = libc.shutdown(@intCast(socketfd), @backingInt(how)); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc == 0); } diff --git a/netbsd.zig b/netbsd.zig index 730703f4d09fb990b3db7687855abb3b69bef6a6..abac85abdf91c7debff2819e96478fc6de26d1c1 100644 --- a/netbsd.zig +++ b/netbsd.zig @@ -217,19 +217,19 @@ pub const errno = struct { // assert Enum is sequential var value: c_ushort = 0; // SUCCESS for (std.enums.values(Enum)) |val| { - std.debug.assert(@intFromEnum(val) > value); - value = @intFromEnum(val); + std.debug.assert(@backingInt(val) > value); + value = @backingInt(val); } } comptime { // sanity test - std.debug.assert(@intFromEnum(Enum.EPERM) == 1); + std.debug.assert(@backingInt(Enum.EPERM) == 1); } const list = blk: { const values = std.enums.values(Enum); - const len = @intFromEnum(values[values.len - 1]) + 1; + const len = @backingInt(values[values.len - 1]) + 1; var errors: [len]Error = @splat(error.Unexpected); - for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f)); + for (values) |f| errors[@backingInt(f)] = @field(Error, @tagName(f)); const final = errors; break :blk final; }; @@ -280,7 +280,7 @@ pub const eai = struct { }; pub fn fromInt(code: c_int) Error { - return switch (@as(Enum, @enumFromInt(code))) { + return switch (@as(Enum, @fromBackingInt(@intCast(code)))) { .EAI_ADDRFAMILY => error.EAI_ADDRFAMILY, .EAI_AGAIN => error.EAI_AGAIN, .EAI_BADFLAGS => error.EAI_BADFLAGS, @@ -368,6 +368,7 @@ pub const libc = struct { pub extern fn accept4(socket: c_int, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) c_int; pub extern fn shutdown(socket: c_int, how: c_int) c_int; pub extern fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) c_int; + pub extern fn lseek(fd: c_int, offset: off_t, whence: c_int) off_t; }; pub const pid_t = i32; @@ -420,9 +421,7 @@ pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t }; pub const suseconds_t = c_int; pub const useconds_t = c_uint; -const impdef = @cImport({ - @cInclude("pthread.h"); -}); +const impdef = @import("c"); pub const pthread_t = impdef.pthread_t; pub const pthread_attr_t = impdef.pthread_attr_t; pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; @@ -816,6 +815,48 @@ pub const PROT = struct { pub const EXEC = 0x04; }; +pub const IPV6 = struct { + pub const SOCKOPT_RESERVED1 = 3; + pub const UNICAST_HOPS = 4; + pub const MULTICAST_IF = 9; + pub const MULTICAST_HOPS = 10; + pub const MULTICAST_LOOP = 11; + pub const JOIN_GROUP = 12; + pub const LEAVE_GROUP = 13; + pub const PORTRANGE = 14; + pub const PORTALGO = 17; + pub const CHECKSUM = 26; + pub const V6ONLY = 27; + pub const IPSEC_POLICY = 28; + pub const FAITH = 29; + pub const RTHDRDSTOPTS = 35; + pub const RECVPKTINFO = 36; + pub const RECVHOPLIMIT = 37; + pub const RECVRTHDR = 38; + pub const RECVHOPOPTS = 39; + pub const RECVDSTOPTS = 40; + pub const USE_MIN_MTU = 42; + pub const RECVPATHMTU = 43; + pub const PATHMTU = 44; + pub const PKTINFO = 46; + pub const HOPLIMIT = 47; + pub const NEXTHOP = 48; + pub const HOPOPTS = 49; + pub const DSTOPTS = 50; + pub const RTHDR = 51; + pub const RECVTCLASS = 57; + pub const TCLASS = 61; + pub const DONTFRAG = 62; + pub const PREFER_TEMPADDR = 63; + pub const BINDANY = 64; +}; + +pub const SEEK = struct { + pub const SET = 0; + pub const CUR = 1; + pub const END = 2; +}; + pub fn pipe2(flag: c_int) ![2]c_int { var fildes: [2]c_int = @splat(-1); const rc = libc.pipe2(&fildes, flag); @@ -920,7 +961,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void { return libc.freeaddrinfo(ai); } pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { - const rc = libc.socket(@intFromEnum(domain), ty, protocol); + const rc = libc.socket(@backingInt(domain), ty, protocol); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc > 0); return @intCast(rc); @@ -938,7 +979,7 @@ pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 { } pub fn clock_gettime(clock_id: CLOCK) !struct_timespec { var tp: struct_timespec = undefined; - const rc = libc.clock_gettime(@intFromEnum(clock_id), &tp); + const rc = libc.clock_gettime(@backingInt(clock_id), &tp); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc == 0); return tp; @@ -1034,7 +1075,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add return @intCast(rc); } pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { - const rc = libc.shutdown(@intCast(socketfd), @intFromEnum(how)); + const rc = libc.shutdown(@intCast(socketfd), @backingInt(how)); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc == 0); } @@ -1043,3 +1084,8 @@ pub fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) !void { if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc == 0); } +pub fn lseek(fd: c_int, offset: off_t, whence: c_int) !void { + const rc = libc.lseek(fd, offset, whence); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc >= 0); +} diff --git a/openbsd.zig b/openbsd.zig index 7440b269802d0e45fa9f77ed5ec4e1ec8b256d66..6e034d553ee218b2cdd60169efadaf0491b02a19 100644 --- a/openbsd.zig +++ b/openbsd.zig @@ -211,19 +211,19 @@ pub const errno = struct { // assert Enum is sequential var value: c_ushort = 0; // SUCCESS for (std.enums.values(Enum)) |val| { - std.debug.assert(@intFromEnum(val) > value); - value = @intFromEnum(val); + std.debug.assert(@backingInt(val) > value); + value = @backingInt(val); } } comptime { // sanity test - std.debug.assert(@intFromEnum(Enum.EPERM) == 1); + std.debug.assert(@backingInt(Enum.EPERM) == 1); } const list = blk: { const values = std.enums.values(Enum); - const len = @intFromEnum(values[values.len - 1]) + 1; + const len = @backingInt(values[values.len - 1]) + 1; var errors: [len]Error = @splat(error.Unexpected); - for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f)); + for (values) |f| errors[@backingInt(f)] = @field(Error, @tagName(f)); const final = errors; break :blk final; }; @@ -274,7 +274,7 @@ pub const eai = struct { }; pub fn fromInt(code: c_int) Error { - return switch (@as(Enum, @enumFromInt(code))) { + return switch (@as(Enum, @fromBackingInt(@intCast(code)))) { .EAI_BADFLAGS => error.EAI_BADFLAGS, .EAI_NONAME => error.EAI_NONAME, .EAI_AGAIN => error.EAI_AGAIN, @@ -412,9 +412,7 @@ pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktyp 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 }; pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t }; -const impdef = @cImport({ - @cInclude("pthread.h"); -}); +const impdef = @import("c"); pub const pthread_t = impdef.pthread_t; pub const pthread_attr_t = impdef.pthread_attr_t; pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t; @@ -931,7 +929,7 @@ pub fn freeaddrinfo(ai: *const struct_addrinfo) void { return libc.freeaddrinfo(ai); } pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint { - const rc = libc.socket(@intFromEnum(domain), ty, protocol); + const rc = libc.socket(@backingInt(domain), ty, protocol); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc > 0); return @intCast(rc); @@ -943,7 +941,7 @@ pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: s } pub fn clock_gettime(clock_id: CLOCK) !struct_timespec { var tp: struct_timespec = undefined; - const rc = libc.clock_gettime(@intFromEnum(clock_id), &tp); + const rc = libc.clock_gettime(@backingInt(clock_id), &tp); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc == 0); return tp; @@ -1039,7 +1037,7 @@ pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias add return @intCast(rc); } pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void { - const rc = libc.shutdown(@intCast(socketfd), @intFromEnum(how)); + const rc = libc.shutdown(@intCast(socketfd), @backingInt(how)); if (rc == -1) return errno.fromInt(errno.fromLibC()); std.debug.assert(rc == 0); } -- 2.54.0