| author | |
| committer | |
| log | 11c8c38332ada0585a8690e84c8de3affb34c935 |
| tree | dc8aa3968f27bd928111bc9aa52f8fefed5f0d76 |
| parent | 77d0a9c07e8880bdb222d87ece66a7d822a76748 |
std.c should reflect the CRT, not std.posix's bizarre view of the world.
Also:
* Audit some incorrect std.c types and function signatures
* Remove ws2_32 from std.c (dubious quality, and ws2_32 isn't libc)
* Remove remnants of Windows support in std.posix
closes https://codeberg.org/ziglang/zig/issues/3738213 files changed, 234 insertions(+), 205 deletions(-)
lib/std/Io/Dir.zig+1-1| ... | ... | @@ -12,7 +12,7 @@ const Allocator = std.mem.Allocator; |
| 12 | 12 | |
| 13 | 13 | handle: Handle, |
| 14 | 14 | |
| 15 | pub const Handle = std.posix.fd_t; | |
| 15 | pub const Handle = File.Handle; | |
| 16 | 16 | |
| 17 | 17 | pub const path = std.fs.path; |
| 18 | 18 |
lib/std/Io/File.zig+5-5| ... | ... | @@ -23,7 +23,7 @@ pub const Flags = struct { |
| 23 | 23 | nonblocking: bool, |
| 24 | 24 | }; |
| 25 | 25 | |
| 26 | pub const Handle = std.posix.fd_t; | |
| 26 | pub const Handle = if (native_os == .windows) std.os.windows.HANDLE else std.posix.fd_t; | |
| 27 | 27 | |
| 28 | 28 | pub const Reader = @import("File/Reader.zig"); |
| 29 | 29 | pub const Writer = @import("File/Writer.zig"); |
| ... | ... | @@ -34,10 +34,10 @@ pub const MemoryMap = @import("File/MemoryMap.zig"); |
| 34 | 34 | /// deadlocking. |
| 35 | 35 | pub const MultiReader = @import("File/MultiReader.zig"); |
| 36 | 36 | |
| 37 | pub const INode = std.posix.ino_t; | |
| 38 | pub const NLink = std.posix.nlink_t; | |
| 39 | pub const Uid = std.posix.uid_t; | |
| 40 | pub const Gid = std.posix.gid_t; | |
| 37 | pub const INode = if (native_os == .windows) std.os.windows.LARGE_INTEGER else std.posix.ino_t; | |
| 38 | pub const NLink = if (native_os == .windows) std.os.windows.ULONG else std.posix.nlink_t; | |
| 39 | pub const Uid = if (native_os == .windows) void else std.posix.uid_t; | |
| 40 | pub const Gid = if (native_os == .windows) void else std.posix.gid_t; | |
| 41 | 41 | pub const BlockSize = u32; |
| 42 | 42 | |
| 43 | 43 | pub const Kind = enum { |
lib/std/Io/Threaded.zig+74-65| ... | ... | @@ -1614,7 +1614,7 @@ pub const default_PATH = "/usr/local/bin:/bin:/usr/bin"; |
| 1614 | 1614 | const max_windows_kernel_bug_retries = 13; |
| 1615 | 1615 | |
| 1616 | 1616 | comptime { |
| 1617 | if (@TypeOf(posix.IOV_MAX) != void) assert(max_iovecs_len <= posix.IOV_MAX); | |
| 1617 | if (!is_windows and @TypeOf(posix.IOV_MAX) != void) assert(max_iovecs_len <= posix.IOV_MAX); | |
| 1618 | 1618 | } |
| 1619 | 1619 | |
| 1620 | 1620 | pub const InitOptions = struct { |
| ... | ... | @@ -1696,7 +1696,7 @@ pub fn init( |
| 1696 | 1696 | .disable_memory_mapping = options.disable_memory_mapping, |
| 1697 | 1697 | }; |
| 1698 | 1698 | |
| 1699 | if (posix.Sigaction != void) { | |
| 1699 | if (!is_windows and posix.Sigaction != void) { | |
| 1700 | 1700 | // This causes sending `posix.SIG.IO` to thread to interrupt blocking |
| 1701 | 1701 | // syscalls, returning `posix.E.INTR`. |
| 1702 | 1702 | const act: posix.Sigaction = .{ |
| ... | ... | @@ -1758,7 +1758,7 @@ pub fn setAsyncLimit(t: *Threaded, new_limit: Io.Limit) void { |
| 1758 | 1758 | |
| 1759 | 1759 | pub fn deinit(t: *Threaded) void { |
| 1760 | 1760 | t.join(); |
| 1761 | if (posix.Sigaction != void and t.have_signal_handler) { | |
| 1761 | if (!is_windows and posix.Sigaction != void and t.have_signal_handler) { | |
| 1762 | 1762 | if (have_sig_io) posix.sigaction(.IO, &t.old_sig_io, null); |
| 1763 | 1763 | if (have_sig_pipe) posix.sigaction(.PIPE, &t.old_sig_pipe, null); |
| 1764 | 1764 | } |
| ... | ... | @@ -2009,8 +2009,8 @@ const have_preadv = switch (native_os) { |
| 2009 | 2009 | .windows, .haiku => false, |
| 2010 | 2010 | else => true, |
| 2011 | 2011 | }; |
| 2012 | const have_sig_io = posix.SIG != void and @hasField(posix.SIG, "IO"); | |
| 2013 | const have_sig_pipe = posix.SIG != void and @hasField(posix.SIG, "PIPE"); | |
| 2012 | const have_sig_io = !is_windows and posix.SIG != void and @hasField(posix.SIG, "IO"); | |
| 2013 | const have_sig_pipe = !is_windows and posix.SIG != void and @hasField(posix.SIG, "PIPE"); | |
| 2014 | 2014 | const have_sendfile = if (builtin.link_libc) @TypeOf(std.c.sendfile) != void else native_os == .linux; |
| 2015 | 2015 | const have_copy_file_range = switch (native_os) { |
| 2016 | 2016 | .linux, .freebsd => true, |
| ... | ... | @@ -7283,6 +7283,8 @@ fn fileHardLink( |
| 7283 | 7283 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 7284 | 7284 | _ = t; |
| 7285 | 7285 | |
| 7286 | if (is_windows) return error.OperationUnsupported; | |
| 7287 | ||
| 7286 | 7288 | var new_path_buffer: [posix.PATH_MAX]u8 = undefined; |
| 7287 | 7289 | const new_sub_path_posix = try pathToPosix(new_sub_path, &new_path_buffer); |
| 7288 | 7290 | |
| ... | ... | @@ -12229,7 +12231,7 @@ fn netListenUnixPosix( |
| 12229 | 12231 | if (!net.has_unix_sockets) return error.AddressFamilyUnsupported; |
| 12230 | 12232 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 12231 | 12233 | _ = t; |
| 12232 | const socket_fd = openSocketPosix(posix.AF.UNIX, .{ .mode = .stream }) catch |err| switch (err) { | |
| 12234 | const socket_fd = openSocketPosix(AF.UNIX, .{ .mode = .stream }) catch |err| switch (err) { | |
| 12233 | 12235 | error.ProtocolUnsupportedBySystem => return error.AddressFamilyUnsupported, |
| 12234 | 12236 | error.ProtocolUnsupportedByAddressFamily => return error.AddressFamilyUnsupported, |
| 12235 | 12237 | error.SocketModeUnsupported => return error.AddressFamilyUnsupported, |
| ... | ... | @@ -12308,8 +12310,8 @@ fn netListenUnixWindows( |
| 12308 | 12310 | |
| 12309 | 12311 | fn posixBindUnix( |
| 12310 | 12312 | fd: posix.socket_t, |
| 12311 | addr: *const posix.sockaddr, | |
| 12312 | addr_len: posix.socklen_t, | |
| 12313 | addr: *const sockaddr, | |
| 12314 | addr_len: socklen_t, | |
| 12313 | 12315 | ) !void { |
| 12314 | 12316 | const syscall: Syscall = try .start(); |
| 12315 | 12317 | while (true) { |
| ... | ... | @@ -12351,8 +12353,8 @@ fn posixBindUnix( |
| 12351 | 12353 | |
| 12352 | 12354 | fn posixBind( |
| 12353 | 12355 | socket_fd: posix.socket_t, |
| 12354 | addr: *const posix.sockaddr, | |
| 12355 | addr_len: posix.socklen_t, | |
| 12356 | addr: *const sockaddr, | |
| 12357 | addr_len: socklen_t, | |
| 12356 | 12358 | ) !void { |
| 12357 | 12359 | const syscall: Syscall = try .start(); |
| 12358 | 12360 | while (true) { |
| ... | ... | @@ -12386,8 +12388,8 @@ fn posixBind( |
| 12386 | 12388 | |
| 12387 | 12389 | fn posixConnect( |
| 12388 | 12390 | socket_fd: posix.socket_t, |
| 12389 | addr: *const posix.sockaddr, | |
| 12390 | addr_len: posix.socklen_t, | |
| 12391 | addr: *const sockaddr, | |
| 12392 | addr_len: socklen_t, | |
| 12391 | 12393 | ) !void { |
| 12392 | 12394 | const syscall: Syscall = try .start(); |
| 12393 | 12395 | while (true) switch (posix.errno(posix.system.connect(socket_fd, addr, addr_len))) { |
| ... | ... | @@ -12424,8 +12426,8 @@ fn posixConnect( |
| 12424 | 12426 | |
| 12425 | 12427 | fn posixConnectUnix( |
| 12426 | 12428 | fd: posix.socket_t, |
| 12427 | addr: *const posix.sockaddr, | |
| 12428 | addr_len: posix.socklen_t, | |
| 12429 | addr: *const sockaddr, | |
| 12430 | addr_len: socklen_t, | |
| 12429 | 12431 | ) !void { |
| 12430 | 12432 | const syscall: Syscall = try .start(); |
| 12431 | 12433 | while (true) { |
| ... | ... | @@ -12468,8 +12470,8 @@ fn posixConnectUnix( |
| 12468 | 12470 | |
| 12469 | 12471 | fn posixGetSockName( |
| 12470 | 12472 | socket_fd: posix.fd_t, |
| 12471 | addr: *posix.sockaddr, | |
| 12472 | addr_len: *posix.socklen_t, | |
| 12473 | addr: *sockaddr, | |
| 12474 | addr_len: *socklen_t, | |
| 12473 | 12475 | ) !void { |
| 12474 | 12476 | const syscall: Syscall = try .start(); |
| 12475 | 12477 | while (true) { |
| ... | ... | @@ -12610,7 +12612,7 @@ fn netConnectUnixPosix( |
| 12610 | 12612 | if (!net.has_unix_sockets) return error.AddressFamilyUnsupported; |
| 12611 | 12613 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 12612 | 12614 | _ = t; |
| 12613 | const socket_fd = openSocketPosix(posix.AF.UNIX, .{ .mode = .stream }) catch |err| switch (err) { | |
| 12615 | const socket_fd = openSocketPosix(AF.UNIX, .{ .mode = .stream }) catch |err| switch (err) { | |
| 12614 | 12616 | error.ProtocolUnsupportedByAddressFamily => return error.AddressFamilyUnsupported, |
| 12615 | 12617 | error.OptionUnsupported => return error.Unexpected, |
| 12616 | 12618 | else => |e| return e, |
| ... | ... | @@ -12705,7 +12707,7 @@ fn netBindIpWindows( |
| 12705 | 12707 | } |
| 12706 | 12708 | |
| 12707 | 12709 | fn openSocketPosix( |
| 12708 | family: posix.sa_family_t, | |
| 12710 | family: sa_family_t, | |
| 12709 | 12711 | options: IpAddress.BindOptions, |
| 12710 | 12712 | ) error{ |
| 12711 | 12713 | AddressFamilyUnsupported, |
| ... | ... | @@ -12720,7 +12722,7 @@ fn openSocketPosix( |
| 12720 | 12722 | Canceled, |
| 12721 | 12723 | }!posix.socket_t { |
| 12722 | 12724 | const mode, const protocol = try posixSocketModeProtocol(family, options.mode, options.protocol); |
| 12723 | const flags: u32 = mode | if (socket_flags_unsupported) 0 else posix.SOCK.CLOEXEC; | |
| 12725 | const flags: u32 = mode | if (socket_flags_unsupported) 0 else SOCK.CLOEXEC; | |
| 12724 | 12726 | const syscall: Syscall = try .start(); |
| 12725 | 12727 | const socket_fd = while (true) { |
| 12726 | 12728 | const rc = posix.system.socket(family, flags, protocol); |
| ... | ... | @@ -12751,7 +12753,7 @@ fn openSocketPosix( |
| 12751 | 12753 | |
| 12752 | 12754 | if (options.ip6_only) |ip6_only| { |
| 12753 | 12755 | if (posix.IPV6 == void) return error.OptionUnsupported; |
| 12754 | try setSocketOptionPosix(socket_fd, posix.IPPROTO.IPV6, posix.IPV6.V6ONLY, @intFromBool(ip6_only)); | |
| 12756 | try setSocketOptionPosix(socket_fd, IPPROTO.IPV6, posix.IPV6.V6ONLY, @intFromBool(ip6_only)); | |
| 12755 | 12757 | } |
| 12756 | 12758 | |
| 12757 | 12759 | return socket_fd; |
| ... | ... | @@ -12776,15 +12778,15 @@ fn netSocketCreatePair( |
| 12776 | 12778 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 12777 | 12779 | _ = t; |
| 12778 | 12780 | if (!have_networking) return error.OperationUnsupported; |
| 12779 | if (@TypeOf(posix.system.socketpair) == void) return error.OperationUnsupported; | |
| 12781 | if (is_windows or @TypeOf(posix.system.socketpair) == void) return error.OperationUnsupported; | |
| 12780 | 12782 | if (native_os == .haiku) @panic("TODO"); |
| 12781 | 12783 | |
| 12782 | const family: posix.sa_family_t = switch (options.family) { | |
| 12783 | .ip4 => posix.AF.INET, | |
| 12784 | .ip6 => posix.AF.INET6, | |
| 12784 | const family: sa_family_t = switch (options.family) { | |
| 12785 | .ip4 => AF.INET, | |
| 12786 | .ip6 => AF.INET6, | |
| 12785 | 12787 | }; |
| 12786 | 12788 | const mode, const protocol = try posixSocketModeProtocol(family, options.mode, options.protocol); |
| 12787 | const flags: u32 = mode | if (socket_flags_unsupported) 0 else posix.SOCK.CLOEXEC; | |
| 12789 | const flags: u32 = mode | if (socket_flags_unsupported) 0 else SOCK.CLOEXEC; | |
| 12788 | 12790 | |
| 12789 | 12791 | var sockets: [2]posix.socket_t = undefined; |
| 12790 | 12792 | const syscall: Syscall = try .start(); |
| ... | ... | @@ -12800,7 +12802,7 @@ fn netSocketCreatePair( |
| 12800 | 12802 | try setCloexec(sockets[1]); |
| 12801 | 12803 | } |
| 12802 | 12804 | var storages: [2]PosixAddress = undefined; |
| 12803 | var addr_lens: [2]posix.socklen_t = .{ @sizeOf(PosixAddress), @sizeOf(PosixAddress) }; | |
| 12805 | var addr_lens: [2]socklen_t = .{ @sizeOf(PosixAddress), @sizeOf(PosixAddress) }; | |
| 12804 | 12806 | try posixGetSockName(sockets[0], &storages[0].any, &addr_lens[0]); |
| 12805 | 12807 | try posixGetSockName(sockets[1], &storages[1].any, &addr_lens[1]); |
| 12806 | 12808 | return .{ |
| ... | ... | @@ -12926,11 +12928,11 @@ fn netAccept(t: *Threaded, listen_fd: net.Socket.Handle, options: net.Server.Acc |
| 12926 | 12928 | |
| 12927 | 12929 | fn netAcceptPosix(listen_fd: net.Socket.Handle) net.Server.AcceptError!net.Socket { |
| 12928 | 12930 | var storage: PosixAddress = undefined; |
| 12929 | var addr_len: posix.socklen_t = @sizeOf(PosixAddress); | |
| 12931 | var addr_len: socklen_t = @sizeOf(PosixAddress); | |
| 12930 | 12932 | const syscall: Syscall = try .start(); |
| 12931 | 12933 | const fd = while (true) { |
| 12932 | 12934 | const rc = if (have_accept4) |
| 12933 | posix.system.accept4(listen_fd, &storage.any, &addr_len, posix.SOCK.CLOEXEC) | |
| 12935 | posix.system.accept4(listen_fd, &storage.any, &addr_len, SOCK.CLOEXEC) | |
| 12934 | 12936 | else |
| 12935 | 12937 | posix.system.accept(listen_fd, &storage.any, &addr_len); |
| 12936 | 12938 | switch (posix.errno(rc)) { |
| ... | ... | @@ -13788,7 +13790,7 @@ fn netInterfaceNameResolve( |
| 13788 | 13790 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 13789 | 13791 | |
| 13790 | 13792 | if (native_os == .linux) { |
| 13791 | const sock_fd = openSocketPosix(posix.AF.UNIX, .{ .mode = .dgram }) catch |err| switch (err) { | |
| 13793 | const sock_fd = openSocketPosix(AF.UNIX, .{ .mode = .dgram }) catch |err| switch (err) { | |
| 13792 | 13794 | error.ProcessFdQuotaExceeded => return error.SystemResources, |
| 13793 | 13795 | error.SystemFdQuotaExceeded => return error.SystemResources, |
| 13794 | 13796 | error.AddressFamilyUnsupported => return error.Unexpected, |
| ... | ... | @@ -13950,7 +13952,7 @@ fn netInterfaceName(userdata: ?*anyopaque, interface: net.Interface) net.Interfa |
| 13950 | 13952 | else => |err| return windows.unexpectedError(err), |
| 13951 | 13953 | } |
| 13952 | 13954 | var name_w: [net.Interface.Name.max_len:0]windows.WCHAR = undefined; |
| 13953 | switch (ConvertInterfaceLuidToNameW.?(&luid, &name_w, name_w.len)) { | |
| 13955 | switch (ConvertInterfaceLuidToNameW.?(&luid, &name_w, name_w.len + 1)) { | |
| 13954 | 13956 | .SUCCESS => {}, |
| 13955 | 13957 | .INVALID_PARAMETER => unreachable, |
| 13956 | 13958 | .NOT_ENOUGH_MEMORY => return error.NameTooLong, |
| ... | ... | @@ -14227,15 +14229,15 @@ fn netLookupFallible( |
| 14227 | 14229 | const port_c = std.mem.printSentinel(&port_buffer, "{d}", .{options.port}, 0) catch unreachable; |
| 14228 | 14230 | |
| 14229 | 14231 | const family: i32 = if (options.family) |f| switch (f) { |
| 14230 | .ip4 => posix.AF.INET, | |
| 14231 | .ip6 => posix.AF.INET6, | |
| 14232 | } else posix.AF.UNSPEC; | |
| 14232 | .ip4 => AF.INET, | |
| 14233 | .ip6 => AF.INET6, | |
| 14234 | } else AF.UNSPEC; | |
| 14233 | 14235 | |
| 14234 | 14236 | const hints: posix.addrinfo = .{ |
| 14235 | 14237 | .flags = .{ .CANONNAME = options.canonical_name_buffer != null, .NUMERICSERV = true }, |
| 14236 | 14238 | .family = family, |
| 14237 | .socktype = posix.SOCK.STREAM, | |
| 14238 | .protocol = posix.IPPROTO.TCP, | |
| 14239 | .socktype = SOCK.STREAM, | |
| 14240 | .protocol = IPPROTO.TCP, | |
| 14239 | 14241 | .canonname = null, |
| 14240 | 14242 | .addr = null, |
| 14241 | 14243 | .addrlen = 0, |
| ... | ... | @@ -14489,47 +14491,54 @@ fn processSetCurrentPath(userdata: ?*anyopaque, path: []const u8) process.SetCur |
| 14489 | 14491 | return chdir(path); |
| 14490 | 14492 | } |
| 14491 | 14493 | |
| 14494 | const sockaddr = if (is_windows) ws2_32.sockaddr else posix.sockaddr; | |
| 14495 | const sa_family_t = if (is_windows) ws2_32.ADDRESS_FAMILY else posix.sa_family_t; | |
| 14496 | const socklen_t = if (is_windows) ws2_32.socklen_t else posix.socklen_t; | |
| 14497 | const AF = if (is_windows) ws2_32.AF else posix.AF; | |
| 14498 | const SOCK = if (is_windows) ws2_32.SOCK else posix.SOCK; | |
| 14499 | const IPPROTO = if (is_windows) ws2_32.IPPROTO else posix.IPPROTO; | |
| 14500 | ||
| 14492 | 14501 | pub const PosixAddress = extern union { |
| 14493 | any: posix.sockaddr, | |
| 14494 | in: posix.sockaddr.in, | |
| 14495 | in6: posix.sockaddr.in6, | |
| 14502 | any: sockaddr, | |
| 14503 | in: sockaddr.in, | |
| 14504 | in6: sockaddr.in6, | |
| 14496 | 14505 | }; |
| 14497 | 14506 | |
| 14498 | 14507 | const UnixAddress = extern union { |
| 14499 | any: posix.sockaddr, | |
| 14500 | un: posix.sockaddr.un, | |
| 14508 | any: sockaddr, | |
| 14509 | un: sockaddr.un, | |
| 14501 | 14510 | }; |
| 14502 | 14511 | |
| 14503 | pub fn posixAddressFamily(a: *const IpAddress) posix.sa_family_t { | |
| 14512 | pub fn posixAddressFamily(a: *const IpAddress) sa_family_t { | |
| 14504 | 14513 | return switch (a.*) { |
| 14505 | .ip4 => posix.AF.INET, | |
| 14506 | .ip6 => posix.AF.INET6, | |
| 14514 | .ip4 => AF.INET, | |
| 14515 | .ip6 => AF.INET6, | |
| 14507 | 14516 | }; |
| 14508 | 14517 | } |
| 14509 | 14518 | |
| 14510 | 14519 | pub fn addressFromPosix(posix_address: *const PosixAddress) IpAddress { |
| 14511 | 14520 | return switch (posix_address.any.family) { |
| 14512 | posix.AF.INET => .{ .ip4 = address4FromPosix(&posix_address.in) }, | |
| 14513 | posix.AF.INET6 => .{ .ip6 = address6FromPosix(&posix_address.in6) }, | |
| 14521 | AF.INET => .{ .ip4 = address4FromPosix(&posix_address.in) }, | |
| 14522 | AF.INET6 => .{ .ip6 = address6FromPosix(&posix_address.in6) }, | |
| 14514 | 14523 | else => .{ .ip4 = .loopback(0) }, |
| 14515 | 14524 | }; |
| 14516 | 14525 | } |
| 14517 | 14526 | |
| 14518 | pub fn addressToPosix(a: *const IpAddress, storage: *PosixAddress) posix.socklen_t { | |
| 14527 | pub fn addressToPosix(a: *const IpAddress, storage: *PosixAddress) socklen_t { | |
| 14519 | 14528 | return switch (a.*) { |
| 14520 | 14529 | .ip4 => |ip4| { |
| 14521 | 14530 | storage.in = address4ToPosix(ip4); |
| 14522 | return @sizeOf(posix.sockaddr.in); | |
| 14531 | return @sizeOf(sockaddr.in); | |
| 14523 | 14532 | }, |
| 14524 | 14533 | .ip6 => |*ip6| { |
| 14525 | 14534 | storage.in6 = address6ToPosix(ip6); |
| 14526 | return @sizeOf(posix.sockaddr.in6); | |
| 14535 | return @sizeOf(sockaddr.in6); | |
| 14527 | 14536 | }, |
| 14528 | 14537 | }; |
| 14529 | 14538 | } |
| 14530 | 14539 | |
| 14531 | fn addressUnixToPosix(a: *const net.UnixAddress, storage: *UnixAddress) posix.socklen_t { | |
| 14532 | storage.un.family = posix.AF.UNIX; | |
| 14540 | fn addressUnixToPosix(a: *const net.UnixAddress, storage: *UnixAddress) socklen_t { | |
| 14541 | storage.un.family = AF.UNIX; | |
| 14533 | 14542 | var path_len = switch (native_os) { |
| 14534 | 14543 | .windows => @min(a.path.len, storage.un.path.len), |
| 14535 | 14544 | else => a.path.len, |
| ... | ... | @@ -14545,13 +14554,13 @@ fn addressUnixToPosix(a: *const net.UnixAddress, storage: *UnixAddress) posix.so |
| 14545 | 14554 | switch (native_os) { |
| 14546 | 14555 | .windows => { |
| 14547 | 14556 | if (storage.un.path[0] == 0) @memset(storage.un.path[path_len..], 0); |
| 14548 | return @sizeOf(posix.sockaddr.un); | |
| 14557 | return @sizeOf(sockaddr.un); | |
| 14549 | 14558 | }, |
| 14550 | else => return @intCast(@offsetOf(posix.sockaddr.un, "path") + path_len), | |
| 14559 | else => return @intCast(@offsetOf(sockaddr.un, "path") + path_len), | |
| 14551 | 14560 | } |
| 14552 | 14561 | } |
| 14553 | 14562 | |
| 14554 | fn address4FromPosix(in: *const posix.sockaddr.in) net.Ip4Address { | |
| 14563 | fn address4FromPosix(in: *const sockaddr.in) net.Ip4Address { | |
| 14555 | 14564 | // The network byte order address in `in.addr` is already the byte order we want. |
| 14556 | 14565 | const addr_bytes: *const [4]u8 = @ptrCast(&in.addr); |
| 14557 | 14566 | return .{ |
| ... | ... | @@ -14560,7 +14569,7 @@ fn address4FromPosix(in: *const posix.sockaddr.in) net.Ip4Address { |
| 14560 | 14569 | }; |
| 14561 | 14570 | } |
| 14562 | 14571 | |
| 14563 | fn address6FromPosix(in6: *const posix.sockaddr.in6) net.Ip6Address { | |
| 14572 | fn address6FromPosix(in6: *const sockaddr.in6) net.Ip6Address { | |
| 14564 | 14573 | return .{ |
| 14565 | 14574 | .port = std.mem.bigToNative(u16, in6.port), |
| 14566 | 14575 | .bytes = in6.addr, |
| ... | ... | @@ -14569,7 +14578,7 @@ fn address6FromPosix(in6: *const posix.sockaddr.in6) net.Ip6Address { |
| 14569 | 14578 | }; |
| 14570 | 14579 | } |
| 14571 | 14580 | |
| 14572 | fn address4ToPosix(a: net.Ip4Address) posix.sockaddr.in { | |
| 14581 | fn address4ToPosix(a: net.Ip4Address) sockaddr.in { | |
| 14573 | 14582 | // The byte order of `a.bytes` is already equivalent to a network byte order address. |
| 14574 | 14583 | const addr_raw: *align(1) const u32 = @ptrCast(&a.bytes); |
| 14575 | 14584 | return .{ |
| ... | ... | @@ -14578,7 +14587,7 @@ fn address4ToPosix(a: net.Ip4Address) posix.sockaddr.in { |
| 14578 | 14587 | }; |
| 14579 | 14588 | } |
| 14580 | 14589 | |
| 14581 | fn address6ToPosix(a: *const net.Ip6Address) posix.sockaddr.in6 { | |
| 14590 | fn address6ToPosix(a: *const net.Ip6Address) sockaddr.in6 { | |
| 14582 | 14591 | return .{ |
| 14583 | 14592 | .port = std.mem.nativeToBig(u16, a.port), |
| 14584 | 14593 | .flowinfo = a.flow, |
| ... | ... | @@ -14592,21 +14601,21 @@ pub fn errnoBug(err: posix.E) Io.UnexpectedError { |
| 14592 | 14601 | return error.Unexpected; |
| 14593 | 14602 | } |
| 14594 | 14603 | |
| 14595 | pub fn posixSocketModeProtocol(family: posix.sa_family_t, mode: net.Socket.Mode, protocol: ?net.Protocol) !struct { u32, u32 } { | |
| 14604 | pub fn posixSocketModeProtocol(family: sa_family_t, mode: net.Socket.Mode, protocol: ?net.Protocol) !struct { u32, u32 } { | |
| 14596 | 14605 | return .{ |
| 14597 | 14606 | switch (mode) { |
| 14598 | .stream => posix.SOCK.STREAM, | |
| 14599 | .dgram => posix.SOCK.DGRAM, | |
| 14600 | .seqpacket => posix.SOCK.SEQPACKET, | |
| 14601 | .raw => posix.SOCK.RAW, | |
| 14602 | .rdm => if (@hasDecl(posix.SOCK, "RDM")) posix.SOCK.RDM else return error.OptionUnsupported, | |
| 14607 | .stream => SOCK.STREAM, | |
| 14608 | .dgram => SOCK.DGRAM, | |
| 14609 | .seqpacket => SOCK.SEQPACKET, | |
| 14610 | .raw => SOCK.RAW, | |
| 14611 | .rdm => if (@hasDecl(SOCK, "RDM")) SOCK.RDM else return error.OptionUnsupported, | |
| 14603 | 14612 | }, |
| 14604 | 14613 | if (protocol) |p| @backingInt(p) else if (is_windows) switch (family) { |
| 14605 | posix.AF.UNIX => switch (mode) { | |
| 14614 | AF.UNIX => switch (mode) { | |
| 14606 | 14615 | .stream => 0, |
| 14607 | 14616 | else => return error.ProtocolUnsupportedByAddressFamily, |
| 14608 | 14617 | }, |
| 14609 | posix.AF.INET, posix.AF.INET6 => @backingInt(@as(net.Protocol, switch (mode) { | |
| 14618 | AF.INET, AF.INET6 => @backingInt(@as(net.Protocol, switch (mode) { | |
| 14610 | 14619 | .stream => .tcp, |
| 14611 | 14620 | .dgram => .udp, |
| 14612 | 14621 | else => return error.ProtocolUnsupportedByAddressFamily, |
| ... | ... | @@ -17992,7 +18001,7 @@ fn progressParentFile(userdata: ?*anyopaque) std.Progress.ParentFileError!File { |
| 17992 | 18001 | return t.environ.zig_progress_file; |
| 17993 | 18002 | } |
| 17994 | 18003 | |
| 17995 | fn inheritParentHandle(handle: posix.fd_t) Io.InheritParentHandleError!void { | |
| 18004 | fn inheritParentHandle(handle: File.Handle) Io.InheritParentHandleError!void { | |
| 17996 | 18005 | switch (native_os) { |
| 17997 | 18006 | .linux, |
| 17998 | 18007 | .dragonfly, |
lib/std/Io/net.zig+8-3| ... | ... | @@ -1016,7 +1016,12 @@ pub const Interface = struct { |
| 1016 | 1016 | pub const Name = struct { |
| 1017 | 1017 | bytes: [max_len:0]u8, |
| 1018 | 1018 | |
| 1019 | pub const max_len = if (@TypeOf(std.posix.IFNAMESIZE) == void) 0 else std.posix.IFNAMESIZE - 1; | |
| 1019 | pub const max_len = if (native_os == .windows) | |
| 1020 | std.os.windows.IF.MAX_STRING_SIZE | |
| 1021 | else if (@TypeOf(std.posix.IFNAMESIZE) == void) | |
| 1022 | 0 | |
| 1023 | else | |
| 1024 | std.posix.IFNAMESIZE - 1; | |
| 1020 | 1025 | |
| 1021 | 1026 | pub fn toSlice(n: *const Name) []const u8 { |
| 1022 | 1027 | return std.mem.sliceTo(&n.bytes, 0); |
| ... | ... | @@ -1094,7 +1099,7 @@ pub const Socket = struct { |
| 1094 | 1099 | |
| 1095 | 1100 | /// Underlying platform-defined type which may or may not be |
| 1096 | 1101 | /// interchangeable with a file system file descriptor. |
| 1097 | pub const Handle = std.posix.fd_t; | |
| 1102 | pub const Handle = if (native_os == .windows) std.os.windows.HANDLE else std.posix.fd_t; | |
| 1098 | 1103 | |
| 1099 | 1104 | /// Leaves `address` in a valid state. |
| 1100 | 1105 | pub fn close(s: *const Socket, io: Io) void { |
| ... | ... | @@ -1517,7 +1522,7 @@ pub const Stream = struct { |
| 1517 | 1522 | } |
| 1518 | 1523 | }; |
| 1519 | 1524 | |
| 1520 | pub const cmsg_align = if (@TypeOf(std.posix.cmsg_align) == void) 1 else std.posix.cmsg_align; | |
| 1525 | pub const cmsg_align = if (native_os == .windows or @TypeOf(std.posix.cmsg_align) == void) 1 else std.posix.cmsg_align; | |
| 1521 | 1526 | /// Utility Functions for interacting with POSIX socket control messages. |
| 1522 | 1527 | /// See also https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_socket.h.html |
| 1523 | 1528 | pub const cmsg = struct { |
lib/std/c.zig+74-46| ... | ... | @@ -12,7 +12,6 @@ const page_size = std.heap.page_size_min; |
| 12 | 12 | const linux = std.os.linux; |
| 13 | 13 | const emscripten = std.os.emscripten; |
| 14 | 14 | const windows = std.os.windows; |
| 15 | const ws2_32 = std.os.windows.ws2_32; | |
| 16 | 15 | const darwin = @import("c/darwin.zig"); |
| 17 | 16 | const freebsd = @import("c/freebsd.zig"); |
| 18 | 17 | const illumos = @import("c/illumos.zig"); |
| ... | ... | @@ -79,7 +78,7 @@ pub fn errno(rc: anytype) E { |
| 79 | 78 | pub const ino_t = switch (native_os) { |
| 80 | 79 | .linux => linux.ino_t, |
| 81 | 80 | .emscripten => emscripten.ino_t, |
| 82 | .windows => windows.LARGE_INTEGER, | |
| 81 | .windows => c_ushort, | |
| 83 | 82 | .haiku => i64, |
| 84 | 83 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L38 |
| 85 | 84 | else => u64, |
| ... | ... | @@ -138,9 +137,10 @@ pub const dev_t = switch (native_os) { |
| 138 | 137 | pub const mode_t = switch (native_os) { |
| 139 | 138 | .linux => linux.mode_t, |
| 140 | 139 | .emscripten => emscripten.mode_t, |
| 141 | .openbsd, .haiku, .netbsd, .illumos, .windows => u32, | |
| 140 | .openbsd, .haiku, .netbsd, .illumos => u32, | |
| 142 | 141 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L44 |
| 143 | 142 | .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .dragonfly, .serenity => u16, |
| 143 | .windows => c_ushort, | |
| 144 | 144 | else => u0, |
| 145 | 145 | }; |
| 146 | 146 | |
| ... | ... | @@ -149,7 +149,7 @@ pub const nlink_t = switch (native_os) { |
| 149 | 149 | .emscripten => emscripten.nlink_t, |
| 150 | 150 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L45 |
| 151 | 151 | .freebsd, .serenity => u64, |
| 152 | .openbsd, .netbsd, .dragonfly, .illumos, .windows => u32, | |
| 152 | .openbsd, .netbsd, .dragonfly, .illumos => u32, | |
| 153 | 153 | .haiku => i32, |
| 154 | 154 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u16, |
| 155 | 155 | else => u0, |
| ... | ... | @@ -237,9 +237,7 @@ pub const blkcnt_t = switch (native_os) { |
| 237 | 237 | |
| 238 | 238 | pub const fd_t = switch (native_os) { |
| 239 | 239 | .linux => linux.fd_t, |
| 240 | .windows => windows.HANDLE, | |
| 241 | .serenity => c_int, | |
| 242 | else => i32, | |
| 240 | else => c_int, | |
| 243 | 241 | }; |
| 244 | 242 | |
| 245 | 243 | pub const ARCH = switch (native_os) { |
| ... | ... | @@ -445,7 +443,6 @@ pub const E = switch (native_os) { |
| 445 | 443 | TIMEDOUT = 138, |
| 446 | 444 | TXTBSY = 139, |
| 447 | 445 | WOULDBLOCK = 140, |
| 448 | DQUOT = 10069, | |
| 449 | 446 | _, |
| 450 | 447 | }, |
| 451 | 448 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.E, |
| ... | ... | @@ -1827,7 +1824,6 @@ pub const PATH_MAX = switch (native_os) { |
| 1827 | 1824 | pub const POLL = switch (native_os) { |
| 1828 | 1825 | .linux => linux.POLL, |
| 1829 | 1826 | .emscripten => emscripten.POLL, |
| 1830 | .windows => ws2_32.POLL, | |
| 1831 | 1827 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { |
| 1832 | 1828 | pub const IN = 0x001; |
| 1833 | 1829 | pub const PRI = 0x002; |
| ... | ... | @@ -1965,7 +1961,7 @@ pub const PROT = switch (native_os) { |
| 1965 | 1961 | .linux => linux.PROT, |
| 1966 | 1962 | .emscripten => emscripten.PROT, |
| 1967 | 1963 | // https://github.com/SerenityOS/serenity/blob/6d59d4d3d9e76e39112842ec487840828f1c9bfe/Kernel/API/POSIX/sys/mman.h#L28-L31 |
| 1968 | .openbsd, .haiku, .dragonfly, .netbsd, .illumos, .freebsd, .windows, .serenity => packed struct(u32) { | |
| 1964 | .openbsd, .haiku, .dragonfly, .netbsd, .illumos, .freebsd, .serenity => packed struct(u32) { | |
| 1969 | 1965 | READ: bool = false, |
| 1970 | 1966 | WRITE: bool = false, |
| 1971 | 1967 | EXEC: bool = false, |
| ... | ... | @@ -3796,7 +3792,6 @@ pub const T = switch (native_os) { |
| 3796 | 3792 | else => void, |
| 3797 | 3793 | }; |
| 3798 | 3794 | pub const IOCPARM_MASK = switch (native_os) { |
| 3799 | .windows => ws2_32.IOCPARM_MASK, | |
| 3800 | 3795 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => 0x1fff, |
| 3801 | 3796 | else => void, |
| 3802 | 3797 | }; |
| ... | ... | @@ -4448,7 +4443,6 @@ pub const nfds_t = switch (native_os) { |
| 4448 | 4443 | .linux => linux.nfds_t, |
| 4449 | 4444 | .emscripten => emscripten.nfds_t, |
| 4450 | 4445 | .haiku, .illumos => usize, |
| 4451 | .windows => c_ulong, | |
| 4452 | 4446 | .openbsd, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u32, |
| 4453 | 4447 | // https://github.com/SerenityOS/serenity/blob/265764ff2fec038855193296588a887fc322d76a/Kernel/API/POSIX/poll.h#L32 |
| 4454 | 4448 | .serenity => c_uint, |
| ... | ... | @@ -4461,15 +4455,13 @@ pub const perf_event_attr = switch (native_os) { |
| 4461 | 4455 | pub const pid_t = switch (native_os) { |
| 4462 | 4456 | .linux => linux.pid_t, |
| 4463 | 4457 | .emscripten => emscripten.pid_t, |
| 4464 | .windows => windows.HANDLE, | |
| 4465 | 4458 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L31-L32 |
| 4466 | .serenity => c_int, | |
| 4467 | else => i32, | |
| 4459 | else => c_int, | |
| 4468 | 4460 | }; |
| 4469 | 4461 | pub const pollfd = switch (native_os) { |
| 4470 | 4462 | .linux => linux.pollfd, |
| 4471 | 4463 | .emscripten => emscripten.pollfd, |
| 4472 | .windows => ws2_32.pollfd, | |
| 4464 | .windows => void, | |
| 4473 | 4465 | // https://github.com/SerenityOS/serenity/blob/265764ff2fec038855193296588a887fc322d76a/Kernel/API/POSIX/poll.h#L26-L30 |
| 4474 | 4466 | .serenity => extern struct { |
| 4475 | 4467 | fd: fd_t, |
| ... | ... | @@ -4942,7 +4934,6 @@ pub const addrinfo = if (builtin.abi.isAndroid()) extern struct { |
| 4942 | 4934 | next: ?*addrinfo, |
| 4943 | 4935 | } else switch (native_os) { |
| 4944 | 4936 | .linux, .emscripten => linux.addrinfo, |
| 4945 | .windows => ws2_32.addrinfo, | |
| 4946 | 4937 | .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { |
| 4947 | 4938 | flags: AI, |
| 4948 | 4939 | family: i32, |
| ... | ... | @@ -5008,7 +4999,6 @@ pub const addrinfo = if (builtin.abi.isAndroid()) extern struct { |
| 5008 | 4999 | }; |
| 5009 | 5000 | pub const sockaddr = switch (native_os) { |
| 5010 | 5001 | .linux, .emscripten => linux.sockaddr, |
| 5011 | .windows => ws2_32.sockaddr, | |
| 5012 | 5002 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { |
| 5013 | 5003 | len: u8, |
| 5014 | 5004 | family: sa_family_t, |
| ... | ... | @@ -5343,14 +5333,13 @@ pub const sockaddr = switch (native_os) { |
| 5343 | 5333 | }; |
| 5344 | 5334 | pub const socklen_t = switch (native_os) { |
| 5345 | 5335 | .linux, .emscripten => linux.socklen_t, |
| 5346 | .windows => ws2_32.socklen_t, | |
| 5336 | .windows => void, | |
| 5347 | 5337 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L57 |
| 5348 | 5338 | else => u32, |
| 5349 | 5339 | }; |
| 5350 | 5340 | pub const in_port_t = u16; |
| 5351 | 5341 | pub const sa_family_t = switch (native_os) { |
| 5352 | 5342 | .linux, .emscripten => linux.sa_family_t, |
| 5353 | .windows => ws2_32.ADDRESS_FAMILY, | |
| 5354 | 5343 | .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u8, |
| 5355 | 5344 | // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L66 |
| 5356 | 5345 | .illumos, .serenity => u16, |
| ... | ... | @@ -5403,7 +5392,6 @@ pub const AF = if (builtin.abi.isAndroid()) struct { |
| 5403 | 5392 | pub const MAX = 43; |
| 5404 | 5393 | } else switch (native_os) { |
| 5405 | 5394 | .linux, .emscripten => linux.AF, |
| 5406 | .windows => ws2_32.AF, | |
| 5407 | 5395 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { |
| 5408 | 5396 | pub const UNSPEC = 0; |
| 5409 | 5397 | pub const LOCAL = 1; |
| ... | ... | @@ -5952,7 +5940,6 @@ pub const DT = switch (native_os) { |
| 5952 | 5940 | pub const MSG = switch (native_os) { |
| 5953 | 5941 | .linux => linux.MSG, |
| 5954 | 5942 | .emscripten => emscripten.MSG, |
| 5955 | .windows => ws2_32.MSG, | |
| 5956 | 5943 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.MSG, |
| 5957 | 5944 | .haiku => struct { |
| 5958 | 5945 | pub const OOB = 0x0001; |
| ... | ... | @@ -6069,7 +6056,6 @@ pub const MSG = switch (native_os) { |
| 6069 | 6056 | pub const SOCK = switch (native_os) { |
| 6070 | 6057 | .linux => linux.SOCK, |
| 6071 | 6058 | .emscripten => emscripten.SOCK, |
| 6072 | .windows => ws2_32.SOCK, | |
| 6073 | 6059 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { |
| 6074 | 6060 | pub const STREAM = 1; |
| 6075 | 6061 | pub const DGRAM = 2; |
| ... | ... | @@ -6178,7 +6164,6 @@ pub const TCP = switch (native_os) { |
| 6178 | 6164 | .openbsd => openbsd.TCP, |
| 6179 | 6165 | .dragonfly => dragonfly.TCP, |
| 6180 | 6166 | .emscripten => emscripten.TCP, |
| 6181 | .windows => ws2_32.TCP, | |
| 6182 | 6167 | .illumos => illumos.TCP, |
| 6183 | 6168 | .haiku => haiku.TCP, |
| 6184 | 6169 | // https://github.com/SerenityOS/serenity/blob/61ac554a3403838f79ca746bd1c65ded6f97d124/Kernel/API/POSIX/netinet/tcp.h#L13-L14 |
| ... | ... | @@ -6190,7 +6175,6 @@ pub const TCP = switch (native_os) { |
| 6190 | 6175 | }; |
| 6191 | 6176 | pub const IPPROTO = switch (native_os) { |
| 6192 | 6177 | .linux, .emscripten => linux.IPPROTO, |
| 6193 | .windows => ws2_32.IPPROTO, | |
| 6194 | 6178 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { |
| 6195 | 6179 | pub const ICMP = 1; |
| 6196 | 6180 | pub const ICMPV6 = 58; |
| ... | ... | @@ -6826,7 +6810,6 @@ pub const IPTOS = switch (native_os) { |
| 6826 | 6810 | pub const SOL = switch (native_os) { |
| 6827 | 6811 | .linux => linux.SOL, |
| 6828 | 6812 | .emscripten => emscripten.SOL, |
| 6829 | .windows => ws2_32.SOL, | |
| 6830 | 6813 | .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { |
| 6831 | 6814 | pub const SOCKET = 0xffff; |
| 6832 | 6815 | }, |
| ... | ... | @@ -6845,7 +6828,6 @@ pub const SOL = switch (native_os) { |
| 6845 | 6828 | pub const SO = switch (native_os) { |
| 6846 | 6829 | .linux => linux.SO, |
| 6847 | 6830 | .emscripten => emscripten.SO, |
| 6848 | .windows => ws2_32.SO, | |
| 6849 | 6831 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { |
| 6850 | 6832 | pub const DEBUG = 0x0001; |
| 6851 | 6833 | pub const ACCEPTCONN = 0x0002; |
| ... | ... | @@ -7084,7 +7066,6 @@ pub const SO = switch (native_os) { |
| 7084 | 7066 | }; |
| 7085 | 7067 | pub const SOMAXCONN = switch (native_os) { |
| 7086 | 7068 | .linux => linux.SOMAXCONN, |
| 7087 | .windows => ws2_32.SOMAXCONN, | |
| 7088 | 7069 | // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L128 |
| 7089 | 7070 | .illumos, .serenity => 128, |
| 7090 | 7071 | // https://github.com/freebsd/freebsd-src/blob/9ab31f821ad1c6bad474510447387c50bef2c24c/sys/sys/socket.h#L434 |
| ... | ... | @@ -7153,7 +7134,6 @@ pub const SCM = switch (native_os) { |
| 7153 | 7134 | pub const IFNAMESIZE = switch (native_os) { |
| 7154 | 7135 | .linux => linux.IFNAMESIZE, |
| 7155 | 7136 | .emscripten => emscripten.IFNAMESIZE, |
| 7156 | .windows => 30, | |
| 7157 | 7137 | // https://github.com/SerenityOS/serenity/blob/9882848e0bf783dfc8e8a6d887a848d70d9c58f4/Kernel/API/POSIX/net/if.h#L50 |
| 7158 | 7138 | .openbsd, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .serenity => 16, |
| 7159 | 7139 | .illumos => 32, |
| ... | ... | @@ -7532,7 +7512,6 @@ pub const AI = if (builtin.abi.isAndroid()) packed struct(u32) { |
| 7532 | 7512 | NUMERICSERV: bool = false, |
| 7533 | 7513 | _: u19 = 0, |
| 7534 | 7514 | }, |
| 7535 | .windows => ws2_32.AI, | |
| 7536 | 7515 | // https://github.com/SerenityOS/serenity/blob/d510d2aeb2facbd8f6c383d70fd1b033e1fee5dd/Userland/Libraries/LibC/netdb.h#L90-L96 |
| 7537 | 7516 | .serenity => packed struct(c_int) { |
| 7538 | 7517 | PASSIVE: bool = false, |
| ... | ... | @@ -8379,10 +8358,6 @@ pub const port_event = switch (native_os) { |
| 8379 | 8358 | |
| 8380 | 8359 | pub const AT = switch (native_os) { |
| 8381 | 8360 | .linux => linux.AT, |
| 8382 | .windows => struct { | |
| 8383 | /// Remove directory instead of unlinking file | |
| 8384 | pub const REMOVEDIR = 0x200; | |
| 8385 | }, | |
| 8386 | 8361 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { |
| 8387 | 8362 | pub const FDCWD = -2; |
| 8388 | 8363 | /// Use effective ids in access check |
| ... | ... | @@ -10436,6 +10411,7 @@ pub extern "c" fn alarm(seconds: c_uint) c_uint; |
| 10436 | 10411 | |
| 10437 | 10412 | pub const close = switch (native_os) { |
| 10438 | 10413 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.@"close$NOCANCEL", |
| 10414 | .windows => private._close, | |
| 10439 | 10415 | else => private.close, |
| 10440 | 10416 | }; |
| 10441 | 10417 | |
| ... | ... | @@ -10922,19 +10898,31 @@ pub extern "c" fn abort() noreturn; |
| 10922 | 10898 | pub extern "c" fn exit(code: c_int) noreturn; |
| 10923 | 10899 | pub extern "c" fn _Exit(code: c_int) noreturn; |
| 10924 | 10900 | pub extern "c" fn _exit(code: c_int) noreturn; |
| 10925 | pub extern "c" fn isatty(fd: fd_t) c_int; | |
| 10926 | pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: whence_t) off_t; | |
| 10901 | pub const isatty = switch (native_os) { | |
| 10902 | .windows => private._isatty, | |
| 10903 | else => private.isatty, | |
| 10904 | }; | |
| 10905 | pub const lseek = switch (native_os) { | |
| 10906 | .windows => private._lseeki64, | |
| 10907 | else => private.lseek, | |
| 10908 | }; | |
| 10927 | 10909 | pub extern "c" fn open(path: [*:0]const u8, oflag: O, ...) c_int; |
| 10928 | 10910 | pub extern "c" fn openat(fd: c_int, path: [*:0]const u8, oflag: O, ...) c_int; |
| 10929 | 10911 | pub extern "c" fn ftruncate(fd: c_int, length: off_t) c_int; |
| 10930 | 10912 | pub extern "c" fn raise(sig: SIG) c_int; |
| 10931 | pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize; | |
| 10913 | pub const read = switch (native_os) { | |
| 10914 | .windows => private._read, | |
| 10915 | else => private.read, | |
| 10916 | }; | |
| 10932 | 10917 | pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize; |
| 10933 | 10918 | pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: off_t) isize; |
| 10934 | 10919 | pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: off_t) isize; |
| 10935 | 10920 | pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize; |
| 10936 | 10921 | pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: off_t) isize; |
| 10937 | pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize; | |
| 10922 | pub const write = switch (native_os) { | |
| 10923 | .windows => private._write, | |
| 10924 | else => private.write, | |
| 10925 | }; | |
| 10938 | 10926 | pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: off_t) isize; |
| 10939 | 10927 | pub extern "c" fn mmap(addr: ?*align(page_size) anyopaque, len: usize, prot: PROT, flags: MAP, fd: fd_t, offset: off_t) *anyopaque; |
| 10940 | 10928 | pub extern "c" fn munmap(addr: *align(page_size) const anyopaque, len: usize) c_int; |
| ... | ... | @@ -10977,7 +10965,10 @@ pub const fork = switch (native_os) { |
| 10977 | 10965 | pub extern "c" fn access(path: [*:0]const u8, mode: c_uint) c_int; |
| 10978 | 10966 | pub extern "c" fn faccessat(dirfd: fd_t, path: [*:0]const u8, mode: c_uint, flags: c_uint) c_int; |
| 10979 | 10967 | pub extern "c" fn pipe(fds: *[2]fd_t) c_int; |
| 10980 | pub extern "c" fn mkdir(path: [*:0]const u8, mode: mode_t) c_int; | |
| 10968 | pub const mkdir = switch (native_os) { | |
| 10969 | .windows => private._mkdir, | |
| 10970 | else => private.mkdir, | |
| 10971 | }; | |
| 10981 | 10972 | pub extern "c" fn mkdirat(dirfd: fd_t, path: [*:0]const u8, mode: mode_t) c_int; |
| 10982 | 10973 | pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int; |
| 10983 | 10974 | pub extern "c" fn symlinkat(oldpath: [*:0]const u8, newdirfd: fd_t, newpath: [*:0]const u8) c_int; |
| ... | ... | @@ -10991,17 +10982,29 @@ pub const fexecve = switch (native_os) { |
| 10991 | 10982 | }; |
| 10992 | 10983 | pub extern "c" fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) c_int; |
| 10993 | 10984 | pub extern "c" fn execveat(dirfd: fd_t, path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8, flags: EXECVEAT) c_int; |
| 10994 | pub extern "c" fn dup(fd: fd_t) c_int; | |
| 10995 | pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int; | |
| 10985 | pub const dup = switch (native_os) { | |
| 10986 | .windows => private._dup, | |
| 10987 | else => private.dup, | |
| 10988 | }; | |
| 10989 | pub const dup2 = switch (native_os) { | |
| 10990 | .windows => private._dup2, | |
| 10991 | else => private.dup2, | |
| 10992 | }; | |
| 10996 | 10993 | pub extern "c" fn dup3(old: c_int, new: c_int, flags: c_uint) c_int; |
| 10997 | 10994 | pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize; |
| 10998 | 10995 | pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize; |
| 10999 | pub extern "c" fn chmod(path: [*:0]const u8, mode: mode_t) c_int; | |
| 10996 | pub const chmod = switch (native_os) { | |
| 10997 | .windows => private._chmod, | |
| 10998 | else => private.chmod, | |
| 10999 | }; | |
| 11000 | 11000 | pub extern "c" fn fchmod(fd: fd_t, mode: mode_t) c_int; |
| 11001 | 11001 | pub extern "c" fn fchmodat(fd: fd_t, path: [*:0]const u8, mode: mode_t, flags: c_uint) c_int; |
| 11002 | 11002 | pub extern "c" fn fchown(fd: fd_t, owner: uid_t, group: gid_t) c_int; |
| 11003 | 11003 | pub extern "c" fn fchownat(fd: fd_t, path: [*:0]const u8, owner: uid_t, group: gid_t, flags: c_uint) c_int; |
| 11004 | pub extern "c" fn umask(mode: mode_t) mode_t; | |
| 11004 | pub const umask = switch (native_os) { | |
| 11005 | .windows => private._umask, | |
| 11006 | else => private.umask, | |
| 11007 | }; | |
| 11005 | 11008 | |
| 11006 | 11009 | pub extern "c" fn rmdir(path: [*:0]const u8) c_int; |
| 11007 | 11010 | pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8; |
| ... | ... | @@ -11044,7 +11047,7 @@ pub extern "c" fn recv( |
| 11044 | 11047 | arg1: ?*anyopaque, |
| 11045 | 11048 | arg2: usize, |
| 11046 | 11049 | arg3: c_int, |
| 11047 | ) if (native_os == .windows) c_int else isize; | |
| 11050 | ) isize; | |
| 11048 | 11051 | pub extern "c" fn recvfrom( |
| 11049 | 11052 | sockfd: fd_t, |
| 11050 | 11053 | noalias buf: *anyopaque, |
| ... | ... | @@ -11052,7 +11055,7 @@ pub extern "c" fn recvfrom( |
| 11052 | 11055 | flags: u32, |
| 11053 | 11056 | noalias src_addr: ?*sockaddr, |
| 11054 | 11057 | noalias addrlen: ?*socklen_t, |
| 11055 | ) if (native_os == .windows) c_int else isize; | |
| 11058 | ) isize; | |
| 11056 | 11059 | |
| 11057 | 11060 | pub const recvmsg = switch (native_os) { |
| 11058 | 11061 | .windows => {}, |
| ... | ... | @@ -11319,7 +11322,10 @@ pub extern "c" fn setlogmask(maskpri: c_int) c_int; |
| 11319 | 11322 | |
| 11320 | 11323 | pub extern "c" fn if_nametoindex([*:0]const u8) c_int; |
| 11321 | 11324 | |
| 11322 | pub extern "c" fn getpid() pid_t; | |
| 11325 | pub const getpid = switch (native_os) { | |
| 11326 | .windows => private._getpid, | |
| 11327 | else => private.getpid, | |
| 11328 | }; | |
| 11323 | 11329 | pub extern "c" fn getppid() pid_t; |
| 11324 | 11330 | pub extern "c" fn setsid() pid_t; |
| 11325 | 11331 | |
| ... | ... | @@ -11882,11 +11888,14 @@ const private = struct { |
| 11882 | 11888 | extern "c" fn swab(noalias from: *const anyopaque, noalias to: *anyopaque, n: isize) void; |
| 11883 | 11889 | extern "c" fn _swab(noalias from: *const anyopaque, noalias to: *anyopaque, n: isize) void; |
| 11884 | 11890 | |
| 11891 | extern "c" fn chmod(path: [*:0]const u8, mode: mode_t) c_int; | |
| 11885 | 11892 | extern "c" fn clock_getres(clk_id: clockid_t, tp: *timespec) c_int; |
| 11886 | 11893 | extern "c" fn clock_gettime(clk_id: clockid_t, tp: *timespec) c_int; |
| 11887 | 11894 | extern "c" fn clock_nanosleep(clockid: clockid_t, flags: TIMER, t: *const timespec, remain: ?*timespec) c_int; |
| 11888 | 11895 | extern "c" fn close(fd: fd_t) c_int; |
| 11889 | 11896 | extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: c_uint) isize; |
| 11897 | extern "c" fn dup(fd: fd_t) c_int; | |
| 11898 | extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int; | |
| 11890 | 11899 | extern "c" fn fexecve(fd: fd_t, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) c_int; |
| 11891 | 11900 | extern "c" fn flock(fd: fd_t, operation: c_int) c_int; |
| 11892 | 11901 | extern "c" fn fork() c_int; |
| ... | ... | @@ -11898,13 +11907,18 @@ const private = struct { |
| 11898 | 11907 | .freebsd => isize, |
| 11899 | 11908 | .illumos => usize, |
| 11900 | 11909 | }; |
| 11910 | extern "c" fn getpid() pid_t; | |
| 11901 | 11911 | extern "c" fn getrusage(who: c_int, usage: *rusage) c_int; |
| 11902 | 11912 | extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; |
| 11903 | 11913 | extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int; |
| 11914 | extern "c" fn isatty(fd: fd_t) c_int; | |
| 11915 | extern "c" fn lseek(fd: fd_t, offset: off_t, whence: whence_t) off_t; | |
| 11916 | extern "c" fn mkdir(path: [*:0]const u8, mode: mode_t) c_int; | |
| 11904 | 11917 | extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int; |
| 11905 | 11918 | extern "c" fn mremap(addr: ?*align(page_size) const anyopaque, old_len: usize, new_len: usize, flags: MREMAP, ...) *anyopaque; |
| 11906 | 11919 | extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; |
| 11907 | 11920 | extern "c" fn pipe2(fds: *[2]fd_t, flags: O) c_int; |
| 11921 | extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize; | |
| 11908 | 11922 | extern "c" fn readdir(dir: *DIR) ?*dirent; |
| 11909 | 11923 | extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8; |
| 11910 | 11924 | extern "c" fn recvmsg(sockfd: fd_t, msg: *msghdr, flags: u32) isize; |
| ... | ... | @@ -11932,7 +11946,21 @@ const private = struct { |
| 11932 | 11946 | extern "c" fn sigaltstack(ss: ?*const stack_t, old_ss: ?*stack_t) c_int; |
| 11933 | 11947 | extern "c" fn sysconf(sc: c_int) c_long; |
| 11934 | 11948 | extern "c" fn shm_open(name: [*:0]const u8, flag: c_int, mode: mode_t) c_int; |
| 11949 | extern "c" fn umask(mode: mode_t) mode_t; | |
| 11935 | 11950 | extern "c" fn wait4(pid: pid_t, status: ?*c_int, options: c_int, ru: ?*rusage) pid_t; |
| 11951 | extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize; | |
| 11952 | ||
| 11953 | extern "c" fn _chmod(filename: [*:0]const u8, pmode: c_int) c_int; | |
| 11954 | extern "c" fn _close(fd: fd_t) c_int; | |
| 11955 | extern "c" fn _dup(fd: fd_t) c_int; | |
| 11956 | extern "c" fn _dup2(old_fd: fd_t, new_fd: fd_t) c_int; | |
| 11957 | extern "c" fn _getpid() pid_t; | |
| 11958 | extern "c" fn _isatty(fd: fd_t) c_int; | |
| 11959 | extern "c" fn _lseeki64(fd: fd_t, offset: off_t, whence: whence_t) off_t; | |
| 11960 | extern "c" fn _mkdir(dirname: [*:0]const u8) c_int; | |
| 11961 | extern "c" fn _read(fd: fd_t, buf: [*]u8, nbyte: c_uint) c_int; | |
| 11962 | extern "c" fn _umask(pmode: c_int) c_int; | |
| 11963 | extern "c" fn _write(fd: fd_t, buf: [*]const u8, nbyte: c_uint) c_int; | |
| 11936 | 11964 | |
| 11937 | 11965 | extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8) c_int; |
| 11938 | 11966 |
lib/std/crypto/Certificate/Bundle.zig+1-1| ... | ... | @@ -144,7 +144,7 @@ fn rescanWithPath(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp, cert_f |
| 144 | 144 | cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | const RescanWindowsError = Allocator.Error || ParseCertError || std.posix.UnexpectedError || error{FileNotFound}; | |
| 147 | const RescanWindowsError = Allocator.Error || ParseCertError || std.Io.UnexpectedError || error{FileNotFound}; | |
| 148 | 148 | |
| 149 | 149 | fn rescanWindows(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanWindowsError!void { |
| 150 | 150 | cb.bytes.clearRetainingCapacity(); |
lib/std/os/windows.zig+5-1| ... | ... | @@ -13,7 +13,7 @@ const mem = std.mem; |
| 13 | 13 | const assert = std.debug.assert; |
| 14 | 14 | const math = std.math; |
| 15 | 15 | const maxInt = std.math.maxInt; |
| 16 | const UnexpectedError = std.posix.UnexpectedError; | |
| 16 | const UnexpectedError = std.Io.UnexpectedError; | |
| 17 | 17 | |
| 18 | 18 | pub const kernel32 = @import("windows/kernel32.zig"); |
| 19 | 19 | pub const ntdll = @import("windows/ntdll.zig"); |
| ... | ... | @@ -1492,6 +1492,10 @@ pub const TDI = struct { |
| 1492 | 1492 | }; |
| 1493 | 1493 | }; |
| 1494 | 1494 | |
| 1495 | pub const IF = struct { | |
| 1496 | pub const MAX_STRING_SIZE = 256; | |
| 1497 | }; | |
| 1498 | ||
| 1495 | 1499 | pub const NET = struct { |
| 1496 | 1500 | pub const LUID = packed struct(ULONG64) { Reserved: u24 = 0, Index: u24, IfType: u16 }; |
| 1497 | 1501 | pub const IFINDEX = enum(ULONG) { _ }; |
lib/std/posix.zig+33-57| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | //! `std.process`. |
| 6 | 6 | //! |
| 7 | 7 | //! These APIs are generally lowered to libc function calls if and only if libc |
| 8 | //! is linked. Most operating systems other than Windows, Linux, and WASI | |
| 8 | //! is linked. Most operating systems other than Linux and WASI | |
| 9 | 9 | //! require always linking libc because they use it as the stable syscall ABI. |
| 10 | 10 | const builtin = @import("builtin"); |
| 11 | 11 | const native_os = builtin.os.tag; |
| ... | ... | @@ -19,21 +19,19 @@ const assert = std.debug.assert; |
| 19 | 19 | const page_size_min = std.heap.page_size_min; |
| 20 | 20 | |
| 21 | 21 | test { |
| 22 | _ = @import("posix/test.zig"); | |
| 22 | if (native_os != .windows) _ = @import("posix/test.zig"); | |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /// Whether to use libc for the POSIX API layer. |
| 26 | const use_libc = builtin.link_libc or switch (native_os) { | |
| 27 | .windows => true, | |
| 28 | else => false, | |
| 29 | }; | |
| 26 | const use_libc = builtin.link_libc; | |
| 30 | 27 | |
| 31 | 28 | const linux = std.os.linux; |
| 32 | const windows = std.os.windows; | |
| 33 | 29 | const wasi = std.os.wasi; |
| 34 | 30 | |
| 35 | 31 | /// A libc-compatible API layer. |
| 36 | pub const system = if (use_libc) | |
| 32 | pub const system = if (native_os == .windows) | |
| 33 | @compileError("Windows does not support POSIX") | |
| 34 | else if (use_libc) | |
| 37 | 35 | std.c |
| 38 | 36 | else switch (native_os) { |
| 39 | 37 | .linux => linux, |
| ... | ... | @@ -134,14 +132,11 @@ pub const STDIN_FILENO = system.STDIN_FILENO; |
| 134 | 132 | pub const STDOUT_FILENO = system.STDOUT_FILENO; |
| 135 | 133 | pub const SYS = system.SYS; |
| 136 | 134 | pub const Sigaction = system.Sigaction; |
| 137 | /// Windows has no concept of `stat`. | |
| 138 | /// | |
| 139 | 135 | /// On Linux, the `stat` bits/wrappers are removed due to having to maintain |
| 140 | 136 | /// the different varying stat structs per target and libc, leading to runtime |
| 141 | 137 | /// errors. Users targeting Linux should add a comptime check and use statx, |
| 142 | 138 | /// similar to how `Io.File.stat` does. |
| 143 | 139 | pub const Stat = switch (native_os) { |
| 144 | .windows => void, | |
| 145 | 140 | .linux => void, |
| 146 | 141 | else => system.Stat, |
| 147 | 142 | }; |
| ... | ... | @@ -406,7 +401,6 @@ pub const ReadError = std.Io.File.Reader.Error; |
| 406 | 401 | /// The corresponding POSIX limit is `maxInt(isize)`. |
| 407 | 402 | pub fn read(fd: fd_t, buf: []u8) ReadError!usize { |
| 408 | 403 | if (buf.len == 0) return 0; |
| 409 | if (native_os == .windows) @compileError("unsupported OS"); | |
| 410 | 404 | if (native_os == .wasi) @compileError("unsupported OS"); |
| 411 | 405 | |
| 412 | 406 | // Prevents EINVAL. |
| ... | ... | @@ -441,14 +435,11 @@ pub const OpenError = std.Io.File.OpenError || error{WouldBlock}; |
| 441 | 435 | |
| 442 | 436 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 443 | 437 | /// `file_path` is relative to the open directory handle `dir_fd`. |
| 444 | /// On Windows, `file_path` should be encoded as [WTF-8](https://wtf-8.codeberg.page/). | |
| 445 | 438 | /// On WASI, `file_path` should be encoded as valid UTF-8. |
| 446 | 439 | /// On other platforms, `file_path` is an opaque sequence of bytes with no particular encoding. |
| 447 | 440 | /// See also `openatZ`. |
| 448 | 441 | pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenError!fd_t { |
| 449 | if (native_os == .windows) { | |
| 450 | @compileError("Windows does not support POSIX; use Windows-specific API or cross-platform std.fs API"); | |
| 451 | } else if (native_os == .wasi) { | |
| 442 | if (native_os == .wasi) { | |
| 452 | 443 | @compileError("use std.Io instead"); |
| 453 | 444 | } |
| 454 | 445 | const file_path_c = try toPosixPath(file_path); |
| ... | ... | @@ -457,14 +448,11 @@ pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenE |
| 457 | 448 | |
| 458 | 449 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 459 | 450 | /// `file_path` is relative to the open directory handle `dir_fd`. |
| 460 | /// On Windows, `file_path` should be encoded as [WTF-8](https://wtf-8.codeberg.page/). | |
| 461 | 451 | /// On WASI, `file_path` should be encoded as valid UTF-8. |
| 462 | 452 | /// On other platforms, `file_path` is an opaque sequence of bytes with no particular encoding. |
| 463 | 453 | /// See also `openat`. |
| 464 | 454 | pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: O, mode: mode_t) OpenError!fd_t { |
| 465 | if (native_os == .windows) { | |
| 466 | @compileError("Windows does not support POSIX; use Windows-specific API or cross-platform std.fs API"); | |
| 467 | } else if (native_os == .wasi) { | |
| 455 | if (native_os == .wasi) { | |
| 468 | 456 | return openat(dir_fd, mem.sliceTo(file_path, 0), flags, mode); |
| 469 | 457 | } |
| 470 | 458 | |
| ... | ... | @@ -526,21 +514,17 @@ pub const GetSockNameError = error{ |
| 526 | 514 | } || UnexpectedError; |
| 527 | 515 | |
| 528 | 516 | pub fn getpeername(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSockNameError!void { |
| 529 | if (native_os == .windows) { | |
| 530 | @compileError("use std.Io instead"); | |
| 531 | } else { | |
| 532 | const rc = system.getpeername(sock, addr, addrlen); | |
| 533 | switch (errno(rc)) { | |
| 534 | .SUCCESS => return, | |
| 535 | else => |err| return unexpectedErrno(err), | |
| 517 | const rc = system.getpeername(sock, addr, addrlen); | |
| 518 | switch (errno(rc)) { | |
| 519 | .SUCCESS => return, | |
| 520 | else => |err| return unexpectedErrno(err), | |
| 536 | 521 | |
| 537 | .BADF => unreachable, // always a race condition | |
| 538 | .FAULT => unreachable, | |
| 539 | .INVAL => unreachable, // invalid parameters | |
| 540 | .NOTSOCK => return error.FileDescriptorNotASocket, | |
| 541 | .NOBUFS => return error.SystemResources, | |
| 542 | .NOTCONN => return error.SocketUnconnected, | |
| 543 | } | |
| 522 | .BADF => unreachable, // always a race condition | |
| 523 | .FAULT => unreachable, | |
| 524 | .INVAL => unreachable, // invalid parameters | |
| 525 | .NOTSOCK => return error.FileDescriptorNotASocket, | |
| 526 | .NOBUFS => return error.SystemResources, | |
| 527 | .NOTCONN => return error.SocketUnconnected, | |
| 544 | 528 | } |
| 545 | 529 | } |
| 546 | 530 | |
| ... | ... | @@ -1008,9 +992,6 @@ pub const PollError = error{ |
| 1008 | 992 | } || UnexpectedError; |
| 1009 | 993 | |
| 1010 | 994 | pub fn poll(fds: []pollfd, timeout: i32) PollError!usize { |
| 1011 | if (native_os == .windows) { | |
| 1012 | @compileError("use std.Io instead"); | |
| 1013 | } | |
| 1014 | 995 | while (true) { |
| 1015 | 996 | const fds_count = cast(nfds_t, fds.len) orelse return error.SystemResources; |
| 1016 | 997 | const rc = system.poll(fds.ptr, fds_count, timeout); |
| ... | ... | @@ -1078,25 +1059,21 @@ pub const SetSockOptError = error{ |
| 1078 | 1059 | |
| 1079 | 1060 | /// Set a socket's options. |
| 1080 | 1061 | pub fn setsockopt(fd: socket_t, level: i32, optname: u32, opt: []const u8) SetSockOptError!void { |
| 1081 | if (native_os == .windows) { | |
| 1082 | @compileError("use std.Io instead"); | |
| 1083 | } else { | |
| 1084 | switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(opt.len)))) { | |
| 1085 | .SUCCESS => {}, | |
| 1086 | .BADF => unreachable, // always a race condition | |
| 1087 | .NOTSOCK => unreachable, // always a race condition | |
| 1088 | .INVAL => unreachable, | |
| 1089 | .FAULT => unreachable, | |
| 1090 | .DOM => return error.TimeoutTooBig, | |
| 1091 | .ISCONN => return error.AlreadyConnected, | |
| 1092 | .NOPROTOOPT => return error.InvalidProtocolOption, | |
| 1093 | .NOMEM => return error.SystemResources, | |
| 1094 | .NOBUFS => return error.SystemResources, | |
| 1095 | .PERM => return error.PermissionDenied, | |
| 1096 | .NODEV => return error.NoDevice, | |
| 1097 | .OPNOTSUPP => return error.OperationUnsupported, | |
| 1098 | else => |err| return unexpectedErrno(err), | |
| 1099 | } | |
| 1062 | switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(opt.len)))) { | |
| 1063 | .SUCCESS => {}, | |
| 1064 | .BADF => unreachable, // always a race condition | |
| 1065 | .NOTSOCK => unreachable, // always a race condition | |
| 1066 | .INVAL => unreachable, | |
| 1067 | .FAULT => unreachable, | |
| 1068 | .DOM => return error.TimeoutTooBig, | |
| 1069 | .ISCONN => return error.AlreadyConnected, | |
| 1070 | .NOPROTOOPT => return error.InvalidProtocolOption, | |
| 1071 | .NOMEM => return error.SystemResources, | |
| 1072 | .NOBUFS => return error.SystemResources, | |
| 1073 | .PERM => return error.PermissionDenied, | |
| 1074 | .NODEV => return error.NoDevice, | |
| 1075 | .OPNOTSUPP => return error.OperationUnsupported, | |
| 1076 | else => |err| return unexpectedErrno(err), | |
| 1100 | 1077 | } |
| 1101 | 1078 | } |
| 1102 | 1079 | |
| ... | ... | @@ -1527,7 +1504,6 @@ pub const PtraceError = error{ |
| 1527 | 1504 | |
| 1528 | 1505 | pub fn ptrace(request: u32, pid: pid_t, addr: usize, data: usize) PtraceError!void { |
| 1529 | 1506 | return switch (native_os) { |
| 1530 | .windows, | |
| 1531 | 1507 | .wasi, |
| 1532 | 1508 | .emscripten, |
| 1533 | 1509 | .haiku, |
lib/std/posix/test.zig+11-14| ... | ... | @@ -36,19 +36,19 @@ test "check WASI CWD" { |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | test "getuid" { |
| 39 | if (native_os == .windows or native_os == .wasi) return error.SkipZigTest; | |
| 39 | if (native_os == .wasi) return error.SkipZigTest; | |
| 40 | 40 | _ = posix.system.getuid(); |
| 41 | 41 | _ = posix.system.geteuid(); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | test "getgid" { |
| 45 | if (native_os == .windows or native_os == .wasi) return error.SkipZigTest; | |
| 45 | if (native_os == .wasi) return error.SkipZigTest; | |
| 46 | 46 | _ = posix.system.getgid(); |
| 47 | 47 | _ = posix.system.getegid(); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | test "sigaltstack" { |
| 51 | if (native_os == .windows or native_os == .wasi) return error.SkipZigTest; | |
| 51 | if (native_os == .wasi) return error.SkipZigTest; | |
| 52 | 52 | |
| 53 | 53 | var st: posix.stack_t = undefined; |
| 54 | 54 | try posix.sigaltstack(null, &st); |
| ... | ... | @@ -102,7 +102,7 @@ test "dl_iterate_phdr" { |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | test "gethostname" { |
| 105 | if (native_os == .windows or native_os == .wasi) | |
| 105 | if (native_os == .wasi) | |
| 106 | 106 | return error.SkipZigTest; |
| 107 | 107 | |
| 108 | 108 | var buf: [posix.HOST_NAME_MAX]u8 = undefined; |
| ... | ... | @@ -111,7 +111,7 @@ test "gethostname" { |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | test "pipe" { |
| 114 | if (native_os == .windows or native_os == .wasi) | |
| 114 | if (native_os == .wasi) | |
| 115 | 115 | return error.SkipZigTest; |
| 116 | 116 | |
| 117 | 117 | const io = testing.io; |
| ... | ... | @@ -155,7 +155,7 @@ test "memfd_create" { |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | test "mmap" { |
| 158 | if (native_os == .windows or native_os == .wasi) | |
| 158 | if (native_os == .wasi) | |
| 159 | 159 | return error.SkipZigTest; |
| 160 | 160 | |
| 161 | 161 | const io = testing.io; |
| ... | ... | @@ -252,7 +252,7 @@ test "mmap" { |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | test "fcntl" { |
| 255 | if (native_os == .windows or native_os == .wasi) | |
| 255 | if (native_os == .wasi) | |
| 256 | 256 | return error.SkipZigTest; |
| 257 | 257 | |
| 258 | 258 | const io = testing.io; |
| ... | ... | @@ -351,7 +351,7 @@ test "getrlimit and setrlimit" { |
| 351 | 351 | |
| 352 | 352 | test "sigrtmin/max" { |
| 353 | 353 | if (native_os.isDarwin() or switch (native_os) { |
| 354 | .wasi, .windows, .openbsd, .dragonfly => true, | |
| 354 | .wasi, .openbsd, .dragonfly => true, | |
| 355 | 355 | else => false, |
| 356 | 356 | }) return error.SkipZigTest; |
| 357 | 357 | |
| ... | ... | @@ -361,7 +361,7 @@ test "sigrtmin/max" { |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | test "sigset empty/full" { |
| 364 | if (native_os == .wasi or native_os == .windows) | |
| 364 | if (native_os == .wasi) | |
| 365 | 365 | return error.SkipZigTest; |
| 366 | 366 | |
| 367 | 367 | var set: posix.sigset_t = posix.sigemptyset(); |
| ... | ... | @@ -389,7 +389,7 @@ fn reserved_signo(i: usize) bool { |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | test "sigset add/del" { |
| 392 | if (native_os == .wasi or native_os == .windows) | |
| 392 | if (native_os == .wasi) | |
| 393 | 393 | return error.SkipZigTest; |
| 394 | 394 | |
| 395 | 395 | var sigset: posix.sigset_t = posix.sigemptyset(); |
| ... | ... | @@ -426,21 +426,18 @@ test "sigset add/del" { |
| 426 | 426 | |
| 427 | 427 | test "getpid" { |
| 428 | 428 | if (native_os == .wasi) return error.SkipZigTest; |
| 429 | if (native_os == .windows) return error.SkipZigTest; | |
| 430 | 429 | |
| 431 | 430 | try expect(posix.system.getpid() != 0); |
| 432 | 431 | } |
| 433 | 432 | |
| 434 | 433 | test "getppid" { |
| 435 | 434 | if (native_os == .wasi) return error.SkipZigTest; |
| 436 | if (native_os == .windows) return error.SkipZigTest; | |
| 437 | 435 | if (native_os == .plan9 and !builtin.link_libc) return error.SkipZigTest; |
| 438 | 436 | |
| 439 | 437 | try expect(posix.getppid() >= 0); |
| 440 | 438 | } |
| 441 | 439 | |
| 442 | 440 | test "rename smoke test" { |
| 443 | if (native_os == .windows) return error.SkipZigTest; | |
| 444 | 441 | if (!fstest.isRealPathSupported()) return error.SkipZigTest; |
| 445 | 442 | |
| 446 | 443 | const io = testing.io; |
| ... | ... | @@ -452,7 +449,7 @@ test "rename smoke test" { |
| 452 | 449 | const base_path = try tmp.dir.realPathFileAlloc(io, ".", gpa); |
| 453 | 450 | defer gpa.free(base_path); |
| 454 | 451 | |
| 455 | const mode: posix.mode_t = if (native_os == .windows) 0 else 0o666; | |
| 452 | const mode: posix.mode_t = 0o666; | |
| 456 | 453 | |
| 457 | 454 | { |
| 458 | 455 | // Create some file using `open`. |
lib/std/process.zig+14-7| ... | ... | @@ -415,12 +415,12 @@ pub const SpawnOptions = struct { |
| 415 | 415 | /// On Linux and Darwin, this obtains rusage statistics from wait4(). |
| 416 | 416 | request_resource_usage_statistics: bool = false, |
| 417 | 417 | |
| 418 | /// Set to change the user id when spawning the child process. | |
| 419 | uid: ?posix.uid_t = null, | |
| 420 | /// Set to change the group id when spawning the child process. | |
| 421 | gid: ?posix.gid_t = null, | |
| 422 | /// Set to change the process group id when spawning the child process. | |
| 423 | pgid: ?posix.pid_t = null, | |
| 418 | /// Set to change the user id when spawning the child process. Unsupported on Windows. | |
| 419 | uid: ?File.Uid = null, | |
| 420 | /// Set to change the group id when spawning the child process. Unsupported on Windows. | |
| 421 | gid: ?File.Gid = null, | |
| 422 | /// Set to change the process group id when spawning the child process. Unsupported on Windows. | |
| 423 | pgid: ?Child.Id = null, | |
| 424 | 424 | |
| 425 | 425 | /// Start child process in suspended state. |
| 426 | 426 | /// For Posix systems it's started as if SIGSTOP was sent. |
| ... | ... | @@ -656,7 +656,7 @@ pub fn cleanExit(io: Io) void { |
| 656 | 656 | /// On some systems, this raises the limit before seeing ProcessFdQuotaExceeded |
| 657 | 657 | /// errors. On other systems, this does nothing. |
| 658 | 658 | pub fn raiseFileDescriptorLimit() void { |
| 659 | const have_rlimit = posix.rlimit_resource != void; | |
| 659 | const have_rlimit = native_os != .windows and posix.rlimit_resource != void; | |
| 660 | 660 | if (!have_rlimit) return; |
| 661 | 661 | |
| 662 | 662 | var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried. |
| ... | ... | @@ -964,6 +964,7 @@ pub const LockMemoryOptions = struct { |
| 964 | 964 | pub fn lockMemory(memory: []align(std.heap.page_size_min) const u8, options: LockMemoryOptions) LockMemoryError!void { |
| 965 | 965 | if (native_os == .windows) { |
| 966 | 966 | // TODO call VirtualLock |
| 967 | return; | |
| 967 | 968 | } |
| 968 | 969 | if (!options.on_fault and @TypeOf(posix.system.mlock) != void) { |
| 969 | 970 | switch (posix.errno(posix.system.mlock(memory.ptr, memory.len))) { |
| ... | ... | @@ -1002,6 +1003,10 @@ pub const UnlockMemoryError = error{ |
| 1002 | 1003 | /// See also: |
| 1003 | 1004 | /// * `lockMemory` |
| 1004 | 1005 | pub fn unlockMemory(memory: []align(std.heap.page_size_min) const u8) UnlockMemoryError!void { |
| 1006 | if (native_os == .windows) { | |
| 1007 | // TODO call VirtualUnlock | |
| 1008 | return; | |
| 1009 | } | |
| 1005 | 1010 | if (@TypeOf(posix.system.munlock) == void) return; |
| 1006 | 1011 | switch (posix.errno(posix.system.munlock(memory.ptr, memory.len))) { |
| 1007 | 1012 | .SUCCESS => return, |
| ... | ... | @@ -1021,6 +1026,7 @@ pub const LockMemoryAllOptions = struct { |
| 1021 | 1026 | }; |
| 1022 | 1027 | |
| 1023 | 1028 | pub fn lockMemoryAll(options: LockMemoryAllOptions) LockMemoryError!void { |
| 1029 | if (native_os == .windows) return; | |
| 1024 | 1030 | if (@TypeOf(posix.system.mlockall) == void) return error.UnsupportedOperation; |
| 1025 | 1031 | var flags: posix.MCL = .{ |
| 1026 | 1032 | .CURRENT = options.current, |
| ... | ... | @@ -1045,6 +1051,7 @@ pub fn lockMemoryAll(options: LockMemoryAllOptions) LockMemoryError!void { |
| 1045 | 1051 | } |
| 1046 | 1052 | |
| 1047 | 1053 | pub fn unlockMemoryAll() UnlockMemoryError!void { |
| 1054 | if (native_os == .windows) return; | |
| 1048 | 1055 | if (@TypeOf(posix.system.munlockall) == void) return; |
| 1049 | 1056 | switch (posix.errno(posix.system.munlockall())) { |
| 1050 | 1057 | .SUCCESS => return, |
lib/std/process/Args.zig+1-1| ... | ... | @@ -372,7 +372,7 @@ pub const Iterator = struct { |
| 372 | 372 | index: usize, |
| 373 | 373 | args: [][:0]u8, |
| 374 | 374 | |
| 375 | pub const InitError = error{OutOfMemory} || std.posix.UnexpectedError; | |
| 375 | pub const InitError = error{OutOfMemory} || std.Io.UnexpectedError; | |
| 376 | 376 | |
| 377 | 377 | /// You must call deinit to free the internal buffer of the |
| 378 | 378 | /// iterator after you are done. |
lib/std/process/Child.zig+5-2| ... | ... | @@ -93,10 +93,13 @@ pub const ResourceUsageStatistics = struct { |
| 93 | 93 | |
| 94 | 94 | pub const Term = union(enum) { |
| 95 | 95 | exited: u8, |
| 96 | signal: std.posix.SIG, | |
| 97 | stopped: std.posix.SIG, | |
| 96 | signal: Signal, | |
| 97 | stopped: Signal, | |
| 98 | 98 | unknown: u32, |
| 99 | 99 | |
| 100 | // This probably needs some more thought for Windows. | |
| 101 | const Signal = if (native_os == .windows) std.c.SIG else std.posix.SIG; | |
| 102 | ||
| 100 | 103 | pub fn success(t: Term) bool { |
| 101 | 104 | return switch (t) { |
| 102 | 105 | .exited => |code| code == 0, |
src/link/MachO.zig+2-2| ... | ... | @@ -4438,7 +4438,7 @@ pub const MachError = error{ |
| 4438 | 4438 | /// Not enough permissions held to perform the requested kernel |
| 4439 | 4439 | /// call. |
| 4440 | 4440 | PermissionDenied, |
| 4441 | } || std.posix.UnexpectedError; | |
| 4441 | } || std.Io.UnexpectedError; | |
| 4442 | 4442 | |
| 4443 | 4443 | pub const MachTask = extern struct { |
| 4444 | 4444 | port: std.c.mach_port_name_t, |
| ... | ... | @@ -4906,7 +4906,7 @@ pub fn getKernError(err: std.c.kern_return_t) KernE { |
| 4906 | 4906 | return @as(KernE, @fromBackingInt(@intCast(@as(u32, @truncate(@as(usize, @intCast(err))))))); |
| 4907 | 4907 | } |
| 4908 | 4908 | |
| 4909 | pub fn unexpectedKernError(err: KernE) std.posix.UnexpectedError { | |
| 4909 | pub fn unexpectedKernError(err: KernE) std.Io.UnexpectedError { | |
| 4910 | 4910 | if (std.options.unexpected_error_tracing) { |
| 4911 | 4911 | std.debug.print("unexpected error: {d}\n", .{@backingInt(err)}); |
| 4912 | 4912 | std.debug.dumpCurrentStackTrace(.{}); |