aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os.zig
diff options
context:
space:
mode:
authorluna <git@l4.pm>2020-07-02 00:49:56 -0300
committerGitHub <noreply@github.com>2020-07-02 00:49:56 -0300
commite2cfc65909d49d1102fa440759f5475ced0c0c15 (patch)
tree64eb34f48fb4066df4e54306f3115a9d341d3fd4 /lib/std/os.zig
parent3f5b2d6c51b983ae66ad20124924378c2291cd67 (diff)
parent6f98ef09e31768e3356598ef30e60fe028a0e70c (diff)
downloadzig-e2cfc65909d49d1102fa440759f5475ced0c0c15.tar.gz
zig-e2cfc65909d49d1102fa440759f5475ced0c0c15.zip
Merge branch 'master' into ebadf-error
Diffstat (limited to 'lib/std/os.zig')
-rw-r--r--lib/std/os.zig99
1 files changed, 76 insertions, 23 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig
index 5677ab5e30..8873535455 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -301,6 +301,10 @@ pub const ReadError = error{
/// This error occurs when no global event loop is configured,
/// and reading from the file descriptor would block.
WouldBlock,
+
+ /// In WASI, this error occurs when the file descriptor does
+ /// not hold the required rights to read from it.
+ AccessDenied,
} || UnexpectedError;
/// Returns the number of bytes that were read, which can be less than
@@ -336,6 +340,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
wasi.ENOMEM => return error.SystemResources,
wasi.ECONNRESET => return error.ConnectionResetByPeer,
wasi.ETIMEDOUT => return error.ConnectionTimedOut,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -403,6 +408,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
wasi.EISDIR => return error.IsDir,
wasi.ENOBUFS => return error.SystemResources,
wasi.ENOMEM => return error.SystemResources,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -467,6 +473,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
wasi.ENXIO => return error.Unseekable,
wasi.ESPIPE => return error.Unseekable,
wasi.EOVERFLOW => return error.Unseekable,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -501,8 +508,11 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
pub const TruncateError = error{
FileTooBig,
InputOutput,
- CannotTruncate,
FileBusy,
+
+ /// In WASI, this error occurs when the file descriptor does
+ /// not hold the required rights to call `ftruncate` on it.
+ AccessDenied,
} || UnexpectedError;
pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
@@ -523,7 +533,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
switch (rc) {
.SUCCESS => return,
.INVALID_HANDLE => unreachable, // Handle not open for writing
- .ACCESS_DENIED => return error.CannotTruncate,
+ .ACCESS_DENIED => return error.AccessDenied,
else => return windows.unexpectedStatus(rc),
}
}
@@ -533,10 +543,11 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
wasi.EINTR => unreachable,
wasi.EFBIG => return error.FileTooBig,
wasi.EIO => return error.InputOutput,
- wasi.EPERM => return error.CannotTruncate,
+ wasi.EPERM => return error.AccessDenied,
wasi.ETXTBSY => return error.FileBusy,
wasi.EBADF => unreachable, // Handle not open for writing
wasi.EINVAL => unreachable, // Handle not open for writing
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -555,7 +566,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
EINTR => continue,
EFBIG => return error.FileTooBig,
EIO => return error.InputOutput,
- EPERM => return error.CannotTruncate,
+ EPERM => return error.AccessDenied,
ETXTBSY => return error.FileBusy,
EBADF => unreachable, // Handle not open for writing
EINVAL => unreachable, // Handle not open for writing
@@ -605,6 +616,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
wasi.ENXIO => return error.Unseekable,
wasi.ESPIPE => return error.Unseekable,
wasi.EOVERFLOW => return error.Unseekable,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -642,6 +654,9 @@ pub const WriteError = error{
FileTooBig,
InputOutput,
NoSpaceLeft,
+
+ /// In WASI, this error may occur when the file descriptor does
+ /// not hold the required rights to write to it.
AccessDenied,
BrokenPipe,
SystemResources,
@@ -699,6 +714,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
wasi.ENOSPC => return error.NoSpaceLeft,
wasi.EPERM => return error.AccessDenied,
wasi.EPIPE => return error.BrokenPipe,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -776,6 +792,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
wasi.ENOSPC => return error.NoSpaceLeft,
wasi.EPERM => return error.AccessDenied,
wasi.EPIPE => return error.BrokenPipe,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -858,6 +875,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
wasi.ENXIO => return error.Unseekable,
wasi.ESPIPE => return error.Unseekable,
wasi.EOVERFLOW => return error.Unseekable,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -951,6 +969,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
wasi.ENXIO => return error.Unseekable,
wasi.ESPIPE => return error.Unseekable,
wasi.EOVERFLOW => return error.Unseekable,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -986,6 +1005,8 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
}
pub const OpenError = error{
+ /// In WASI, this error may occur when the file descriptor does
+ /// not hold the required rights to open a new resource relative to it.
AccessDenied,
SymLinkLoop,
ProcessFdQuotaExceeded,
@@ -1115,6 +1136,7 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, oflags: oflags_t, fdflags
wasi.EPERM => return error.AccessDenied,
wasi.EEXIST => return error.PathAlreadyExists,
wasi.EBUSY => return error.DeviceBusy,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -1501,6 +1523,8 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
}
pub const SymLinkError = error{
+ /// In WASI, this error may occur when the file descriptor does
+ /// not hold the required rights to create a new symbolic link relative to it.
AccessDenied,
DiskQuota,
PathAlreadyExists,
@@ -1606,13 +1630,14 @@ pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []c
wasi.ENOMEM => return error.SystemResources,
wasi.ENOSPC => return error.NoSpaceLeft,
wasi.EROFS => return error.ReadOnlyFileSystem,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
/// Windows-only. The same as `symlinkat` except the paths are null-terminated, WTF-16 encoded.
/// See also `symlinkat`.
-pub fn symlinkatW(target_path: [*:0]const u16, newdirfd: fd_t, sym_link_path: [*:0]const u16) SymlinkError!void {
+pub fn symlinkatW(target_path: [*:0]const u16, newdirfd: fd_t, sym_link_path: [*:0]const u16) SymLinkError!void {
@compileError("TODO implement on Windows");
}
@@ -1646,6 +1671,9 @@ pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:
pub const UnlinkError = error{
FileNotFound,
+
+ /// In WASI, this error may occur when the file descriptor does
+ /// not hold the required rights to unlink a resource by path relative to it.
AccessDenied,
FileBusy,
FileSystem,
@@ -1749,6 +1777,7 @@ pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatErro
wasi.ENOMEM => return error.SystemResources,
wasi.EROFS => return error.ReadOnlyFileSystem,
wasi.ENOTEMPTY => return error.DirNotEmpty,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
wasi.EINVAL => unreachable, // invalid flags, or pathname has . as last component
wasi.EBADF => unreachable, // always a race condition
@@ -1851,6 +1880,8 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*:0]const u16, flags: u32) UnlinkatEr
}
const RenameError = error{
+ /// In WASI, this error may occur when the file descriptor does
+ /// not hold the required rights to rename a resource by path relative to it.
AccessDenied,
FileBusy,
DiskQuota,
@@ -1970,6 +2001,7 @@ pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, ne
wasi.ENOTEMPTY => return error.PathAlreadyExists,
wasi.EROFS => return error.ReadOnlyFileSystem,
wasi.EXDEV => return error.RenameAcrossMountPoints,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -2068,23 +2100,6 @@ pub fn renameatW(
}
}
-pub const MakeDirError = error{
- AccessDenied,
- DiskQuota,
- PathAlreadyExists,
- SymLinkLoop,
- LinkQuotaExceeded,
- NameTooLong,
- FileNotFound,
- SystemResources,
- NoSpaceLeft,
- NotDir,
- ReadOnlyFileSystem,
- InvalidUtf8,
- BadPathName,
- NoDevice,
-} || UnexpectedError;
-
pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
if (builtin.os.tag == .windows) {
const sub_dir_path_w = try windows.sliceToPrefixedFileW(sub_dir_path);
@@ -2116,6 +2131,7 @@ pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirErr
wasi.ENOSPC => return error.NoSpaceLeft,
wasi.ENOTDIR => return error.NotDir,
wasi.EROFS => return error.ReadOnlyFileSystem,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -2150,6 +2166,25 @@ pub fn mkdiratW(dir_fd: fd_t, sub_path_w: [*:0]const u16, mode: u32) MakeDirErro
windows.CloseHandle(sub_dir_handle);
}
+pub const MakeDirError = error{
+ /// In WASI, this error may occur when the file descriptor does
+ /// not hold the required rights to create a new directory relative to it.
+ AccessDenied,
+ DiskQuota,
+ PathAlreadyExists,
+ SymLinkLoop,
+ LinkQuotaExceeded,
+ NameTooLong,
+ FileNotFound,
+ SystemResources,
+ NoSpaceLeft,
+ NotDir,
+ ReadOnlyFileSystem,
+ InvalidUtf8,
+ BadPathName,
+ NoDevice,
+} || UnexpectedError;
+
/// Create a directory.
/// `mode` is ignored on Windows.
pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void {
@@ -2313,6 +2348,8 @@ pub fn fchdir(dirfd: fd_t) FchdirError!void {
}
pub const ReadLinkError = error{
+ /// In WASI, this error may occur when the file descriptor does
+ /// not hold the required rights to read value of a symbolic link relative to it.
AccessDenied,
FileSystem,
SymLinkLoop,
@@ -2398,6 +2435,7 @@ pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) Read
wasi.ENOENT => return error.FileNotFound,
wasi.ENOMEM => return error.SystemResources,
wasi.ENOTDIR => return error.NotDir,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -3075,6 +3113,9 @@ pub fn waitpid(pid: i32, flags: u32) u32 {
pub const FStatError = error{
SystemResources,
+
+ /// In WASI, this error may occur when the file descriptor does
+ /// not hold the required rights to get its filestat information.
AccessDenied,
} || UnexpectedError;
@@ -3088,6 +3129,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
wasi.EBADF => unreachable, // Always a race condition.
wasi.ENOMEM => return error.SystemResources,
wasi.EACCES => return error.AccessDenied,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -3138,6 +3180,7 @@ pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!S
wasi.ENAMETOOLONG => return error.NameTooLong,
wasi.ENOENT => return error.FileNotFound,
wasi.ENOTDIR => return error.FileNotFound,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -3643,7 +3686,13 @@ pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {
}
}
-pub const SeekError = error{Unseekable} || UnexpectedError;
+pub const SeekError = error{
+ Unseekable,
+
+ /// In WASI, this error may occur when the file descriptor does
+ /// not hold the required rights to seek on it.
+ AccessDenied,
+} || UnexpectedError;
/// Repositions read/write file offset relative to the beginning.
pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
@@ -3671,6 +3720,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
wasi.EOVERFLOW => return error.Unseekable,
wasi.ESPIPE => return error.Unseekable,
wasi.ENXIO => return error.Unseekable,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -3712,6 +3762,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
wasi.EOVERFLOW => return error.Unseekable,
wasi.ESPIPE => return error.Unseekable,
wasi.ENXIO => return error.Unseekable,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -3752,6 +3803,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
wasi.EOVERFLOW => return error.Unseekable,
wasi.ESPIPE => return error.Unseekable,
wasi.ENXIO => return error.Unseekable,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}
@@ -3792,6 +3844,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
wasi.EOVERFLOW => return error.Unseekable,
wasi.ESPIPE => return error.Unseekable,
wasi.ENXIO => return error.Unseekable,
+ wasi.ENOTCAPABLE => return error.AccessDenied,
else => |err| return unexpectedErrno(err),
}
}