authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-06-30 18:18:25+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-06-30 18:21:38+02:00
log8306826d53bf6dd0c5ea5ea27963374b31aa6dd1
tree382f0ca9e0612bb8d173928a4f61e7663b5a1de3
parent5bc99dd7e8c037aa6c5f46d779fba99163d1da36

Map ENOTCAPABLE into error.AccessDenied instead of error.NotCapable

This is direct result of review comments left by andrewrk and daurnimator. It makes sense to map `ENOTCAPABLE` into a more generic `error.AccessDenied`.

6 files changed, 69 insertions(+), 114 deletions(-)

lib/std/child_process.zig-1
...@@ -364,7 +364,6 @@ pub const ChildProcess = struct {...@@ -364,7 +364,6 @@ pub const ChildProcess = struct {
364 error.FileTooBig => unreachable,364 error.FileTooBig => unreachable,
365 error.DeviceBusy => unreachable,365 error.DeviceBusy => unreachable,
366 error.FileLocksNotSupported => unreachable,366 error.FileLocksNotSupported => unreachable,
367 error.NotCapable => unreachable, // until WASI comes up with multi-processing (if ever)
368 else => |e| return e,367 else => |e| return e,
369 }368 }
370 else369 else
lib/std/elf.zig+1-1
...@@ -551,7 +551,7 @@ fn preadNoEof(file: std.fs.File, buf: []u8, offset: u64) !void {...@@ -551,7 +551,7 @@ fn preadNoEof(file: std.fs.File, buf: []u8, offset: u64) !void {
551 error.InputOutput => return error.FileSystem,551 error.InputOutput => return error.FileSystem,
552 error.Unexpected => return error.Unexpected,552 error.Unexpected => return error.Unexpected,
553 error.WouldBlock => return error.Unexpected,553 error.WouldBlock => return error.Unexpected,
554 error.NotCapable => unreachable, // NotCapable mainly pertains WASI target so it's a bug if we hit it here554 error.AccessDenied => return error.Unexpected,
555 };555 };
556 if (len == 0) return error.UnexpectedEndOfFile;556 if (len == 0) return error.UnexpectedEndOfFile;
557 i += len;557 i += len;
lib/std/fs.zig+3-18
...@@ -264,13 +264,7 @@ pub const Dir = struct {...@@ -264,13 +264,7 @@ pub const Dir = struct {
264 pub const Kind = File.Kind;264 pub const Kind = File.Kind;
265 };265 };
266266
267 const IteratorError = error{267 const IteratorError = error{AccessDenied} || os.UnexpectedError;
268 AccessDenied,
269
270 /// WASI-only. This error occurs when the underlying `Dir` file descriptor does
271 /// not hold the required rights to call `fd_readdir` on it.
272 NotCapable,
273 } || os.UnexpectedError;
274268
275 pub const Iterator = switch (builtin.os.tag) {269 pub const Iterator = switch (builtin.os.tag) {
276 .macosx, .ios, .freebsd, .netbsd, .dragonfly => struct {270 .macosx, .ios, .freebsd, .netbsd, .dragonfly => struct {
...@@ -541,7 +535,7 @@ pub const Dir = struct {...@@ -541,7 +535,7 @@ pub const Dir = struct {
541 w.EFAULT => unreachable,535 w.EFAULT => unreachable,
542 w.ENOTDIR => unreachable,536 w.ENOTDIR => unreachable,
543 w.EINVAL => unreachable,537 w.EINVAL => unreachable,
544 w.ENOTCAPABLE => return error.NotCapable,538 w.ENOTCAPABLE => return error.AccessDenied,
545 else => |err| return os.unexpectedErrno(err),539 else => |err| return os.unexpectedErrno(err),
546 }540 }
547 if (bufused == 0) return null;541 if (bufused == 0) return null;
...@@ -628,7 +622,6 @@ pub const Dir = struct {...@@ -628,7 +622,6 @@ pub const Dir = struct {
628 InvalidUtf8,622 InvalidUtf8,
629 BadPathName,623 BadPathName,
630 DeviceBusy,624 DeviceBusy,
631 NotCapable,
632 } || os.UnexpectedError;625 } || os.UnexpectedError;
633626
634 pub fn close(self: *Dir) void {627 pub fn close(self: *Dir) void {
...@@ -1113,7 +1106,7 @@ pub const Dir = struct {...@@ -1113,7 +1106,7 @@ pub const Dir = struct {
1113 }1106 }
1114 }1107 }
11151108
1116 pub const DeleteFileError = os.UnlinkatError;1109 pub const DeleteFileError = os.UnlinkError;
11171110
1118 /// Delete a file name and possibly the file it refers to, based on an open directory handle.1111 /// Delete a file name and possibly the file it refers to, based on an open directory handle.
1119 /// Asserts that the path parameter has no null bytes.1112 /// Asserts that the path parameter has no null bytes.
...@@ -1155,7 +1148,6 @@ pub const Dir = struct {...@@ -1155,7 +1148,6 @@ pub const Dir = struct {
1155 ReadOnlyFileSystem,1148 ReadOnlyFileSystem,
1156 InvalidUtf8,1149 InvalidUtf8,
1157 BadPathName,1150 BadPathName,
1158 NotCapable,
1159 Unexpected,1151 Unexpected,
1160 };1152 };
11611153
...@@ -1258,7 +1250,6 @@ pub const Dir = struct {...@@ -1258,7 +1250,6 @@ pub const Dir = struct {
1258 /// On Windows, file paths cannot contain these characters:1250 /// On Windows, file paths cannot contain these characters:
1259 /// '/', '*', '?', '"', '<', '>', '|'1251 /// '/', '*', '?', '"', '<', '>', '|'
1260 BadPathName,1252 BadPathName,
1261 NotCapable,
1262 } || os.UnexpectedError;1253 } || os.UnexpectedError;
12631254
1264 /// Whether `full_path` describes a symlink, file, or directory, this function1255 /// Whether `full_path` describes a symlink, file, or directory, this function
...@@ -1272,7 +1263,6 @@ pub const Dir = struct {...@@ -1272,7 +1263,6 @@ pub const Dir = struct {
1272 if (self.deleteFile(sub_path)) {1263 if (self.deleteFile(sub_path)) {
1273 return;1264 return;
1274 } else |err| switch (err) {1265 } else |err| switch (err) {
1275 error.DirNotEmpty => unreachable,
1276 error.FileNotFound => return,1266 error.FileNotFound => return,
1277 error.IsDir => {},1267 error.IsDir => {},
1278 error.AccessDenied => got_access_denied = true,1268 error.AccessDenied => got_access_denied = true,
...@@ -1287,7 +1277,6 @@ pub const Dir = struct {...@@ -1287,7 +1277,6 @@ pub const Dir = struct {
1287 error.FileBusy,1277 error.FileBusy,
1288 error.BadPathName,1278 error.BadPathName,
1289 error.Unexpected,1279 error.Unexpected,
1290 error.NotCapable,
1291 => |e| return e,1280 => |e| return e,
1292 }1281 }
1293 var dir = self.openDir(sub_path, .{ .iterate = true }) catch |err| switch (err) {1282 var dir = self.openDir(sub_path, .{ .iterate = true }) catch |err| switch (err) {
...@@ -1313,7 +1302,6 @@ pub const Dir = struct {...@@ -1313,7 +1302,6 @@ pub const Dir = struct {
1313 error.InvalidUtf8,1302 error.InvalidUtf8,
1314 error.BadPathName,1303 error.BadPathName,
1315 error.DeviceBusy,1304 error.DeviceBusy,
1316 error.NotCapable,
1317 => |e| return e,1305 => |e| return e,
1318 };1306 };
1319 var cleanup_dir_parent: ?Dir = null;1307 var cleanup_dir_parent: ?Dir = null;
...@@ -1342,7 +1330,6 @@ pub const Dir = struct {...@@ -1342,7 +1330,6 @@ pub const Dir = struct {
13421330
1343 // Impossible because we do not pass any path separators.1331 // Impossible because we do not pass any path separators.
1344 error.NotDir => unreachable,1332 error.NotDir => unreachable,
1345 error.DirNotEmpty => unreachable,
13461333
1347 error.IsDir => {},1334 error.IsDir => {},
1348 error.AccessDenied => got_access_denied = true,1335 error.AccessDenied => got_access_denied = true,
...@@ -1356,7 +1343,6 @@ pub const Dir = struct {...@@ -1356,7 +1343,6 @@ pub const Dir = struct {
1356 error.FileBusy,1343 error.FileBusy,
1357 error.BadPathName,1344 error.BadPathName,
1358 error.Unexpected,1345 error.Unexpected,
1359 error.NotCapable,
1360 => |e| return e,1346 => |e| return e,
1361 }1347 }
13621348
...@@ -1383,7 +1369,6 @@ pub const Dir = struct {...@@ -1383,7 +1369,6 @@ pub const Dir = struct {
1383 error.InvalidUtf8,1369 error.InvalidUtf8,
1384 error.BadPathName,1370 error.BadPathName,
1385 error.DeviceBusy,1371 error.DeviceBusy,
1386 error.NotCapable,
1387 => |e| return e,1372 => |e| return e,
1388 };1373 };
1389 if (cleanup_dir_parent) |*d| d.close();1374 if (cleanup_dir_parent) |*d| d.close();
lib/std/os.zig+64-87
...@@ -301,9 +301,9 @@ pub const ReadError = error{...@@ -301,9 +301,9 @@ pub const ReadError = error{
301 /// and reading from the file descriptor would block.301 /// and reading from the file descriptor would block.
302 WouldBlock,302 WouldBlock,
303303
304 /// WASI-only. This error occurs when the file descriptor does304 /// In WASI, this error occurs when the file descriptor does
305 /// not hold the required rights to read from it.305 /// not hold the required rights to read from it.
306 NotCapable,306 AccessDenied,
307} || UnexpectedError;307} || UnexpectedError;
308308
309/// Returns the number of bytes that were read, which can be less than309/// Returns the number of bytes that were read, which can be less than
...@@ -339,7 +339,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {...@@ -339,7 +339,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
339 wasi.ENOMEM => return error.SystemResources,339 wasi.ENOMEM => return error.SystemResources,
340 wasi.ECONNRESET => return error.ConnectionResetByPeer,340 wasi.ECONNRESET => return error.ConnectionResetByPeer,
341 wasi.ETIMEDOUT => return error.ConnectionTimedOut,341 wasi.ETIMEDOUT => return error.ConnectionTimedOut,
342 wasi.ENOTCAPABLE => return error.NotCapable,342 wasi.ENOTCAPABLE => return error.AccessDenied,
343 else => |err| return unexpectedErrno(err),343 else => |err| return unexpectedErrno(err),
344 }344 }
345 }345 }
...@@ -407,7 +407,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {...@@ -407,7 +407,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
407 wasi.EISDIR => return error.IsDir,407 wasi.EISDIR => return error.IsDir,
408 wasi.ENOBUFS => return error.SystemResources,408 wasi.ENOBUFS => return error.SystemResources,
409 wasi.ENOMEM => return error.SystemResources,409 wasi.ENOMEM => return error.SystemResources,
410 wasi.ENOTCAPABLE => return error.NotCapable,410 wasi.ENOTCAPABLE => return error.AccessDenied,
411 else => |err| return unexpectedErrno(err),411 else => |err| return unexpectedErrno(err),
412 }412 }
413 }413 }
...@@ -472,7 +472,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {...@@ -472,7 +472,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
472 wasi.ENXIO => return error.Unseekable,472 wasi.ENXIO => return error.Unseekable,
473 wasi.ESPIPE => return error.Unseekable,473 wasi.ESPIPE => return error.Unseekable,
474 wasi.EOVERFLOW => return error.Unseekable,474 wasi.EOVERFLOW => return error.Unseekable,
475 wasi.ENOTCAPABLE => return error.NotCapable,475 wasi.ENOTCAPABLE => return error.AccessDenied,
476 else => |err| return unexpectedErrno(err),476 else => |err| return unexpectedErrno(err),
477 }477 }
478 }478 }
...@@ -507,12 +507,11 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {...@@ -507,12 +507,11 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
507pub const TruncateError = error{507pub const TruncateError = error{
508 FileTooBig,508 FileTooBig,
509 InputOutput,509 InputOutput,
510 CannotTruncate,
511 FileBusy,510 FileBusy,
512511
513 /// WASI-only. This error occurs when the file descriptor does512 /// In WASI, this error occurs when the file descriptor does
514 /// not hold the required rights to call `ftruncate` on it.513 /// not hold the required rights to call `ftruncate` on it.
515 NotCapable,514 AccessDenied,
516} || UnexpectedError;515} || UnexpectedError;
517516
518pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {517pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
...@@ -533,7 +532,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {...@@ -533,7 +532,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
533 switch (rc) {532 switch (rc) {
534 .SUCCESS => return,533 .SUCCESS => return,
535 .INVALID_HANDLE => unreachable, // Handle not open for writing534 .INVALID_HANDLE => unreachable, // Handle not open for writing
536 .ACCESS_DENIED => return error.CannotTruncate,535 .ACCESS_DENIED => return error.AccessDenied,
537 else => return windows.unexpectedStatus(rc),536 else => return windows.unexpectedStatus(rc),
538 }537 }
539 }538 }
...@@ -543,11 +542,11 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {...@@ -543,11 +542,11 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
543 wasi.EINTR => unreachable,542 wasi.EINTR => unreachable,
544 wasi.EFBIG => return error.FileTooBig,543 wasi.EFBIG => return error.FileTooBig,
545 wasi.EIO => return error.InputOutput,544 wasi.EIO => return error.InputOutput,
546 wasi.EPERM => return error.CannotTruncate,545 wasi.EPERM => return error.AccessDenied,
547 wasi.ETXTBSY => return error.FileBusy,546 wasi.ETXTBSY => return error.FileBusy,
548 wasi.EBADF => unreachable, // Handle not open for writing547 wasi.EBADF => unreachable, // Handle not open for writing
549 wasi.EINVAL => unreachable, // Handle not open for writing548 wasi.EINVAL => unreachable, // Handle not open for writing
550 wasi.ENOTCAPABLE => return error.NotCapable,549 wasi.ENOTCAPABLE => return error.AccessDenied,
551 else => |err| return unexpectedErrno(err),550 else => |err| return unexpectedErrno(err),
552 }551 }
553 }552 }
...@@ -566,7 +565,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {...@@ -566,7 +565,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
566 EINTR => continue,565 EINTR => continue,
567 EFBIG => return error.FileTooBig,566 EFBIG => return error.FileTooBig,
568 EIO => return error.InputOutput,567 EIO => return error.InputOutput,
569 EPERM => return error.CannotTruncate,568 EPERM => return error.AccessDenied,
570 ETXTBSY => return error.FileBusy,569 ETXTBSY => return error.FileBusy,
571 EBADF => unreachable, // Handle not open for writing570 EBADF => unreachable, // Handle not open for writing
572 EINVAL => unreachable, // Handle not open for writing571 EINVAL => unreachable, // Handle not open for writing
...@@ -616,7 +615,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {...@@ -616,7 +615,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
616 wasi.ENXIO => return error.Unseekable,615 wasi.ENXIO => return error.Unseekable,
617 wasi.ESPIPE => return error.Unseekable,616 wasi.ESPIPE => return error.Unseekable,
618 wasi.EOVERFLOW => return error.Unseekable,617 wasi.EOVERFLOW => return error.Unseekable,
619 wasi.ENOTCAPABLE => return error.NotCapable,618 wasi.ENOTCAPABLE => return error.AccessDenied,
620 else => |err| return unexpectedErrno(err),619 else => |err| return unexpectedErrno(err),
621 }620 }
622 }621 }
...@@ -654,6 +653,9 @@ pub const WriteError = error{...@@ -654,6 +653,9 @@ pub const WriteError = error{
654 FileTooBig,653 FileTooBig,
655 InputOutput,654 InputOutput,
656 NoSpaceLeft,655 NoSpaceLeft,
656
657 /// In WASI, this error may occur when the file descriptor does
658 /// not hold the required rights to write to it.
657 AccessDenied,659 AccessDenied,
658 BrokenPipe,660 BrokenPipe,
659 SystemResources,661 SystemResources,
...@@ -662,10 +664,6 @@ pub const WriteError = error{...@@ -662,10 +664,6 @@ pub const WriteError = error{
662 /// This error occurs when no global event loop is configured,664 /// This error occurs when no global event loop is configured,
663 /// and reading from the file descriptor would block.665 /// and reading from the file descriptor would block.
664 WouldBlock,666 WouldBlock,
665
666 /// WASI-only. This error occurs when the file descriptor does
667 /// not hold the required rights to write to it.
668 NotCapable,
669} || UnexpectedError;667} || UnexpectedError;
670668
671/// Write to a file descriptor.669/// Write to a file descriptor.
...@@ -714,7 +712,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {...@@ -714,7 +712,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
714 wasi.ENOSPC => return error.NoSpaceLeft,712 wasi.ENOSPC => return error.NoSpaceLeft,
715 wasi.EPERM => return error.AccessDenied,713 wasi.EPERM => return error.AccessDenied,
716 wasi.EPIPE => return error.BrokenPipe,714 wasi.EPIPE => return error.BrokenPipe,
717 wasi.ENOTCAPABLE => return error.NotCapable,715 wasi.ENOTCAPABLE => return error.AccessDenied,
718 else => |err| return unexpectedErrno(err),716 else => |err| return unexpectedErrno(err),
719 }717 }
720 }718 }
...@@ -792,7 +790,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {...@@ -792,7 +790,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
792 wasi.ENOSPC => return error.NoSpaceLeft,790 wasi.ENOSPC => return error.NoSpaceLeft,
793 wasi.EPERM => return error.AccessDenied,791 wasi.EPERM => return error.AccessDenied,
794 wasi.EPIPE => return error.BrokenPipe,792 wasi.EPIPE => return error.BrokenPipe,
795 wasi.ENOTCAPABLE => return error.NotCapable,793 wasi.ENOTCAPABLE => return error.AccessDenied,
796 else => |err| return unexpectedErrno(err),794 else => |err| return unexpectedErrno(err),
797 }795 }
798 }796 }
...@@ -875,7 +873,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {...@@ -875,7 +873,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
875 wasi.ENXIO => return error.Unseekable,873 wasi.ENXIO => return error.Unseekable,
876 wasi.ESPIPE => return error.Unseekable,874 wasi.ESPIPE => return error.Unseekable,
877 wasi.EOVERFLOW => return error.Unseekable,875 wasi.EOVERFLOW => return error.Unseekable,
878 wasi.ENOTCAPABLE => return error.NotCapable,876 wasi.ENOTCAPABLE => return error.AccessDenied,
879 else => |err| return unexpectedErrno(err),877 else => |err| return unexpectedErrno(err),
880 }878 }
881 }879 }
...@@ -969,7 +967,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz...@@ -969,7 +967,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
969 wasi.ENXIO => return error.Unseekable,967 wasi.ENXIO => return error.Unseekable,
970 wasi.ESPIPE => return error.Unseekable,968 wasi.ESPIPE => return error.Unseekable,
971 wasi.EOVERFLOW => return error.Unseekable,969 wasi.EOVERFLOW => return error.Unseekable,
972 wasi.ENOTCAPABLE => return error.NotCapable,970 wasi.ENOTCAPABLE => return error.AccessDenied,
973 else => |err| return unexpectedErrno(err),971 else => |err| return unexpectedErrno(err),
974 }972 }
975 }973 }
...@@ -1005,6 +1003,8 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz...@@ -1005,6 +1003,8 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
1005}1003}
10061004
1007pub const OpenError = error{1005pub const OpenError = error{
1006 /// In WASI, this error may occur when the file descriptor does
1007 /// not hold the required rights to open a new resource relative to it.
1008 AccessDenied,1008 AccessDenied,
1009 SymLinkLoop,1009 SymLinkLoop,
1010 ProcessFdQuotaExceeded,1010 ProcessFdQuotaExceeded,
...@@ -1041,10 +1041,6 @@ pub const OpenError = error{...@@ -1041,10 +1041,6 @@ pub const OpenError = error{
10411041
1042 /// The underlying filesystem does not support file locks1042 /// The underlying filesystem does not support file locks
1043 FileLocksNotSupported,1043 FileLocksNotSupported,
1044
1045 /// WASI-only. This error occurs when the file descriptor does
1046 /// not hold the required rights to open a new resource relative to it.
1047 NotCapable,
1048} || UnexpectedError;1044} || UnexpectedError;
10491045
1050/// Open and possibly create a file. Keeps trying if it gets interrupted.1046/// Open and possibly create a file. Keeps trying if it gets interrupted.
...@@ -1138,7 +1134,7 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, oflags: oflags_t, fdflags...@@ -1138,7 +1134,7 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, oflags: oflags_t, fdflags
1138 wasi.EPERM => return error.AccessDenied,1134 wasi.EPERM => return error.AccessDenied,
1139 wasi.EEXIST => return error.PathAlreadyExists,1135 wasi.EEXIST => return error.PathAlreadyExists,
1140 wasi.EBUSY => return error.DeviceBusy,1136 wasi.EBUSY => return error.DeviceBusy,
1141 wasi.ENOTCAPABLE => return error.NotCapable,1137 wasi.ENOTCAPABLE => return error.AccessDenied,
1142 else => |err| return unexpectedErrno(err),1138 else => |err| return unexpectedErrno(err),
1143 }1139 }
1144 }1140 }
...@@ -1525,6 +1521,8 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {...@@ -1525,6 +1521,8 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
1525}1521}
15261522
1527pub const SymLinkError = error{1523pub const SymLinkError = error{
1524 /// In WASI, this error may occur when the file descriptor does
1525 /// not hold the required rights to create a new symbolic link relative to it.
1528 AccessDenied,1526 AccessDenied,
1529 DiskQuota,1527 DiskQuota,
1530 PathAlreadyExists,1528 PathAlreadyExists,
...@@ -1589,19 +1587,13 @@ pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin...@@ -1589,19 +1587,13 @@ pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin
1589 }1587 }
1590}1588}
15911589
1592pub const SymLinkAtError = error{
1593 /// WASI-only. This error occurs when the file descriptor does
1594 /// not hold the required rights to create a new symbolic link relative to it.
1595 NotCapable,
1596} || SymLinkError;
1597
1598/// Similar to `symlink`, however, creates a symbolic link named `sym_link_path` which contains the string1590/// Similar to `symlink`, however, creates a symbolic link named `sym_link_path` which contains the string
1599/// `target_path` **relative** to `newdirfd` directory handle.1591/// `target_path` **relative** to `newdirfd` directory handle.
1600/// A symbolic link (also known as a soft link) may point to an existing file or to a nonexistent1592/// A symbolic link (also known as a soft link) may point to an existing file or to a nonexistent
1601/// one; the latter case is known as a dangling link.1593/// one; the latter case is known as a dangling link.
1602/// If `sym_link_path` exists, it will not be overwritten.1594/// If `sym_link_path` exists, it will not be overwritten.
1603/// See also `symlinkatWasi`, `symlinkatZ` and `symlinkatW`.1595/// See also `symlinkatWasi`, `symlinkatZ` and `symlinkatW`.
1604pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkAtError!void {1596pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {
1605 if (builtin.os.tag == .wasi) {1597 if (builtin.os.tag == .wasi) {
1606 return symlinkatWasi(target_path, newdirfd, sym_link_path);1598 return symlinkatWasi(target_path, newdirfd, sym_link_path);
1607 }1599 }
...@@ -1619,7 +1611,7 @@ pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ");...@@ -1619,7 +1611,7 @@ pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ");
16191611
1620/// WASI-only. The same as `symlinkat` but targeting WASI.1612/// WASI-only. The same as `symlinkat` but targeting WASI.
1621/// See also `symlinkat`.1613/// See also `symlinkat`.
1622pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkAtError!void {1614pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {
1623 switch (wasi.path_symlink(target_path.ptr, target_path.len, newdirfd, sym_link_path.ptr, sym_link_path.len)) {1615 switch (wasi.path_symlink(target_path.ptr, target_path.len, newdirfd, sym_link_path.ptr, sym_link_path.len)) {
1624 wasi.ESUCCESS => {},1616 wasi.ESUCCESS => {},
1625 wasi.EFAULT => unreachable,1617 wasi.EFAULT => unreachable,
...@@ -1636,20 +1628,20 @@ pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []c...@@ -1636,20 +1628,20 @@ pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []c
1636 wasi.ENOMEM => return error.SystemResources,1628 wasi.ENOMEM => return error.SystemResources,
1637 wasi.ENOSPC => return error.NoSpaceLeft,1629 wasi.ENOSPC => return error.NoSpaceLeft,
1638 wasi.EROFS => return error.ReadOnlyFileSystem,1630 wasi.EROFS => return error.ReadOnlyFileSystem,
1639 wasi.ENOTCAPABLE => return error.NotCapable,1631 wasi.ENOTCAPABLE => return error.AccessDenied,
1640 else => |err| return unexpectedErrno(err),1632 else => |err| return unexpectedErrno(err),
1641 }1633 }
1642}1634}
16431635
1644/// Windows-only. The same as `symlinkat` except the paths are null-terminated, WTF-16 encoded.1636/// Windows-only. The same as `symlinkat` except the paths are null-terminated, WTF-16 encoded.
1645/// See also `symlinkat`.1637/// See also `symlinkat`.
1646pub fn symlinkatW(target_path: [*:0]const u16, newdirfd: fd_t, sym_link_path: [*:0]const u16) SymLinkAtError!void {1638pub fn symlinkatW(target_path: [*:0]const u16, newdirfd: fd_t, sym_link_path: [*:0]const u16) SymLinkError!void {
1647 @compileError("TODO implement on Windows");1639 @compileError("TODO implement on Windows");
1648}1640}
16491641
1650/// The same as `symlinkat` except the parameters are null-terminated pointers.1642/// The same as `symlinkat` except the parameters are null-terminated pointers.
1651/// See also `symlinkat`.1643/// See also `symlinkat`.
1652pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkAtError!void {1644pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkError!void {
1653 if (builtin.os.tag == .windows) {1645 if (builtin.os.tag == .windows) {
1654 const target_path_w = try windows.cStrToPrefixedFileW(target_path);1646 const target_path_w = try windows.cStrToPrefixedFileW(target_path);
1655 const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path);1647 const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path);
...@@ -1677,6 +1669,9 @@ pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:...@@ -1677,6 +1669,9 @@ pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:
16771669
1678pub const UnlinkError = error{1670pub const UnlinkError = error{
1679 FileNotFound,1671 FileNotFound,
1672
1673 /// In WASI, this error may occur when the file descriptor does
1674 /// not hold the required rights to unlink a resource by path relative to it.
1680 AccessDenied,1675 AccessDenied,
1681 FileBusy,1676 FileBusy,
1682 FileSystem,1677 FileSystem,
...@@ -1739,10 +1734,6 @@ pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {...@@ -1739,10 +1734,6 @@ pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {
1739pub const UnlinkatError = UnlinkError || error{1734pub const UnlinkatError = UnlinkError || error{
1740 /// When passing `AT_REMOVEDIR`, this error occurs when the named directory is not empty.1735 /// When passing `AT_REMOVEDIR`, this error occurs when the named directory is not empty.
1741 DirNotEmpty,1736 DirNotEmpty,
1742
1743 /// WASI-only. This error occurs when the file descriptor does
1744 /// not hold the required rights to unlink a resource by path relative to it.
1745 NotCapable,
1746};1737};
17471738
1748/// Delete a file name and possibly the file it refers to, based on an open directory handle.1739/// Delete a file name and possibly the file it refers to, based on an open directory handle.
...@@ -1784,7 +1775,7 @@ pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatErro...@@ -1784,7 +1775,7 @@ pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatErro
1784 wasi.ENOMEM => return error.SystemResources,1775 wasi.ENOMEM => return error.SystemResources,
1785 wasi.EROFS => return error.ReadOnlyFileSystem,1776 wasi.EROFS => return error.ReadOnlyFileSystem,
1786 wasi.ENOTEMPTY => return error.DirNotEmpty,1777 wasi.ENOTEMPTY => return error.DirNotEmpty,
1787 wasi.ENOTCAPABLE => return error.NotCapable,1778 wasi.ENOTCAPABLE => return error.AccessDenied,
17881779
1789 wasi.EINVAL => unreachable, // invalid flags, or pathname has . as last component1780 wasi.EINVAL => unreachable, // invalid flags, or pathname has . as last component
1790 wasi.EBADF => unreachable, // always a race condition1781 wasi.EBADF => unreachable, // always a race condition
...@@ -1887,6 +1878,8 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*:0]const u16, flags: u32) UnlinkatEr...@@ -1887,6 +1878,8 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*:0]const u16, flags: u32) UnlinkatEr
1887}1878}
18881879
1889const RenameError = error{1880const RenameError = error{
1881 /// In WASI, this error may occur when the file descriptor does
1882 /// not hold the required rights to rename a resource by path relative to it.
1890 AccessDenied,1883 AccessDenied,
1891 FileBusy,1884 FileBusy,
1892 DiskQuota,1885 DiskQuota,
...@@ -1963,19 +1956,13 @@ pub fn renameW(old_path: [*:0]const u16, new_path: [*:0]const u16) RenameError!v...@@ -1963,19 +1956,13 @@ pub fn renameW(old_path: [*:0]const u16, new_path: [*:0]const u16) RenameError!v
1963 return windows.MoveFileExW(old_path, new_path, flags);1956 return windows.MoveFileExW(old_path, new_path, flags);
1964}1957}
19651958
1966pub const RenameatError = error{
1967 /// WASI-only. This error occurs when the file descriptor does
1968 /// not hold the required rights to rename a resource by path relative to it.
1969 NotCapable,
1970} || RenameError;
1971
1972/// Change the name or location of a file based on an open directory handle.1959/// Change the name or location of a file based on an open directory handle.
1973pub fn renameat(1960pub fn renameat(
1974 old_dir_fd: fd_t,1961 old_dir_fd: fd_t,
1975 old_path: []const u8,1962 old_path: []const u8,
1976 new_dir_fd: fd_t,1963 new_dir_fd: fd_t,
1977 new_path: []const u8,1964 new_path: []const u8,
1978) RenameatError!void {1965) RenameError!void {
1979 if (builtin.os.tag == .windows) {1966 if (builtin.os.tag == .windows) {
1980 const old_path_w = try windows.sliceToPrefixedFileW(old_path);1967 const old_path_w = try windows.sliceToPrefixedFileW(old_path);
1981 const new_path_w = try windows.sliceToPrefixedFileW(new_path);1968 const new_path_w = try windows.sliceToPrefixedFileW(new_path);
...@@ -1991,7 +1978,7 @@ pub fn renameat(...@@ -1991,7 +1978,7 @@ pub fn renameat(
19911978
1992/// WASI-only. Same as `renameat` expect targeting WASI.1979/// WASI-only. Same as `renameat` expect targeting WASI.
1993/// See also `renameat`.1980/// See also `renameat`.
1994pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameatError!void {1981pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameError!void {
1995 switch (wasi.path_rename(old_dir_fd, old_path.ptr, old_path.len, new_dir_fd, new_path.ptr, new_path.len)) {1982 switch (wasi.path_rename(old_dir_fd, old_path.ptr, old_path.len, new_dir_fd, new_path.ptr, new_path.len)) {
1996 wasi.ESUCCESS => return,1983 wasi.ESUCCESS => return,
1997 wasi.EACCES => return error.AccessDenied,1984 wasi.EACCES => return error.AccessDenied,
...@@ -2012,7 +1999,7 @@ pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, ne...@@ -2012,7 +1999,7 @@ pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, ne
2012 wasi.ENOTEMPTY => return error.PathAlreadyExists,1999 wasi.ENOTEMPTY => return error.PathAlreadyExists,
2013 wasi.EROFS => return error.ReadOnlyFileSystem,2000 wasi.EROFS => return error.ReadOnlyFileSystem,
2014 wasi.EXDEV => return error.RenameAcrossMountPoints,2001 wasi.EXDEV => return error.RenameAcrossMountPoints,
2015 wasi.ENOTCAPABLE => return error.NotCapable,2002 wasi.ENOTCAPABLE => return error.AccessDenied,
2016 else => |err| return unexpectedErrno(err),2003 else => |err| return unexpectedErrno(err),
2017 }2004 }
2018}2005}
...@@ -2023,7 +2010,7 @@ pub fn renameatZ(...@@ -2023,7 +2010,7 @@ pub fn renameatZ(
2023 old_path: [*:0]const u8,2010 old_path: [*:0]const u8,
2024 new_dir_fd: fd_t,2011 new_dir_fd: fd_t,
2025 new_path: [*:0]const u8,2012 new_path: [*:0]const u8,
2026) RenameatError!void {2013) RenameError!void {
2027 if (builtin.os.tag == .windows) {2014 if (builtin.os.tag == .windows) {
2028 const old_path_w = try windows.cStrToPrefixedFileW(old_path);2015 const old_path_w = try windows.cStrToPrefixedFileW(old_path);
2029 const new_path_w = try windows.cStrToPrefixedFileW(new_path);2016 const new_path_w = try windows.cStrToPrefixedFileW(new_path);
...@@ -2062,7 +2049,7 @@ pub fn renameatW(...@@ -2062,7 +2049,7 @@ pub fn renameatW(
2062 new_dir_fd: fd_t,2049 new_dir_fd: fd_t,
2063 new_path_w: []const u16,2050 new_path_w: []const u16,
2064 ReplaceIfExists: windows.BOOLEAN,2051 ReplaceIfExists: windows.BOOLEAN,
2065) RenameatError!void {2052) RenameError!void {
2066 const src_fd = windows.OpenFile(old_path_w, .{2053 const src_fd = windows.OpenFile(old_path_w, .{
2067 .dir = old_dir_fd,2054 .dir = old_dir_fd,
2068 .access_mask = windows.SYNCHRONIZE | windows.GENERIC_WRITE | windows.DELETE,2055 .access_mask = windows.SYNCHRONIZE | windows.GENERIC_WRITE | windows.DELETE,
...@@ -2111,13 +2098,7 @@ pub fn renameatW(...@@ -2111,13 +2098,7 @@ pub fn renameatW(
2111 }2098 }
2112}2099}
21132100
2114pub const MakeDirAtError = error{2101pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
2115 /// WASI-only. This error occurs when the file descriptor does
2116 /// not hold the required rights to create a new directory relative to it.
2117 NotCapable,
2118} || MakeDirError;
2119
2120pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtError!void {
2121 if (builtin.os.tag == .windows) {2102 if (builtin.os.tag == .windows) {
2122 const sub_dir_path_w = try windows.sliceToPrefixedFileW(sub_dir_path);2103 const sub_dir_path_w = try windows.sliceToPrefixedFileW(sub_dir_path);
2123 return mkdiratW(dir_fd, sub_dir_path_w.span().ptr, mode);2104 return mkdiratW(dir_fd, sub_dir_path_w.span().ptr, mode);
...@@ -2131,7 +2112,7 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtError...@@ -2131,7 +2112,7 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtError
21312112
2132pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");2113pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");
21332114
2134pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtError!void {2115pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
2135 switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {2116 switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {
2136 wasi.ESUCCESS => return,2117 wasi.ESUCCESS => return,
2137 wasi.EACCES => return error.AccessDenied,2118 wasi.EACCES => return error.AccessDenied,
...@@ -2148,12 +2129,12 @@ pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtE...@@ -2148,12 +2129,12 @@ pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtE
2148 wasi.ENOSPC => return error.NoSpaceLeft,2129 wasi.ENOSPC => return error.NoSpaceLeft,
2149 wasi.ENOTDIR => return error.NotDir,2130 wasi.ENOTDIR => return error.NotDir,
2150 wasi.EROFS => return error.ReadOnlyFileSystem,2131 wasi.EROFS => return error.ReadOnlyFileSystem,
2151 wasi.ENOTCAPABLE => return error.NotCapable,2132 wasi.ENOTCAPABLE => return error.AccessDenied,
2152 else => |err| return unexpectedErrno(err),2133 else => |err| return unexpectedErrno(err),
2153 }2134 }
2154}2135}
21552136
2156pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirAtError!void {2137pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
2157 if (builtin.os.tag == .windows) {2138 if (builtin.os.tag == .windows) {
2158 const sub_dir_path_w = try windows.cStrToPrefixedFileW(sub_dir_path);2139 const sub_dir_path_w = try windows.cStrToPrefixedFileW(sub_dir_path);
2159 return mkdiratW(dir_fd, sub_dir_path_w.span().ptr, mode);2140 return mkdiratW(dir_fd, sub_dir_path_w.span().ptr, mode);
...@@ -2178,12 +2159,14 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirAtE...@@ -2178,12 +2159,14 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirAtE
2178 }2159 }
2179}2160}
21802161
2181pub fn mkdiratW(dir_fd: fd_t, sub_path_w: [*:0]const u16, mode: u32) MakeDirAtError!void {2162pub fn mkdiratW(dir_fd: fd_t, sub_path_w: [*:0]const u16, mode: u32) MakeDirError!void {
2182 const sub_dir_handle = try windows.CreateDirectoryW(dir_fd, sub_path_w, null);2163 const sub_dir_handle = try windows.CreateDirectoryW(dir_fd, sub_path_w, null);
2183 windows.CloseHandle(sub_dir_handle);2164 windows.CloseHandle(sub_dir_handle);
2184}2165}
21852166
2186pub const MakeDirError = error{2167pub const MakeDirError = error{
2168 /// In WASI, this error may occur when the file descriptor does
2169 /// not hold the required rights to create a new directory relative to it.
2187 AccessDenied,2170 AccessDenied,
2188 DiskQuota,2171 DiskQuota,
2189 PathAlreadyExists,2172 PathAlreadyExists,
...@@ -2363,6 +2346,8 @@ pub fn fchdir(dirfd: fd_t) FchdirError!void {...@@ -2363,6 +2346,8 @@ pub fn fchdir(dirfd: fd_t) FchdirError!void {
2363}2346}
23642347
2365pub const ReadLinkError = error{2348pub const ReadLinkError = error{
2349 /// In WASI, this error may occur when the file descriptor does
2350 /// not hold the required rights to read value of a symbolic link relative to it.
2366 AccessDenied,2351 AccessDenied,
2367 FileSystem,2352 FileSystem,
2368 SymLinkLoop,2353 SymLinkLoop,
...@@ -2416,16 +2401,10 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8...@@ -2416,16 +2401,10 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8
2416 }2401 }
2417}2402}
24182403
2419pub const ReadLinkAtError = error{
2420 /// WASI-only. This error occurs when the file descriptor does
2421 /// not hold the required rights to read value of a symbolic link relative to it.
2422 NotCapable,
2423} || ReadLinkError;
2424
2425/// Similar to `readlink` except reads value of a symbolink link **relative** to `dirfd` directory handle.2404/// Similar to `readlink` except reads value of a symbolink link **relative** to `dirfd` directory handle.
2426/// The return value is a slice of `out_buffer` from index 0.2405/// The return value is a slice of `out_buffer` from index 0.
2427/// See also `readlinkatWasi`, `realinkatZ` and `realinkatW`.2406/// See also `readlinkatWasi`, `realinkatZ` and `realinkatW`.
2428pub fn readlinkat(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkAtError![]u8 {2407pub fn readlinkat(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
2429 if (builtin.os.tag == .wasi) {2408 if (builtin.os.tag == .wasi) {
2430 return readlinkatWasi(dirfd, file_path, out_buffer);2409 return readlinkatWasi(dirfd, file_path, out_buffer);
2431 }2410 }
...@@ -2441,7 +2420,7 @@ pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ");...@@ -2441,7 +2420,7 @@ pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ");
24412420
2442/// WASI-only. Same as `readlinkat` but targets WASI.2421/// WASI-only. Same as `readlinkat` but targets WASI.
2443/// See also `readlinkat`.2422/// See also `readlinkat`.
2444pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkAtError![]u8 {2423pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
2445 var bufused: usize = undefined;2424 var bufused: usize = undefined;
2446 switch (wasi.path_readlink(dirfd, file_path.ptr, file_path.len, out_buffer.ptr, out_buffer.len, &bufused)) {2425 switch (wasi.path_readlink(dirfd, file_path.ptr, file_path.len, out_buffer.ptr, out_buffer.len, &bufused)) {
2447 wasi.ESUCCESS => return out_buffer[0..bufused],2426 wasi.ESUCCESS => return out_buffer[0..bufused],
...@@ -2454,20 +2433,20 @@ pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) Read...@@ -2454,20 +2433,20 @@ pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) Read
2454 wasi.ENOENT => return error.FileNotFound,2433 wasi.ENOENT => return error.FileNotFound,
2455 wasi.ENOMEM => return error.SystemResources,2434 wasi.ENOMEM => return error.SystemResources,
2456 wasi.ENOTDIR => return error.NotDir,2435 wasi.ENOTDIR => return error.NotDir,
2457 wasi.ENOTCAPABLE => return error.NotCapable,2436 wasi.ENOTCAPABLE => return error.AccessDenied,
2458 else => |err| return unexpectedErrno(err),2437 else => |err| return unexpectedErrno(err),
2459 }2438 }
2460}2439}
24612440
2462/// Windows-only. Same as `readlinkat` except `file_path` is null-terminated, WTF16 encoded.2441/// Windows-only. Same as `readlinkat` except `file_path` is null-terminated, WTF16 encoded.
2463/// See also `readlinkat`.2442/// See also `readlinkat`.
2464pub fn readlinkatW(dirfd: fd_t, file_path: [*:0]const u16, out_buffer: []u8) ReadLinkAtError![]u8 {2443pub fn readlinkatW(dirfd: fd_t, file_path: [*:0]const u16, out_buffer: []u8) ReadLinkError![]u8 {
2465 @compileError("TODO implement on Windows");2444 @compileError("TODO implement on Windows");
2466}2445}
24672446
2468/// Same as `readlinkat` except `file_path` is null-terminated.2447/// Same as `readlinkat` except `file_path` is null-terminated.
2469/// See also `readlinkat`.2448/// See also `readlinkat`.
2470pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkAtError![]u8 {2449pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 {
2471 if (builtin.os.tag == .windows) {2450 if (builtin.os.tag == .windows) {
2472 const file_path_w = try windows.cStrToPrefixedFileW(file_path);2451 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
2473 return readlinkatW(dirfd, file_path_w.span().ptr, out_buffer);2452 return readlinkatW(dirfd, file_path_w.span().ptr, out_buffer);
...@@ -3132,11 +3111,10 @@ pub fn waitpid(pid: i32, flags: u32) u32 {...@@ -3132,11 +3111,10 @@ pub fn waitpid(pid: i32, flags: u32) u32 {
31323111
3133pub const FStatError = error{3112pub const FStatError = error{
3134 SystemResources,3113 SystemResources,
3135 AccessDenied,
31363114
3137 /// WASI-only. This error occurs when the file descriptor does3115 /// In WASI, this error may occur when the file descriptor does
3138 /// not hold the required rights to get its filestat information.3116 /// not hold the required rights to get its filestat information.
3139 NotCapable,3117 AccessDenied,
3140} || UnexpectedError;3118} || UnexpectedError;
31413119
3142/// Return information about a file descriptor.3120/// Return information about a file descriptor.
...@@ -3149,7 +3127,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {...@@ -3149,7 +3127,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
3149 wasi.EBADF => unreachable, // Always a race condition.3127 wasi.EBADF => unreachable, // Always a race condition.
3150 wasi.ENOMEM => return error.SystemResources,3128 wasi.ENOMEM => return error.SystemResources,
3151 wasi.EACCES => return error.AccessDenied,3129 wasi.EACCES => return error.AccessDenied,
3152 wasi.ENOTCAPABLE => return error.NotCapable,3130 wasi.ENOTCAPABLE => return error.AccessDenied,
3153 else => |err| return unexpectedErrno(err),3131 else => |err| return unexpectedErrno(err),
3154 }3132 }
3155 }3133 }
...@@ -3200,7 +3178,7 @@ pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!S...@@ -3200,7 +3178,7 @@ pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!S
3200 wasi.ENAMETOOLONG => return error.NameTooLong,3178 wasi.ENAMETOOLONG => return error.NameTooLong,
3201 wasi.ENOENT => return error.FileNotFound,3179 wasi.ENOENT => return error.FileNotFound,
3202 wasi.ENOTDIR => return error.FileNotFound,3180 wasi.ENOTDIR => return error.FileNotFound,
3203 wasi.ENOTCAPABLE => return error.NotCapable,3181 wasi.ENOTCAPABLE => return error.AccessDenied,
3204 else => |err| return unexpectedErrno(err),3182 else => |err| return unexpectedErrno(err),
3205 }3183 }
3206}3184}
...@@ -3709,9 +3687,9 @@ pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {...@@ -3709,9 +3687,9 @@ pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {
3709pub const SeekError = error{3687pub const SeekError = error{
3710 Unseekable,3688 Unseekable,
37113689
3712 /// WASI-only. This error occurs when the file descriptor does3690 /// In WASI, this error may occur when the file descriptor does
3713 /// not hold the required rights to seek on it.3691 /// not hold the required rights to seek on it.
3714 NotCapable,3692 AccessDenied,
3715} || UnexpectedError;3693} || UnexpectedError;
37163694
3717/// Repositions read/write file offset relative to the beginning.3695/// Repositions read/write file offset relative to the beginning.
...@@ -3740,7 +3718,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {...@@ -3740,7 +3718,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
3740 wasi.EOVERFLOW => return error.Unseekable,3718 wasi.EOVERFLOW => return error.Unseekable,
3741 wasi.ESPIPE => return error.Unseekable,3719 wasi.ESPIPE => return error.Unseekable,
3742 wasi.ENXIO => return error.Unseekable,3720 wasi.ENXIO => return error.Unseekable,
3743 wasi.ENOTCAPABLE => return error.NotCapable,3721 wasi.ENOTCAPABLE => return error.AccessDenied,
3744 else => |err| return unexpectedErrno(err),3722 else => |err| return unexpectedErrno(err),
3745 }3723 }
3746 }3724 }
...@@ -3782,7 +3760,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {...@@ -3782,7 +3760,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
3782 wasi.EOVERFLOW => return error.Unseekable,3760 wasi.EOVERFLOW => return error.Unseekable,
3783 wasi.ESPIPE => return error.Unseekable,3761 wasi.ESPIPE => return error.Unseekable,
3784 wasi.ENXIO => return error.Unseekable,3762 wasi.ENXIO => return error.Unseekable,
3785 wasi.ENOTCAPABLE => return error.NotCapable,3763 wasi.ENOTCAPABLE => return error.AccessDenied,
3786 else => |err| return unexpectedErrno(err),3764 else => |err| return unexpectedErrno(err),
3787 }3765 }
3788 }3766 }
...@@ -3823,7 +3801,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {...@@ -3823,7 +3801,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
3823 wasi.EOVERFLOW => return error.Unseekable,3801 wasi.EOVERFLOW => return error.Unseekable,
3824 wasi.ESPIPE => return error.Unseekable,3802 wasi.ESPIPE => return error.Unseekable,
3825 wasi.ENXIO => return error.Unseekable,3803 wasi.ENXIO => return error.Unseekable,
3826 wasi.ENOTCAPABLE => return error.NotCapable,3804 wasi.ENOTCAPABLE => return error.AccessDenied,
3827 else => |err| return unexpectedErrno(err),3805 else => |err| return unexpectedErrno(err),
3828 }3806 }
3829 }3807 }
...@@ -3864,7 +3842,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {...@@ -3864,7 +3842,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
3864 wasi.EOVERFLOW => return error.Unseekable,3842 wasi.EOVERFLOW => return error.Unseekable,
3865 wasi.ESPIPE => return error.Unseekable,3843 wasi.ESPIPE => return error.Unseekable,
3866 wasi.ENXIO => return error.Unseekable,3844 wasi.ENXIO => return error.Unseekable,
3867 wasi.ENOTCAPABLE => return error.NotCapable,3845 wasi.ENOTCAPABLE => return error.AccessDenied,
3868 else => |err| return unexpectedErrno(err),3846 else => |err| return unexpectedErrno(err),
3869 }3847 }
3870 }3848 }
...@@ -4012,7 +3990,6 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP...@@ -4012,7 +3990,6 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
4012 if (builtin.os.tag == .linux and !builtin.link_libc) {3990 if (builtin.os.tag == .linux and !builtin.link_libc) {
4013 const fd = openZ(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0) catch |err| switch (err) {3991 const fd = openZ(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0) catch |err| switch (err) {
4014 error.FileLocksNotSupported => unreachable,3992 error.FileLocksNotSupported => unreachable,
4015 error.NotCapable => unreachable, // WASI only
4016 else => |e| return e,3993 else => |e| return e,
4017 };3994 };
4018 defer close(fd);3995 defer close(fd);
lib/std/zig/system.zig+1-4
...@@ -499,7 +499,6 @@ pub const NativeTargetInfo = struct {...@@ -499,7 +499,6 @@ pub const NativeTargetInfo = struct {
499 error.PipeBusy => unreachable,499 error.PipeBusy => unreachable,
500 error.FileLocksNotSupported => unreachable,500 error.FileLocksNotSupported => unreachable,
501 error.WouldBlock => unreachable,501 error.WouldBlock => unreachable,
502 error.NotCapable => unreachable, // we don't support WASI here (not yet at least)
503502
504 error.IsDir,503 error.IsDir,
505 error.NotDir,504 error.NotDir,
...@@ -791,7 +790,6 @@ pub const NativeTargetInfo = struct {...@@ -791,7 +790,6 @@ pub const NativeTargetInfo = struct {
791 var it = mem.tokenize(rpath_list, ":");790 var it = mem.tokenize(rpath_list, ":");
792 while (it.next()) |rpath| {791 while (it.next()) |rpath| {
793 var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) {792 var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) {
794 error.NotCapable => unreachable, // we don't support WASI here (not yet at least)
795 error.NameTooLong => unreachable,793 error.NameTooLong => unreachable,
796 error.InvalidUtf8 => unreachable,794 error.InvalidUtf8 => unreachable,
797 error.BadPathName => unreachable,795 error.BadPathName => unreachable,
...@@ -819,7 +817,6 @@ pub const NativeTargetInfo = struct {...@@ -819,7 +817,6 @@ pub const NativeTargetInfo = struct {
819 &link_buf,817 &link_buf,
820 ) catch |err| switch (err) {818 ) catch |err| switch (err) {
821 error.NameTooLong => unreachable,819 error.NameTooLong => unreachable,
822 error.NotCapable => unreachable, // we don't support WASI here (not yet at least)
823820
824 error.AccessDenied,821 error.AccessDenied,
825 error.FileNotFound,822 error.FileNotFound,
...@@ -854,7 +851,6 @@ pub const NativeTargetInfo = struct {...@@ -854,7 +851,6 @@ pub const NativeTargetInfo = struct {
854 const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {851 const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
855 error.OperationAborted => unreachable, // Windows-only852 error.OperationAborted => unreachable, // Windows-only
856 error.WouldBlock => unreachable, // Did not request blocking mode853 error.WouldBlock => unreachable, // Did not request blocking mode
857 error.NotCapable => unreachable, // WASI only, and we don't support it here yet
858 error.SystemResources => return error.SystemResources,854 error.SystemResources => return error.SystemResources,
859 error.IsDir => return error.UnableToReadElfFile,855 error.IsDir => return error.UnableToReadElfFile,
860 error.BrokenPipe => return error.UnableToReadElfFile,856 error.BrokenPipe => return error.UnableToReadElfFile,
...@@ -863,6 +859,7 @@ pub const NativeTargetInfo = struct {...@@ -863,6 +859,7 @@ pub const NativeTargetInfo = struct {
863 error.ConnectionTimedOut => return error.UnableToReadElfFile,859 error.ConnectionTimedOut => return error.UnableToReadElfFile,
864 error.Unexpected => return error.Unexpected,860 error.Unexpected => return error.Unexpected,
865 error.InputOutput => return error.FileSystem,861 error.InputOutput => return error.FileSystem,
862 error.AccessDenied => return error.Unexpected,
866 };863 };
867 if (len == 0) return error.UnexpectedEndOfFile;864 if (len == 0) return error.UnexpectedEndOfFile;
868 i += len;865 i += len;
src-self-hosted/stage2.zig-3
...@@ -163,7 +163,6 @@ export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error {...@@ -163,7 +163,6 @@ export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error {
163 error.OutOfMemory => return .OutOfMemory,163 error.OutOfMemory => return .OutOfMemory,
164 error.Unexpected => return .Unexpected,164 error.Unexpected => return .Unexpected,
165 error.InputOutput => return .FileSystem,165 error.InputOutput => return .FileSystem,
166 error.NotCapable => unreachable, // we should handle this when we're able to cross-compile Zig to WASI
167 };166 };
168 return .None;167 return .None;
169}168}
...@@ -607,7 +606,6 @@ export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [...@@ -607,7 +606,6 @@ export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [
607 error.NotDir => return .NotDir,606 error.NotDir => return .NotDir,
608 error.DeviceBusy => return .DeviceBusy,607 error.DeviceBusy => return .DeviceBusy,
609 error.FileLocksNotSupported => unreachable,608 error.FileLocksNotSupported => unreachable,
610 error.NotCapable => unreachable, // we should handle this when we're able to cross-compile Zig to WASI
611 };609 };
612 stage1_libc.initFromStage2(libc);610 stage1_libc.initFromStage2(libc);
613 return .None;611 return .None;
...@@ -651,7 +649,6 @@ export fn stage2_libc_render(stage1_libc: *Stage2LibCInstallation, output_file:...@@ -651,7 +649,6 @@ export fn stage2_libc_render(stage1_libc: *Stage2LibCInstallation, output_file:
651 error.AccessDenied => return .AccessDenied,649 error.AccessDenied => return .AccessDenied,
652 error.Unexpected => return .Unexpected,650 error.Unexpected => return .Unexpected,
653 error.InputOutput => return .FileSystem,651 error.InputOutput => return .FileSystem,
654 error.NotCapable => unreachable, // we should handle this when we're able to cross-compile Zig to WASI
655 };652 };
656 return .None;653 return .None;
657}654}