authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-18 23:59:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-19 16:18:18-07:00
log8c94950c2496a5fa69f35b0f06f221e2c12339cf
treeab80d1a4f48e7401ad04dfb7855ad654e3761f63
parent6b2899df2ad5ad139ebcadd7e42762b095853be4

fix compilation failures found by CI


28 files changed, 126 insertions(+), 128 deletions(-)

lib/compiler/resinator/main.zig+11-11
...@@ -26,7 +26,7 @@ pub fn main() !void {...@@ -26,7 +26,7 @@ pub fn main() !void {
2626
27 if (args.len < 2) {27 if (args.len < 2) {
28 try renderErrorMessage(stderr.writer(), stderr_config, .err, "expected zig lib dir as first argument", .{});28 try renderErrorMessage(stderr.writer(), stderr_config, .err, "expected zig lib dir as first argument", .{});
29 std.os.exit(1);29 std.process.exit(1);
30 }30 }
31 const zig_lib_dir = args[1];31 const zig_lib_dir = args[1];
32 var cli_args = args[2..];32 var cli_args = args[2..];
...@@ -62,7 +62,7 @@ pub fn main() !void {...@@ -62,7 +62,7 @@ pub fn main() !void {
62 var options = cli.parse(allocator, cli_args, &cli_diagnostics) catch |err| switch (err) {62 var options = cli.parse(allocator, cli_args, &cli_diagnostics) catch |err| switch (err) {
63 error.ParseError => {63 error.ParseError => {
64 try error_handler.emitCliDiagnostics(allocator, cli_args, &cli_diagnostics);64 try error_handler.emitCliDiagnostics(allocator, cli_args, &cli_diagnostics);
65 std.os.exit(1);65 std.process.exit(1);
66 },66 },
67 else => |e| return e,67 else => |e| return e,
68 };68 };
...@@ -117,7 +117,7 @@ pub fn main() !void {...@@ -117,7 +117,7 @@ pub fn main() !void {
117 },117 },
118 }118 }
119 try error_handler.emitMessage(allocator, .note, "to disable auto includes, use the option /:auto-includes none", .{});119 try error_handler.emitMessage(allocator, .note, "to disable auto includes, use the option /:auto-includes none", .{});
120 std.os.exit(1);120 std.process.exit(1);
121 },121 },
122 };122 };
123123
...@@ -153,16 +153,16 @@ pub fn main() !void {...@@ -153,16 +153,16 @@ pub fn main() !void {
153 preprocess.preprocess(&comp, preprocessed_buf.writer(), argv.items, maybe_dependencies_list) catch |err| switch (err) {153 preprocess.preprocess(&comp, preprocessed_buf.writer(), argv.items, maybe_dependencies_list) catch |err| switch (err) {
154 error.GeneratedSourceError => {154 error.GeneratedSourceError => {
155 try error_handler.emitAroDiagnostics(allocator, "failed during preprocessor setup (this is always a bug):", &comp);155 try error_handler.emitAroDiagnostics(allocator, "failed during preprocessor setup (this is always a bug):", &comp);
156 std.os.exit(1);156 std.process.exit(1);
157 },157 },
158 // ArgError can occur if e.g. the .rc file is not found158 // ArgError can occur if e.g. the .rc file is not found
159 error.ArgError, error.PreprocessError => {159 error.ArgError, error.PreprocessError => {
160 try error_handler.emitAroDiagnostics(allocator, "failed during preprocessing:", &comp);160 try error_handler.emitAroDiagnostics(allocator, "failed during preprocessing:", &comp);
161 std.os.exit(1);161 std.process.exit(1);
162 },162 },
163 error.StreamTooLong => {163 error.StreamTooLong => {
164 try error_handler.emitMessage(allocator, .err, "failed during preprocessing: maximum file size exceeded", .{});164 try error_handler.emitMessage(allocator, .err, "failed during preprocessing: maximum file size exceeded", .{});
165 std.os.exit(1);165 std.process.exit(1);
166 },166 },
167 error.OutOfMemory => |e| return e,167 error.OutOfMemory => |e| return e,
168 };168 };
...@@ -171,7 +171,7 @@ pub fn main() !void {...@@ -171,7 +171,7 @@ pub fn main() !void {
171 } else {171 } else {
172 break :full_input std.fs.cwd().readFileAlloc(allocator, options.input_filename, std.math.maxInt(usize)) catch |err| {172 break :full_input std.fs.cwd().readFileAlloc(allocator, options.input_filename, std.math.maxInt(usize)) catch |err| {
173 try error_handler.emitMessage(allocator, .err, "unable to read input file path '{s}': {s}", .{ options.input_filename, @errorName(err) });173 try error_handler.emitMessage(allocator, .err, "unable to read input file path '{s}': {s}", .{ options.input_filename, @errorName(err) });
174 std.os.exit(1);174 std.process.exit(1);
175 };175 };
176 }176 }
177 };177 };
...@@ -191,14 +191,14 @@ pub fn main() !void {...@@ -191,14 +191,14 @@ pub fn main() !void {
191 const final_input = removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings) catch |err| switch (err) {191 const final_input = removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings) catch |err| switch (err) {
192 error.InvalidSourceMappingCollapse => {192 error.InvalidSourceMappingCollapse => {
193 try error_handler.emitMessage(allocator, .err, "failed during comment removal; this is a known bug", .{});193 try error_handler.emitMessage(allocator, .err, "failed during comment removal; this is a known bug", .{});
194 std.os.exit(1);194 std.process.exit(1);
195 },195 },
196 else => |e| return e,196 else => |e| return e,
197 };197 };
198198
199 var output_file = std.fs.cwd().createFile(options.output_filename, .{}) catch |err| {199 var output_file = std.fs.cwd().createFile(options.output_filename, .{}) catch |err| {
200 try error_handler.emitMessage(allocator, .err, "unable to create output file '{s}': {s}", .{ options.output_filename, @errorName(err) });200 try error_handler.emitMessage(allocator, .err, "unable to create output file '{s}': {s}", .{ options.output_filename, @errorName(err) });
201 std.os.exit(1);201 std.process.exit(1);
202 };202 };
203 var output_file_closed = false;203 var output_file_closed = false;
204 defer if (!output_file_closed) output_file.close();204 defer if (!output_file_closed) output_file.close();
...@@ -231,7 +231,7 @@ pub fn main() !void {...@@ -231,7 +231,7 @@ pub fn main() !void {
231 output_file_closed = true;231 output_file_closed = true;
232 // Failing to delete is not really a big deal, so swallow any errors232 // Failing to delete is not really a big deal, so swallow any errors
233 std.fs.cwd().deleteFile(options.output_filename) catch {};233 std.fs.cwd().deleteFile(options.output_filename) catch {};
234 std.os.exit(1);234 std.process.exit(1);
235 },235 },
236 else => |e| return e,236 else => |e| return e,
237 };237 };
...@@ -247,7 +247,7 @@ pub fn main() !void {...@@ -247,7 +247,7 @@ pub fn main() !void {
247 if (options.depfile_path) |depfile_path| {247 if (options.depfile_path) |depfile_path| {
248 var depfile = std.fs.cwd().createFile(depfile_path, .{}) catch |err| {248 var depfile = std.fs.cwd().createFile(depfile_path, .{}) catch |err| {
249 try error_handler.emitMessage(allocator, .err, "unable to create depfile '{s}': {s}", .{ depfile_path, @errorName(err) });249 try error_handler.emitMessage(allocator, .err, "unable to create depfile '{s}': {s}", .{ depfile_path, @errorName(err) });
250 std.os.exit(1);250 std.process.exit(1);
251 };251 };
252 defer depfile.close();252 defer depfile.close();
253253
lib/std/c/wasi.zig+2
...@@ -8,6 +8,8 @@ pub fn _errno() *c_int {...@@ -8,6 +8,8 @@ pub fn _errno() *c_int {
8 return &errno;8 return &errno;
9}9}
1010
11pub const PATH_MAX = 4096;
12
11pub const mode_t = u32;13pub const mode_t = u32;
12pub const time_t = i64;14pub const time_t = i64;
1315
lib/std/fs.zig+1-3
...@@ -53,14 +53,12 @@ pub const MAX_PATH_BYTES = max_path_bytes;...@@ -53,14 +53,12 @@ pub const MAX_PATH_BYTES = max_path_bytes;
53/// * On other platforms, `[]u8` file paths are opaque sequences of bytes with53/// * On other platforms, `[]u8` file paths are opaque sequences of bytes with
54/// no particular encoding.54/// no particular encoding.
55pub const max_path_bytes = switch (native_os) {55pub const max_path_bytes = switch (native_os) {
56 .linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .illumos, .plan9, .emscripten => posix.PATH_MAX,56 .linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .illumos, .plan9, .emscripten, .wasi => posix.PATH_MAX,
57 // Each WTF-16LE code unit may be expanded to 3 WTF-8 bytes.57 // Each WTF-16LE code unit may be expanded to 3 WTF-8 bytes.
58 // If it would require 4 WTF-8 bytes, then there would be a surrogate58 // If it would require 4 WTF-8 bytes, then there would be a surrogate
59 // pair in the WTF-16LE, and we (over)account 3 bytes for it that way.59 // pair in the WTF-16LE, and we (over)account 3 bytes for it that way.
60 // +1 for the null byte at the end, which can be encoded in 1 byte.60 // +1 for the null byte at the end, which can be encoded in 1 byte.
61 .windows => windows.PATH_MAX_WIDE * 3 + 1,61 .windows => windows.PATH_MAX_WIDE * 3 + 1,
62 // TODO work out what a reasonable value we should use here
63 .wasi => 4096,
64 else => if (@hasDecl(root, "os") and @hasDecl(root.os, "PATH_MAX"))62 else => if (@hasDecl(root, "os") and @hasDecl(root.os, "PATH_MAX"))
65 root.os.PATH_MAX63 root.os.PATH_MAX
66 else64 else
lib/std/fs/Dir.zig+1-1
...@@ -2555,7 +2555,7 @@ pub fn statFile(self: Dir, sub_path: []const u8) StatFileError!Stat {...@@ -2555,7 +2555,7 @@ pub fn statFile(self: Dir, sub_path: []const u8) StatFileError!Stat {
2555 return file.stat();2555 return file.stat();
2556 }2556 }
2557 if (native_os == .wasi and !builtin.link_libc) {2557 if (native_os == .wasi and !builtin.link_libc) {
2558 const st = try posix.fstatat_wasi(self.fd, sub_path, .{ .SYMLINK_FOLLOW = true });2558 const st = try std.os.fstatat_wasi(self.fd, sub_path, .{ .SYMLINK_FOLLOW = true });
2559 return Stat.fromWasi(st);2559 return Stat.fromWasi(st);
2560 }2560 }
2561 const st = try posix.fstatat(self.fd, sub_path, 0);2561 const st = try posix.fstatat(self.fd, sub_path, 0);
lib/std/fs/File.zig+2-2
...@@ -457,7 +457,7 @@ pub fn stat(self: File) StatError!Stat {...@@ -457,7 +457,7 @@ pub fn stat(self: File) StatError!Stat {
457 }457 }
458458
459 if (builtin.os.tag == .wasi and !builtin.link_libc) {459 if (builtin.os.tag == .wasi and !builtin.link_libc) {
460 const st = try posix.fstat_wasi(self.handle);460 const st = try std.os.fstat_wasi(self.handle);
461 return Stat.fromWasi(st);461 return Stat.fromWasi(st);
462 }462 }
463463
...@@ -1004,7 +1004,7 @@ pub fn metadata(self: File) MetadataError!Metadata {...@@ -1004,7 +1004,7 @@ pub fn metadata(self: File) MetadataError!Metadata {
1004 .statx = stx,1004 .statx = stx,
1005 };1005 };
1006 },1006 },
1007 .wasi => .{ .stat = try posix.fstat_wasi(self.handle) },1007 .wasi => .{ .stat = try std.os.fstat_wasi(self.handle) },
1008 else => .{ .stat = try posix.fstat(self.handle) },1008 else => .{ .stat = try posix.fstat(self.handle) },
1009 },1009 },
1010 };1010 };
lib/std/fs/wasi.zig+2-3
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const os = std.os;
4const mem = std.mem;3const mem = std.mem;
5const math = std.math;4const math = std.math;
6const fs = std.fs;5const fs = std.fs;
...@@ -14,10 +13,10 @@ pub const Preopens = struct {...@@ -14,10 +13,10 @@ pub const Preopens = struct {
14 // Indexed by file descriptor number.13 // Indexed by file descriptor number.
15 names: []const []const u8,14 names: []const []const u8,
1615
17 pub fn find(p: Preopens, name: []const u8) ?os.fd_t {16 pub fn find(p: Preopens, name: []const u8) ?std.posix.fd_t {
18 for (p.names, 0..) |elem_name, i| {17 for (p.names, 0..) |elem_name, i| {
19 if (mem.eql(u8, elem_name, name)) {18 if (mem.eql(u8, elem_name, name)) {
20 return @as(os.fd_t, @intCast(i));19 return @intCast(i);
21 }20 }
22 }21 }
23 return null;22 return null;
lib/std/os.zig+35-1
...@@ -22,6 +22,7 @@ const elf = std.elf;...@@ -22,6 +22,7 @@ const elf = std.elf;
22const fs = std.fs;22const fs = std.fs;
23const dl = @import("dynamic_library.zig");23const dl = @import("dynamic_library.zig");
24const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;24const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
25const posix = std.posix;
2526
26pub const linux = @import("os/linux.zig");27pub const linux = @import("os/linux.zig");
27pub const plan9 = @import("os/plan9.zig");28pub const plan9 = @import("os/plan9.zig");
...@@ -98,7 +99,6 @@ pub fn isGetFdPathSupportedOnTarget(os: std.Target.Os) bool {...@@ -98,7 +99,6 @@ pub fn isGetFdPathSupportedOnTarget(os: std.Target.Os) bool {
98///99///
99/// Calling this function is usually a bug.100/// Calling this function is usually a bug.
100pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[MAX_PATH_BYTES]u8) std.posix.RealPathError![]u8 {101pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[MAX_PATH_BYTES]u8) std.posix.RealPathError![]u8 {
101 const posix = std.posix;
102 if (!comptime isGetFdPathSupportedOnTarget(builtin.os)) {102 if (!comptime isGetFdPathSupportedOnTarget(builtin.os)) {
103 @compileError("querying for canonical path of a handle is unsupported on this host");103 @compileError("querying for canonical path of a handle is unsupported on this host");
104 }104 }
...@@ -234,3 +234,37 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[MAX_PATH_BYTES]u8) std.posix....@@ -234,3 +234,37 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[MAX_PATH_BYTES]u8) std.posix.
234 else => unreachable, // made unreachable by isGetFdPathSupportedOnTarget above234 else => unreachable, // made unreachable by isGetFdPathSupportedOnTarget above
235 }235 }
236}236}
237
238/// WASI-only. Same as `fstatat` but targeting WASI.
239/// `pathname` should be encoded as valid UTF-8.
240/// See also `fstatat`.
241pub fn fstatat_wasi(dirfd: posix.fd_t, pathname: []const u8, flags: wasi.lookupflags_t) posix.FStatAtError!wasi.filestat_t {
242 var stat: wasi.filestat_t = undefined;
243 switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) {
244 .SUCCESS => return stat,
245 .INVAL => unreachable,
246 .BADF => unreachable, // Always a race condition.
247 .NOMEM => return error.SystemResources,
248 .ACCES => return error.AccessDenied,
249 .FAULT => unreachable,
250 .NAMETOOLONG => return error.NameTooLong,
251 .NOENT => return error.FileNotFound,
252 .NOTDIR => return error.FileNotFound,
253 .NOTCAPABLE => return error.AccessDenied,
254 .ILSEQ => return error.InvalidUtf8,
255 else => |err| return posix.unexpectedErrno(err),
256 }
257}
258
259pub fn fstat_wasi(fd: posix.fd_t) posix.FStatError!wasi.filestat_t {
260 var stat: wasi.filestat_t = undefined;
261 switch (wasi.fd_filestat_get(fd, &stat)) {
262 .SUCCESS => return stat,
263 .INVAL => unreachable,
264 .BADF => unreachable, // Always a race condition.
265 .NOMEM => return error.SystemResources,
266 .ACCES => return error.AccessDenied,
267 .NOTCAPABLE => return error.AccessDenied,
268 else => |err| return posix.unexpectedErrno(err),
269 }
270}
lib/std/os/linux/start_pie.zig+1-1
...@@ -81,7 +81,7 @@ pub fn relocate(phdrs: []elf.Phdr) void {...@@ -81,7 +81,7 @@ pub fn relocate(phdrs: []elf.Phdr) void {
81 break :base @intFromPtr(dynv) - phdr.p_vaddr;81 break :base @intFromPtr(dynv) - phdr.p_vaddr;
82 }82 }
83 // This is not supposed to happen for well-formed binaries.83 // This is not supposed to happen for well-formed binaries.
84 std.os.abort();84 @trap();
85 };85 };
8686
87 var rel_addr: usize = 0;87 var rel_addr: usize = 0;
lib/std/posix.zig+6-40
...@@ -1635,7 +1635,7 @@ pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenE...@@ -1635,7 +1635,7 @@ pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenE
1635 errdefer close(fd);1635 errdefer close(fd);
16361636
1637 if (flags.write) {1637 if (flags.write) {
1638 const info = try fstat_wasi(fd);1638 const info = try std.os.fstat_wasi(fd);
1639 if (info.filetype == .DIRECTORY)1639 if (info.filetype == .DIRECTORY)
1640 return error.IsDir;1640 return error.IsDir;
1641 }1641 }
...@@ -4282,7 +4282,7 @@ pub const FStatError = error{...@@ -4282,7 +4282,7 @@ pub const FStatError = error{
4282/// Return information about a file descriptor.4282/// Return information about a file descriptor.
4283pub fn fstat(fd: fd_t) FStatError!Stat {4283pub fn fstat(fd: fd_t) FStatError!Stat {
4284 if (native_os == .wasi and !builtin.link_libc) {4284 if (native_os == .wasi and !builtin.link_libc) {
4285 return Stat.fromFilestat(try fstat_wasi(fd));4285 return Stat.fromFilestat(try std.os.fstat_wasi(fd));
4286 }4286 }
4287 if (native_os == .windows) {4287 if (native_os == .windows) {
4288 @compileError("fstat is not yet implemented on Windows");4288 @compileError("fstat is not yet implemented on Windows");
...@@ -4300,19 +4300,6 @@ pub fn fstat(fd: fd_t) FStatError!Stat {...@@ -4300,19 +4300,6 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
4300 }4300 }
4301}4301}
43024302
4303fn fstat_wasi(fd: fd_t) FStatError!wasi.filestat_t {
4304 var stat: wasi.filestat_t = undefined;
4305 switch (wasi.fd_filestat_get(fd, &stat)) {
4306 .SUCCESS => return stat,
4307 .INVAL => unreachable,
4308 .BADF => unreachable, // Always a race condition.
4309 .NOMEM => return error.SystemResources,
4310 .ACCES => return error.AccessDenied,
4311 .NOTCAPABLE => return error.AccessDenied,
4312 else => |err| return unexpectedErrno(err),
4313 }
4314}
4315
4316pub const FStatAtError = FStatError || error{4303pub const FStatAtError = FStatError || error{
4317 NameTooLong,4304 NameTooLong,
4318 FileNotFound,4305 FileNotFound,
...@@ -4325,10 +4312,10 @@ pub const FStatAtError = FStatError || error{...@@ -4325,10 +4312,10 @@ pub const FStatAtError = FStatError || error{
4325/// which is relative to `dirfd` handle.4312/// which is relative to `dirfd` handle.
4326/// On WASI, `pathname` should be encoded as valid UTF-8.4313/// On WASI, `pathname` should be encoded as valid UTF-8.
4327/// On other platforms, `pathname` is an opaque sequence of bytes with no particular encoding.4314/// On other platforms, `pathname` is an opaque sequence of bytes with no particular encoding.
4328/// See also `fstatatZ` and `fstatat_wasi`.4315/// See also `fstatatZ` and `std.os.fstatat_wasi`.
4329pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {4316pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {
4330 if (native_os == .wasi and !builtin.link_libc) {4317 if (native_os == .wasi and !builtin.link_libc) {
4331 const filestat = try fstatat_wasi(dirfd, pathname, .{4318 const filestat = try std.os.fstatat_wasi(dirfd, pathname, .{
4332 .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,4319 .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
4333 });4320 });
4334 return Stat.fromFilestat(filestat);4321 return Stat.fromFilestat(filestat);
...@@ -4344,7 +4331,7 @@ pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat...@@ -4344,7 +4331,7 @@ pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat
4344/// See also `fstatat`.4331/// See also `fstatat`.
4345pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat {4332pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat {
4346 if (native_os == .wasi and !builtin.link_libc) {4333 if (native_os == .wasi and !builtin.link_libc) {
4347 const filestat = try fstatat_wasi(dirfd, mem.sliceTo(pathname, 0), .{4334 const filestat = try std.os.fstatat_wasi(dirfd, mem.sliceTo(pathname, 0), .{
4348 .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,4335 .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
4349 });4336 });
4350 return Stat.fromFilestat(filestat);4337 return Stat.fromFilestat(filestat);
...@@ -4372,27 +4359,6 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S...@@ -4372,27 +4359,6 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S
4372 }4359 }
4373}4360}
43744361
4375/// WASI-only. Same as `fstatat` but targeting WASI.
4376/// `pathname` should be encoded as valid UTF-8.
4377/// See also `fstatat`.
4378fn fstatat_wasi(dirfd: fd_t, pathname: []const u8, flags: wasi.lookupflags_t) FStatAtError!wasi.filestat_t {
4379 var stat: wasi.filestat_t = undefined;
4380 switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) {
4381 .SUCCESS => return stat,
4382 .INVAL => unreachable,
4383 .BADF => unreachable, // Always a race condition.
4384 .NOMEM => return error.SystemResources,
4385 .ACCES => return error.AccessDenied,
4386 .FAULT => unreachable,
4387 .NAMETOOLONG => return error.NameTooLong,
4388 .NOENT => return error.FileNotFound,
4389 .NOTDIR => return error.FileNotFound,
4390 .NOTCAPABLE => return error.AccessDenied,
4391 .ILSEQ => return error.InvalidUtf8,
4392 else => |err| return unexpectedErrno(err),
4393 }
4394}
4395
4396pub const KQueueError = error{4362pub const KQueueError = error{
4397 /// The per-process limit on the number of open file descriptors has been reached.4363 /// The per-process limit on the number of open file descriptors has been reached.
4398 ProcessFdQuotaExceeded,4364 ProcessFdQuotaExceeded,
...@@ -4822,7 +4788,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr...@@ -4822,7 +4788,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr
4822 const resolved: RelativePathWasi = .{ .dir_fd = dirfd, .relative_path = path };4788 const resolved: RelativePathWasi = .{ .dir_fd = dirfd, .relative_path = path };
48234789
4824 const st = blk: {4790 const st = blk: {
4825 break :blk fstatat_wasi(dirfd, path, .{4791 break :blk std.os.fstatat_wasi(dirfd, path, .{
4826 .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,4792 .SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
4827 });4793 });
4828 } catch |err| switch (err) {4794 } catch |err| switch (err) {
src/DarwinPosixSpawn.zig+5-5
...@@ -81,7 +81,7 @@ pub const Actions = struct {...@@ -81,7 +81,7 @@ pub const Actions = struct {
81 }81 }
8282
83 pub fn open(self: *Actions, fd: std.c.fd_t, path: []const u8, flags: u32, mode: std.c.mode_t) Error!void {83 pub fn open(self: *Actions, fd: std.c.fd_t, path: []const u8, flags: u32, mode: std.c.mode_t) Error!void {
84 const posix_path = try std.os.toPosixPath(path);84 const posix_path = try std.posix.toPosixPath(path);
85 return self.openZ(fd, &posix_path, flags, mode);85 return self.openZ(fd, &posix_path, flags, mode);
86 }86 }
8787
...@@ -130,7 +130,7 @@ pub const Actions = struct {...@@ -130,7 +130,7 @@ pub const Actions = struct {
130 }130 }
131131
132 pub fn chdir(self: *Actions, path: []const u8) Error!void {132 pub fn chdir(self: *Actions, path: []const u8) Error!void {
133 const posix_path = try std.os.toPosixPath(path);133 const posix_path = try std.posix.toPosixPath(path);
134 return self.chdirZ(&posix_path);134 return self.chdirZ(&posix_path);
135 }135 }
136136
...@@ -164,7 +164,7 @@ pub fn spawn(...@@ -164,7 +164,7 @@ pub fn spawn(
164 argv: [*:null]?[*:0]const u8,164 argv: [*:null]?[*:0]const u8,
165 envp: [*:null]?[*:0]const u8,165 envp: [*:null]?[*:0]const u8,
166) Error!std.c.pid_t {166) Error!std.c.pid_t {
167 const posix_path = try std.os.toPosixPath(path);167 const posix_path = try std.posix.toPosixPath(path);
168 return spawnZ(&posix_path, actions, attr, argv, envp);168 return spawnZ(&posix_path, actions, attr, argv, envp);
169}169}
170170
...@@ -204,12 +204,12 @@ pub fn spawnZ(...@@ -204,12 +204,12 @@ pub fn spawnZ(
204 }204 }
205}205}
206206
207pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.os.WaitPidResult {207pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.posix.WaitPidResult {
208 var status: c_int = undefined;208 var status: c_int = undefined;
209 while (true) {209 while (true) {
210 const rc = waitpid(pid, &status, @as(c_int, @intCast(flags)));210 const rc = waitpid(pid, &status, @as(c_int, @intCast(flags)));
211 switch (errno(rc)) {211 switch (errno(rc)) {
212 .SUCCESS => return std.os.WaitPidResult{212 .SUCCESS => return std.posix.WaitPidResult{
213 .pid = @as(std.c.pid_t, @intCast(rc)),213 .pid = @as(std.c.pid_t, @intCast(rc)),
214 .status = @as(u32, @bitCast(status)),214 .status = @as(u32, @bitCast(status)),
215 },215 },
src/link/MachO.zig+4-4
...@@ -4136,10 +4136,10 @@ pub fn getDebugSymbols(self: *MachO) ?*DebugSymbols {...@@ -4136,10 +4136,10 @@ pub fn getDebugSymbols(self: *MachO) ?*DebugSymbols {
4136 return null;4136 return null;
4137}4137}
41384138
4139pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void {4139pub fn ptraceAttach(self: *MachO, pid: std.posix.pid_t) !void {
4140 if (!is_hot_update_compatible) return;4140 if (!is_hot_update_compatible) return;
41414141
4142 const mach_task = try std.os.darwin.machTaskForPid(pid);4142 const mach_task = try std.c.machTaskForPid(pid);
4143 log.debug("Mach task for pid {d}: {any}", .{ pid, mach_task });4143 log.debug("Mach task for pid {d}: {any}", .{ pid, mach_task });
4144 self.hot_state.mach_task = mach_task;4144 self.hot_state.mach_task = mach_task;
41454145
...@@ -4149,7 +4149,7 @@ pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void {...@@ -4149,7 +4149,7 @@ pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void {
4149 // try std.os.ptrace(std.os.darwin.PT.ATTACHEXC, pid, 0, 0);4149 // try std.os.ptrace(std.os.darwin.PT.ATTACHEXC, pid, 0, 0);
4150}4150}
41514151
4152pub fn ptraceDetach(self: *MachO, pid: std.os.pid_t) !void {4152pub fn ptraceDetach(self: *MachO, pid: std.posix.pid_t) !void {
4153 if (!is_hot_update_compatible) return;4153 if (!is_hot_update_compatible) return;
41544154
4155 _ = pid;4155 _ = pid;
...@@ -4330,7 +4330,7 @@ const Section = struct {...@@ -4330,7 +4330,7 @@ const Section = struct {
4330};4330};
43314331
4332const HotUpdateState = struct {4332const HotUpdateState = struct {
4333 mach_task: ?std.os.darwin.MachTask = null,4333 mach_task: ?std.c.MachTask = null,
4334};4334};
43354335
4336pub const DynamicRelocs = struct {4336pub const DynamicRelocs = struct {
src/main.zig+20-19
...@@ -12,6 +12,7 @@ const Color = std.zig.Color;...@@ -12,6 +12,7 @@ const Color = std.zig.Color;
12const warn = std.log.warn;12const warn = std.log.warn;
13const ThreadPool = std.Thread.Pool;13const ThreadPool = std.Thread.Pool;
14const cleanExit = std.process.cleanExit;14const cleanExit = std.process.cleanExit;
15const native_os = builtin.os.tag;
1516
16const tracy = @import("tracy.zig");17const tracy = @import("tracy.zig");
17const Compilation = @import("Compilation.zig");18const Compilation = @import("Compilation.zig");
...@@ -158,9 +159,9 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{...@@ -158,9 +159,9 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{
158pub fn main() anyerror!void {159pub fn main() anyerror!void {
159 crash_report.initialize();160 crash_report.initialize();
160161
161 const use_gpa = (build_options.force_gpa or !builtin.link_libc) and builtin.os.tag != .wasi;162 const use_gpa = (build_options.force_gpa or !builtin.link_libc) and native_os != .wasi;
162 const gpa = gpa: {163 const gpa = gpa: {
163 if (builtin.os.tag == .wasi) {164 if (native_os == .wasi) {
164 break :gpa std.heap.wasm_allocator;165 break :gpa std.heap.wasm_allocator;
165 }166 }
166 if (use_gpa) {167 if (use_gpa) {
...@@ -187,7 +188,7 @@ pub fn main() anyerror!void {...@@ -187,7 +188,7 @@ pub fn main() anyerror!void {
187 return mainArgs(gpa_tracy.allocator(), arena, args);188 return mainArgs(gpa_tracy.allocator(), arena, args);
188 }189 }
189190
190 if (builtin.os.tag == .wasi) {191 if (native_os == .wasi) {
191 wasi_preopens = try fs.wasi.preopensAlloc(arena);192 wasi_preopens = try fs.wasi.preopensAlloc(arena);
192 }193 }
193194
...@@ -813,9 +814,9 @@ fn buildOutputType(...@@ -813,9 +814,9 @@ fn buildOutputType(
813 var no_builtin = false;814 var no_builtin = false;
814 var listen: Listen = .none;815 var listen: Listen = .none;
815 var debug_compile_errors = false;816 var debug_compile_errors = false;
816 var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and817 var verbose_link = (native_os != .wasi or builtin.link_libc) and
817 EnvVar.ZIG_VERBOSE_LINK.isSet();818 EnvVar.ZIG_VERBOSE_LINK.isSet();
818 var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and819 var verbose_cc = (native_os != .wasi or builtin.link_libc) and
819 EnvVar.ZIG_VERBOSE_CC.isSet();820 EnvVar.ZIG_VERBOSE_CC.isSet();
820 var verbose_air = false;821 var verbose_air = false;
821 var verbose_intern_pool = false;822 var verbose_intern_pool = false;
...@@ -991,7 +992,7 @@ fn buildOutputType(...@@ -991,7 +992,7 @@ fn buildOutputType(
991 // if it exists, default the color setting to .off992 // if it exists, default the color setting to .off
992 // explicit --color arguments will still override this setting.993 // explicit --color arguments will still override this setting.
993 // Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162994 // Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162
994 var color: Color = if (builtin.os.tag == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto;995 var color: Color = if (native_os == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto;
995996
996 switch (arg_mode) {997 switch (arg_mode) {
997 .build, .translate_c, .zig_test, .run => {998 .build, .translate_c, .zig_test, .run => {
...@@ -2684,7 +2685,7 @@ fn buildOutputType(...@@ -2684,7 +2685,7 @@ fn buildOutputType(
2684 fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });2685 fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });
2685 },2686 },
2686 };2687 };
2687 } else if (builtin.os.tag == .wasi) {2688 } else if (native_os == .wasi) {
2688 break :d getWasiPreopen("/lib");2689 break :d getWasiPreopen("/lib");
2689 } else if (self_exe_path) |p| {2690 } else if (self_exe_path) |p| {
2690 break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| {2691 break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| {
...@@ -2703,7 +2704,7 @@ fn buildOutputType(...@@ -2703,7 +2704,7 @@ fn buildOutputType(
2703 .path = p,2704 .path = p,
2704 };2705 };
2705 }2706 }
2706 if (builtin.os.tag == .wasi) {2707 if (native_os == .wasi) {
2707 break :l getWasiPreopen("/cache");2708 break :l getWasiPreopen("/cache");
2708 }2709 }
2709 const p = try introspect.resolveGlobalCacheDir(arena);2710 const p = try introspect.resolveGlobalCacheDir(arena);
...@@ -4368,7 +4369,7 @@ fn runOrTest(...@@ -4368,7 +4369,7 @@ fn runOrTest(
4368 }4369 }
4369 } else {4370 } else {
4370 const cmd = try std.mem.join(arena, " ", argv.items);4371 const cmd = try std.mem.join(arena, " ", argv.items);
4371 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });4372 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd });
4372 }4373 }
4373}4374}
43744375
...@@ -4747,9 +4748,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -4747,9 +4748,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4747 var child_argv = std.ArrayList([]const u8).init(arena);4748 var child_argv = std.ArrayList([]const u8).init(arena);
4748 var reference_trace: ?u32 = null;4749 var reference_trace: ?u32 = null;
4749 var debug_compile_errors = false;4750 var debug_compile_errors = false;
4750 var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and4751 var verbose_link = (native_os != .wasi or builtin.link_libc) and
4751 EnvVar.ZIG_VERBOSE_LINK.isSet();4752 EnvVar.ZIG_VERBOSE_LINK.isSet();
4752 var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and4753 var verbose_cc = (native_os != .wasi or builtin.link_libc) and
4753 EnvVar.ZIG_VERBOSE_CC.isSet();4754 EnvVar.ZIG_VERBOSE_CC.isSet();
4754 var verbose_air = false;4755 var verbose_air = false;
4755 var verbose_intern_pool = false;4756 var verbose_intern_pool = false;
...@@ -4894,7 +4895,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -4894,7 +4895,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4894 }4895 }
4895 }4896 }
48964897
4897 const work_around_btrfs_bug = builtin.os.tag == .linux and4898 const work_around_btrfs_bug = native_os == .linux and
4898 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();4899 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
4899 const color: Color = .auto;4900 const color: Color = .auto;
49004901
...@@ -5311,7 +5312,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -5311,7 +5312,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
5311 }5312 }
5312 } else {5313 } else {
5313 const cmd = try std.mem.join(arena, " ", child_argv.items);5314 const cmd = try std.mem.join(arena, " ", child_argv.items);
5314 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });5315 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd });
5315 }5316 }
5316 }5317 }
5317}5318}
...@@ -5543,7 +5544,7 @@ fn jitCmd(...@@ -5543,7 +5544,7 @@ fn jitCmd(
5543 if (!process.can_spawn) {5544 if (!process.can_spawn) {
5544 const cmd = try std.mem.join(arena, " ", child_argv.items);5545 const cmd = try std.mem.join(arena, " ", child_argv.items);
5545 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{5546 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{
5546 @tagName(builtin.os.tag), cmd,5547 @tagName(native_os), cmd,
5547 });5548 });
5548 }5549 }
55495550
...@@ -5655,7 +5656,7 @@ pub fn lldMain(...@@ -5655,7 +5656,7 @@ pub fn lldMain(
5655 var count: usize = 0;5656 var count: usize = 0;
5656 };5657 };
5657 if (CallCounter.count == 1) { // Issue the warning on the first repeat call5658 if (CallCounter.count == 1) { // Issue the warning on the first repeat call
5658 warn("invoking LLD for the second time within the same process because the host OS ({s}) does not support spawning child processes. This sometimes activates LLD bugs", .{@tagName(builtin.os.tag)});5659 warn("invoking LLD for the second time within the same process because the host OS ({s}) does not support spawning child processes. This sometimes activates LLD bugs", .{@tagName(native_os)});
5659 }5660 }
5660 CallCounter.count += 1;5661 CallCounter.count += 1;
56615662
...@@ -5985,7 +5986,7 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel {...@@ -5985,7 +5986,7 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel {
5985/// garbage collector to run concurrently to zig processes, and to allow multiple5986/// garbage collector to run concurrently to zig processes, and to allow multiple
5986/// zig processes to run concurrently with each other, without clobbering each other.5987/// zig processes to run concurrently with each other, without clobbering each other.
5987fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {5988fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
5988 const have_rlimit = switch (builtin.os.tag) {5989 const have_rlimit = switch (native_os) {
5989 .windows, .wasi => false,5990 .windows, .wasi => false,
5990 else => true,5991 else => true,
5991 };5992 };
...@@ -5993,13 +5994,13 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {...@@ -5993,13 +5994,13 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
5993 const posix = std.posix;5994 const posix = std.posix;
59945995
5995 var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.5996 var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.
5996 if (comptime builtin.target.isDarwin()) {5997 if (native_os.isDarwin()) {
5997 // On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`.5998 // On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`.
5998 // According to the man pages for setrlimit():5999 // According to the man pages for setrlimit():
5999 // setrlimit() now returns with errno set to EINVAL in places that historically succeeded.6000 // setrlimit() now returns with errno set to EINVAL in places that historically succeeded.
6000 // It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE.6001 // It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE.
6001 // Use "rlim_cur = min(OPEN_MAX, rlim_max)".6002 // Use "rlim_cur = min(OPEN_MAX, rlim_max)".
6002 lim.max = @min(std.os.darwin.OPEN_MAX, lim.max);6003 lim.max = @min(std.c.OPEN_MAX, lim.max);
6003 }6004 }
6004 if (lim.cur == lim.max) return;6005 if (lim.cur == lim.max) return;
60056006
...@@ -6770,7 +6771,7 @@ fn cmdFetch(...@@ -6770,7 +6771,7 @@ fn cmdFetch(
6770 args: []const []const u8,6771 args: []const []const u8,
6771) !void {6772) !void {
6772 const color: Color = .auto;6773 const color: Color = .auto;
6773 const work_around_btrfs_bug = builtin.os.tag == .linux and6774 const work_around_btrfs_bug = native_os == .linux and
6774 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();6775 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
6775 var opt_path_or_url: ?[]const u8 = null;6776 var opt_path_or_url: ?[]const u8 = null;
6776 var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);6777 var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);
test/cases/arithmetic_operations.0.zig+1-1
...@@ -8,7 +8,7 @@ pub fn main() void {...@@ -8,7 +8,7 @@ pub fn main() void {
8fn print(a: u32, b: u32) void {8fn print(a: u32, b: u32) void {
9 const str = "123456789";9 const str = "123456789";
10 const len = a + b;10 const len = a + b;
11 _ = std.os.write(1, str[0..len]) catch {};11 _ = std.posix.write(1, str[0..len]) catch {};
12}12}
1313
14// run14// run
test/cases/arithmetic_operations.1.zig+1-1
...@@ -8,7 +8,7 @@ pub fn main() void {...@@ -8,7 +8,7 @@ pub fn main() void {
8fn print(a: u32, b: u32) void {8fn print(a: u32, b: u32) void {
9 const str = "123456789";9 const str = "123456789";
10 const len = a - b;10 const len = a - b;
11 _ = std.os.write(1, str[0..len]) catch {};11 _ = std.posix.write(1, str[0..len]) catch {};
12}12}
1313
14// run14// run
test/cases/arithmetic_operations.2.zig+1-1
...@@ -8,7 +8,7 @@ pub fn main() void {...@@ -8,7 +8,7 @@ pub fn main() void {
8fn print(a: u32, b: u32) void {8fn print(a: u32, b: u32) void {
9 const str = "123456789";9 const str = "123456789";
10 const len = a & b;10 const len = a & b;
11 _ = std.os.write(1, str[0..len]) catch {};11 _ = std.posix.write(1, str[0..len]) catch {};
12}12}
1313
14// run14// run
test/cases/arithmetic_operations.3.zig+1-1
...@@ -8,7 +8,7 @@ pub fn main() void {...@@ -8,7 +8,7 @@ pub fn main() void {
8fn print(a: u32, b: u32) void {8fn print(a: u32, b: u32) void {
9 const str = "123456789";9 const str = "123456789";
10 const len = a | b;10 const len = a | b;
11 _ = std.os.write(1, str[0..len]) catch {};11 _ = std.posix.write(1, str[0..len]) catch {};
12}12}
1313
14// run14// run
test/cases/arithmetic_operations.4.zig+1-1
...@@ -8,7 +8,7 @@ pub fn main() void {...@@ -8,7 +8,7 @@ pub fn main() void {
8fn print(a: u32, b: u32) void {8fn print(a: u32, b: u32) void {
9 const str = "123456789";9 const str = "123456789";
10 const len = a ^ b;10 const len = a ^ b;
11 _ = std.os.write(1, str[0..len]) catch {};11 _ = std.posix.write(1, str[0..len]) catch {};
12}12}
1313
14// run14// run
test/cases/errors.0.zig+1-1
...@@ -7,7 +7,7 @@ pub fn main() void {...@@ -7,7 +7,7 @@ pub fn main() void {
7fn foo() anyerror!void {}7fn foo() anyerror!void {}
88
9fn print() void {9fn print() void {
10 _ = std.os.write(1, "Hello, World!\n") catch {};10 _ = std.posix.write(1, "Hello, World!\n") catch {};
11}11}
1212
13// run13// run
test/cases/errors.1.zig+1-1
...@@ -9,7 +9,7 @@ fn foo() anyerror!void {...@@ -9,7 +9,7 @@ fn foo() anyerror!void {
9}9}
1010
11fn print() void {11fn print() void {
12 _ = std.os.write(1, "Hello, World!\n") catch {};12 _ = std.posix.write(1, "Hello, World!\n") catch {};
13}13}
1414
15// run15// run
test/cases/function_pointers.zig+2-2
...@@ -12,11 +12,11 @@ pub fn main() void {...@@ -12,11 +12,11 @@ pub fn main() void {
12}12}
1313
14fn stopSayingThat() void {14fn stopSayingThat() void {
15 _ = std.os.write(1, "Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n") catch {};15 _ = std.posix.write(1, "Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n") catch {};
16}16}
1717
18fn moveEveryZig() void {18fn moveEveryZig() void {
19 _ = std.os.write(1, "All your codebase are belong to us\n") catch {};19 _ = std.posix.write(1, "All your codebase are belong to us\n") catch {};
20}20}
2121
22// run22// run
test/cases/parameters_and_return_values.0.zig+1-1
...@@ -10,7 +10,7 @@ fn id(x: u32) u32 {...@@ -10,7 +10,7 @@ fn id(x: u32) u32 {
1010
11fn print(len: u32) void {11fn print(len: u32) void {
12 const str = "Hello, World!\n";12 const str = "Hello, World!\n";
13 _ = std.os.write(1, str[0..len]) catch {};13 _ = std.posix.write(1, str[0..len]) catch {};
14}14}
1515
16// run16// run
test/cases/print_u32s.zig+2-2
...@@ -12,10 +12,10 @@ fn printNumberHex(x: u32) void {...@@ -12,10 +12,10 @@ fn printNumberHex(x: u32) void {
12 var i: u5 = 28;12 var i: u5 = 28;
13 while (true) : (i -= 4) {13 while (true) : (i -= 4) {
14 const digit = (x >> i) & 0xf;14 const digit = (x >> i) & 0xf;
15 _ = std.os.write(1, &.{digit_chars[digit]}) catch {};15 _ = std.posix.write(1, &.{digit_chars[digit]}) catch {};
16 if (i == 0) break;16 if (i == 0) break;
17 }17 }
18 _ = std.os.write(1, "\n") catch {};18 _ = std.posix.write(1, "\n") catch {};
19}19}
2020
21// run21// run
test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig +3-3
...@@ -11,21 +11,21 @@ fn foo() void {...@@ -11,21 +11,21 @@ fn foo() void {
11 }11 }
12 var f = async bar(@frame());12 var f = async bar(@frame());
13 _ = &f;13 _ = &f;
14 std.os.exit(1);14 std.process.exit(1);
15}15}
1616
17fn bar(frame: anyframe) void {17fn bar(frame: anyframe) void {
18 suspend {18 suspend {
19 resume frame;19 resume frame;
20 }20 }
21 std.os.exit(1);21 std.process.exit(1);
22}22}
2323
24var global_frame: anyframe = undefined;24var global_frame: anyframe = undefined;
25pub fn main() !void {25pub fn main() !void {
26 _ = async foo();26 _ = async foo();
27 resume global_frame;27 resume global_frame;
28 std.os.exit(1);28 std.process.exit(1);
29}29}
30// run30// run
31// backend=stage131// backend=stage1
test/cases/safety/resuming a non-suspended function which never been suspended.zig +2-2
...@@ -8,14 +8,14 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -8,14 +8,14 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
8fn foo() void {8fn foo() void {
9 var f = async bar(@frame());9 var f = async bar(@frame());
10 _ = &f;10 _ = &f;
11 std.os.exit(1);11 std.process.exit(1);
12}12}
1313
14fn bar(frame: anyframe) void {14fn bar(frame: anyframe) void {
15 suspend {15 suspend {
16 resume frame;16 resume frame;
17 }17 }
18 std.os.exit(1);18 std.process.exit(1);
19}19}
2020
21pub fn main() !void {21pub fn main() !void {
test/link/glibc_compat/glibc_runtime_check.zig+2-2
...@@ -30,11 +30,11 @@ fn checkStat() !void {...@@ -30,11 +30,11 @@ fn checkStat() !void {
30 var stat = std.mem.zeroes(std.c.Stat);30 var stat = std.mem.zeroes(std.c.Stat);
31 var result = std.c.fstatat(cwdFd, "a_file_that_definitely_does_not_exist", &stat, 0);31 var result = std.c.fstatat(cwdFd, "a_file_that_definitely_does_not_exist", &stat, 0);
32 assert(result == -1);32 assert(result == -1);
33 assert(std.c.getErrno(result) == .NOENT);33 assert(std.posix.errno(result) == .NOENT);
3434
35 result = std.c.stat("a_file_that_definitely_does_not_exist", &stat);35 result = std.c.stat("a_file_that_definitely_does_not_exist", &stat);
36 assert(result == -1);36 assert(result == -1);
37 assert(std.c.getErrno(result) == .NOENT);37 assert(std.posix.errno(result) == .NOENT);
38}38}
3939
40// PR #17607 - reallocarray not visible in headers40// PR #17607 - reallocarray not visible in headers
test/standalone/sigpipe/breakpipe.zig+7-9
...@@ -1,19 +1,17 @@...@@ -1,19 +1,17 @@
1const std = @import("std");1const std = @import("std");
2const build_options = @import("build_options");2const build_options = @import("build_options");
33
4pub usingnamespace if (build_options.keep_sigpipe) struct {4pub const std_options = .{
5 pub const std_options = .{5 .keep_sigpipe = build_options.keep_sigpipe,
6 .keep_sigpipe = true,6};
7 };
8} else struct {};
97
10pub fn main() !void {8pub fn main() !void {
11 const pipe = try std.os.pipe();9 const pipe = try std.posix.pipe();
12 std.os.close(pipe[0]);10 std.posix.close(pipe[0]);
13 _ = std.os.write(pipe[1], "a") catch |err| switch (err) {11 _ = std.posix.write(pipe[1], "a") catch |err| switch (err) {
14 error.BrokenPipe => {12 error.BrokenPipe => {
15 try std.io.getStdOut().writer().writeAll("BrokenPipe\n");13 try std.io.getStdOut().writer().writeAll("BrokenPipe\n");
16 std.os.exit(123);14 std.posix.exit(123);
17 },15 },
18 else => |e| return e,16 else => |e| return e,
19 };17 };
test/standalone/sigpipe/build.zig+6-6
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const os = std.os;2const posix = std.posix;
33
4pub fn build(b: *std.build.Builder) !void {4pub fn build(b: *std.build.Builder) !void {
5 const test_step = b.step("test", "Test it");5 const test_step = b.step("test", "Test it");
...@@ -16,12 +16,12 @@ pub fn build(b: *std.build.Builder) !void {...@@ -16,12 +16,12 @@ pub fn build(b: *std.build.Builder) !void {
16 // This test runs "breakpipe" as a child process and that process16 // This test runs "breakpipe" as a child process and that process
17 // depends on inheriting a SIGPIPE disposition of "default".17 // depends on inheriting a SIGPIPE disposition of "default".
18 {18 {
19 const act = os.Sigaction{19 const act = posix.Sigaction{
20 .handler = .{ .handler = os.SIG.DFL },20 .handler = .{ .handler = posix.SIG.DFL },
21 .mask = os.empty_sigset,21 .mask = posix.empty_sigset,
22 .flags = 0,22 .flags = 0,
23 };23 };
24 try os.sigaction(os.SIG.PIPE, &act, null);24 try posix.sigaction(posix.SIG.PIPE, &act, null);
25 }25 }
2626
27 for ([_]bool{ false, true }) |keep_sigpipe| {27 for ([_]bool{ false, true }) |keep_sigpipe| {
...@@ -34,7 +34,7 @@ pub fn build(b: *std.build.Builder) !void {...@@ -34,7 +34,7 @@ pub fn build(b: *std.build.Builder) !void {
34 exe.addOptions("build_options", options);34 exe.addOptions("build_options", options);
35 const run = b.addRunArtifact(exe);35 const run = b.addRunArtifact(exe);
36 if (keep_sigpipe) {36 if (keep_sigpipe) {
37 run.addCheck(.{ .expect_term = .{ .Signal = std.os.SIG.PIPE } });37 run.addCheck(.{ .expect_term = .{ .Signal = std.posix.SIG.PIPE } });
38 } else {38 } else {
39 run.addCheck(.{ .expect_stdout_exact = "BrokenPipe\n" });39 run.addCheck(.{ .expect_stdout_exact = "BrokenPipe\n" });
40 run.addCheck(.{ .expect_term = .{ .Exited = 123 } });40 run.addCheck(.{ .expect_term = .{ .Exited = 123 } });
test/standalone/windows_spawn/main.zig+4-4
...@@ -25,13 +25,13 @@ pub fn main() anyerror!void {...@@ -25,13 +25,13 @@ pub fn main() anyerror!void {
25 defer allocator.free(tmp_relative_path);25 defer allocator.free(tmp_relative_path);
2626
27 // Clear PATH27 // Clear PATH
28 std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(28 std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
29 utf16Literal("PATH"),29 utf16Literal("PATH"),
30 null,30 null,
31 ) == windows.TRUE);31 ) == windows.TRUE);
3232
33 // Set PATHEXT to something predictable33 // Set PATHEXT to something predictable
34 std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(34 std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
35 utf16Literal("PATHEXT"),35 utf16Literal("PATHEXT"),
36 utf16Literal(".COM;.EXE;.BAT;.CMD;.JS"),36 utf16Literal(".COM;.EXE;.BAT;.CMD;.JS"),
37 ) == windows.TRUE);37 ) == windows.TRUE);
...@@ -39,7 +39,7 @@ pub fn main() anyerror!void {...@@ -39,7 +39,7 @@ pub fn main() anyerror!void {
39 // No PATH, so it should fail to find anything not in the cwd39 // No PATH, so it should fail to find anything not in the cwd
40 try testExecError(error.FileNotFound, allocator, "something_missing");40 try testExecError(error.FileNotFound, allocator, "something_missing");
4141
42 std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(42 std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
43 utf16Literal("PATH"),43 utf16Literal("PATH"),
44 tmp_absolute_path_w,44 tmp_absolute_path_w,
45 ) == windows.TRUE);45 ) == windows.TRUE);
...@@ -120,7 +120,7 @@ pub fn main() anyerror!void {...@@ -120,7 +120,7 @@ pub fn main() anyerror!void {
120 const something_subdir_abs_path = try std.mem.concatWithSentinel(allocator, u16, &.{ tmp_absolute_path_w, utf16Literal("\\something") }, 0);120 const something_subdir_abs_path = try std.mem.concatWithSentinel(allocator, u16, &.{ tmp_absolute_path_w, utf16Literal("\\something") }, 0);
121 defer allocator.free(something_subdir_abs_path);121 defer allocator.free(something_subdir_abs_path);
122122
123 std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(123 std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
124 utf16Literal("PATH"),124 utf16Literal("PATH"),
125 something_subdir_abs_path,125 something_subdir_abs_path,
126 ) == windows.TRUE);126 ) == windows.TRUE);