| ... | ... | @@ -301,9 +301,9 @@ pub const ReadError = error{ |
| 301 | 301 | /// and reading from the file descriptor would block. |
| 302 | 302 | WouldBlock, |
| 303 | 303 | |
| 304 | | /// WASI-only. This error occurs when the file descriptor does |
| 304 | /// In WASI, this error occurs when the file descriptor does |
| 305 | 305 | /// not hold the required rights to read from it. |
| 306 | | NotCapable, |
| 306 | AccessDenied, |
| 307 | 307 | } || UnexpectedError; |
| 308 | 308 | |
| 309 | 309 | /// 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 | 339 | wasi.ENOMEM => return error.SystemResources, |
| 340 | 340 | wasi.ECONNRESET => return error.ConnectionResetByPeer, |
| 341 | 341 | wasi.ETIMEDOUT => return error.ConnectionTimedOut, |
| 342 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 342 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 343 | 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 | 407 | wasi.EISDIR => return error.IsDir, |
| 408 | 408 | wasi.ENOBUFS => return error.SystemResources, |
| 409 | 409 | wasi.ENOMEM => return error.SystemResources, |
| 410 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 410 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 411 | 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 | 472 | wasi.ENXIO => return error.Unseekable, |
| 473 | 473 | wasi.ESPIPE => return error.Unseekable, |
| 474 | 474 | wasi.EOVERFLOW => return error.Unseekable, |
| 475 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 475 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 476 | 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 | 507 | pub const TruncateError = error{ |
| 508 | 508 | FileTooBig, |
| 509 | 509 | InputOutput, |
| 510 | | CannotTruncate, |
| 511 | 510 | FileBusy, |
| 512 | 511 | |
| 513 | | /// WASI-only. This error occurs when the file descriptor does |
| 512 | /// In WASI, this error occurs when the file descriptor does |
| 514 | 513 | /// not hold the required rights to call `ftruncate` on it. |
| 515 | | NotCapable, |
| 514 | AccessDenied, |
| 516 | 515 | } || UnexpectedError; |
| 517 | 516 | |
| 518 | 517 | 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 | 532 | switch (rc) { |
| 534 | 533 | .SUCCESS => return, |
| 535 | 534 | .INVALID_HANDLE => unreachable, // Handle not open for writing |
| 536 | | .ACCESS_DENIED => return error.CannotTruncate, |
| 535 | .ACCESS_DENIED => return error.AccessDenied, |
| 537 | 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 | 542 | wasi.EINTR => unreachable, |
| 544 | 543 | wasi.EFBIG => return error.FileTooBig, |
| 545 | 544 | wasi.EIO => return error.InputOutput, |
| 546 | | wasi.EPERM => return error.CannotTruncate, |
| 545 | wasi.EPERM => return error.AccessDenied, |
| 547 | 546 | wasi.ETXTBSY => return error.FileBusy, |
| 548 | 547 | wasi.EBADF => unreachable, // Handle not open for writing |
| 549 | 548 | wasi.EINVAL => unreachable, // Handle not open for writing |
| 550 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 549 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 551 | 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 | 565 | EINTR => continue, |
| 567 | 566 | EFBIG => return error.FileTooBig, |
| 568 | 567 | EIO => return error.InputOutput, |
| 569 | | EPERM => return error.CannotTruncate, |
| 568 | EPERM => return error.AccessDenied, |
| 570 | 569 | ETXTBSY => return error.FileBusy, |
| 571 | 570 | EBADF => unreachable, // Handle not open for writing |
| 572 | 571 | 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 | 615 | wasi.ENXIO => return error.Unseekable, |
| 617 | 616 | wasi.ESPIPE => return error.Unseekable, |
| 618 | 617 | wasi.EOVERFLOW => return error.Unseekable, |
| 619 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 618 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 620 | 619 | else => |err| return unexpectedErrno(err), |
| 621 | 620 | } |
| 622 | 621 | } |
| ... | ... | @@ -654,6 +653,9 @@ pub const WriteError = error{ |
| 654 | 653 | FileTooBig, |
| 655 | 654 | InputOutput, |
| 656 | 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 | 659 | AccessDenied, |
| 658 | 660 | BrokenPipe, |
| 659 | 661 | SystemResources, |
| ... | ... | @@ -662,10 +664,6 @@ pub const WriteError = error{ |
| 662 | 664 | /// This error occurs when no global event loop is configured, |
| 663 | 665 | /// and reading from the file descriptor would block. |
| 664 | 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 | 667 | } || UnexpectedError; |
| 670 | 668 | |
| 671 | 669 | /// Write to a file descriptor. |
| ... | ... | @@ -714,7 +712,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { |
| 714 | 712 | wasi.ENOSPC => return error.NoSpaceLeft, |
| 715 | 713 | wasi.EPERM => return error.AccessDenied, |
| 716 | 714 | wasi.EPIPE => return error.BrokenPipe, |
| 717 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 715 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 718 | 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 | 790 | wasi.ENOSPC => return error.NoSpaceLeft, |
| 793 | 791 | wasi.EPERM => return error.AccessDenied, |
| 794 | 792 | wasi.EPIPE => return error.BrokenPipe, |
| 795 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 793 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 796 | 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 | 873 | wasi.ENXIO => return error.Unseekable, |
| 876 | 874 | wasi.ESPIPE => return error.Unseekable, |
| 877 | 875 | wasi.EOVERFLOW => return error.Unseekable, |
| 878 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 876 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 879 | 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 | 967 | wasi.ENXIO => return error.Unseekable, |
| 970 | 968 | wasi.ESPIPE => return error.Unseekable, |
| 971 | 969 | wasi.EOVERFLOW => return error.Unseekable, |
| 972 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 970 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 973 | 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 | 1003 | } |
| 1006 | 1004 | |
| 1007 | 1005 | pub 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 | 1008 | AccessDenied, |
| 1009 | 1009 | SymLinkLoop, |
| 1010 | 1010 | ProcessFdQuotaExceeded, |
| ... | ... | @@ -1041,10 +1041,6 @@ pub const OpenError = error{ |
| 1041 | 1041 | |
| 1042 | 1042 | /// The underlying filesystem does not support file locks |
| 1043 | 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 | 1044 | } || UnexpectedError; |
| 1049 | 1045 | |
| 1050 | 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 | 1134 | wasi.EPERM => return error.AccessDenied, |
| 1139 | 1135 | wasi.EEXIST => return error.PathAlreadyExists, |
| 1140 | 1136 | wasi.EBUSY => return error.DeviceBusy, |
| 1141 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 1137 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 1142 | 1138 | else => |err| return unexpectedErrno(err), |
| 1143 | 1139 | } |
| 1144 | 1140 | } |
| ... | ... | @@ -1525,6 +1521,8 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { |
| 1525 | 1521 | } |
| 1526 | 1522 | |
| 1527 | 1523 | pub 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 | 1526 | AccessDenied, |
| 1529 | 1527 | DiskQuota, |
| 1530 | 1528 | PathAlreadyExists, |
| ... | ... | @@ -1589,19 +1587,13 @@ pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin |
| 1589 | 1587 | } |
| 1590 | 1588 | } |
| 1591 | 1589 | |
| 1592 | | pub 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 | 1590 | /// Similar to `symlink`, however, creates a symbolic link named `sym_link_path` which contains the string |
| 1599 | 1591 | /// `target_path` **relative** to `newdirfd` directory handle. |
| 1600 | 1592 | /// A symbolic link (also known as a soft link) may point to an existing file or to a nonexistent |
| 1601 | 1593 | /// one; the latter case is known as a dangling link. |
| 1602 | 1594 | /// If `sym_link_path` exists, it will not be overwritten. |
| 1603 | 1595 | /// See also `symlinkatWasi`, `symlinkatZ` and `symlinkatW`. |
| 1604 | | pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkAtError!void { |
| 1596 | pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void { |
| 1605 | 1597 | if (builtin.os.tag == .wasi) { |
| 1606 | 1598 | return symlinkatWasi(target_path, newdirfd, sym_link_path); |
| 1607 | 1599 | } |
| ... | ... | @@ -1619,7 +1611,7 @@ pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ"); |
| 1619 | 1611 | |
| 1620 | 1612 | /// WASI-only. The same as `symlinkat` but targeting WASI. |
| 1621 | 1613 | /// See also `symlinkat`. |
| 1622 | | pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkAtError!void { |
| 1614 | pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void { |
| 1623 | 1615 | switch (wasi.path_symlink(target_path.ptr, target_path.len, newdirfd, sym_link_path.ptr, sym_link_path.len)) { |
| 1624 | 1616 | wasi.ESUCCESS => {}, |
| 1625 | 1617 | wasi.EFAULT => unreachable, |
| ... | ... | @@ -1636,20 +1628,20 @@ pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []c |
| 1636 | 1628 | wasi.ENOMEM => return error.SystemResources, |
| 1637 | 1629 | wasi.ENOSPC => return error.NoSpaceLeft, |
| 1638 | 1630 | wasi.EROFS => return error.ReadOnlyFileSystem, |
| 1639 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 1631 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 1640 | 1632 | else => |err| return unexpectedErrno(err), |
| 1641 | 1633 | } |
| 1642 | 1634 | } |
| 1643 | 1635 | |
| 1644 | 1636 | /// Windows-only. The same as `symlinkat` except the paths are null-terminated, WTF-16 encoded. |
| 1645 | 1637 | /// See also `symlinkat`. |
| 1646 | | pub fn symlinkatW(target_path: [*:0]const u16, newdirfd: fd_t, sym_link_path: [*:0]const u16) SymLinkAtError!void { |
| 1638 | pub fn symlinkatW(target_path: [*:0]const u16, newdirfd: fd_t, sym_link_path: [*:0]const u16) SymLinkError!void { |
| 1647 | 1639 | @compileError("TODO implement on Windows"); |
| 1648 | 1640 | } |
| 1649 | 1641 | |
| 1650 | 1642 | /// The same as `symlinkat` except the parameters are null-terminated pointers. |
| 1651 | 1643 | /// See also `symlinkat`. |
| 1652 | | pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkAtError!void { |
| 1644 | pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkError!void { |
| 1653 | 1645 | if (builtin.os.tag == .windows) { |
| 1654 | 1646 | const target_path_w = try windows.cStrToPrefixedFileW(target_path); |
| 1655 | 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 | 1669 | |
| 1678 | 1670 | pub const UnlinkError = error{ |
| 1679 | 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 | 1675 | AccessDenied, |
| 1681 | 1676 | FileBusy, |
| 1682 | 1677 | FileSystem, |
| ... | ... | @@ -1739,10 +1734,6 @@ pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void { |
| 1739 | 1734 | pub const UnlinkatError = UnlinkError || error{ |
| 1740 | 1735 | /// When passing `AT_REMOVEDIR`, this error occurs when the named directory is not empty. |
| 1741 | 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 | }; |
| 1747 | 1738 | |
| 1748 | 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 | 1775 | wasi.ENOMEM => return error.SystemResources, |
| 1785 | 1776 | wasi.EROFS => return error.ReadOnlyFileSystem, |
| 1786 | 1777 | wasi.ENOTEMPTY => return error.DirNotEmpty, |
| 1787 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 1778 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 1788 | 1779 | |
| 1789 | 1780 | wasi.EINVAL => unreachable, // invalid flags, or pathname has . as last component |
| 1790 | 1781 | 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 | 1878 | } |
| 1888 | 1879 | |
| 1889 | 1880 | const 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 | 1883 | AccessDenied, |
| 1891 | 1884 | FileBusy, |
| 1892 | 1885 | DiskQuota, |
| ... | ... | @@ -1963,19 +1956,13 @@ pub fn renameW(old_path: [*:0]const u16, new_path: [*:0]const u16) RenameError!v |
| 1963 | 1956 | return windows.MoveFileExW(old_path, new_path, flags); |
| 1964 | 1957 | } |
| 1965 | 1958 | |
| 1966 | | pub 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 | 1959 | /// Change the name or location of a file based on an open directory handle. |
| 1973 | 1960 | pub fn renameat( |
| 1974 | 1961 | old_dir_fd: fd_t, |
| 1975 | 1962 | old_path: []const u8, |
| 1976 | 1963 | new_dir_fd: fd_t, |
| 1977 | 1964 | new_path: []const u8, |
| 1978 | | ) RenameatError!void { |
| 1965 | ) RenameError!void { |
| 1979 | 1966 | if (builtin.os.tag == .windows) { |
| 1980 | 1967 | const old_path_w = try windows.sliceToPrefixedFileW(old_path); |
| 1981 | 1968 | const new_path_w = try windows.sliceToPrefixedFileW(new_path); |
| ... | ... | @@ -1991,7 +1978,7 @@ pub fn renameat( |
| 1991 | 1978 | |
| 1992 | 1979 | /// WASI-only. Same as `renameat` expect targeting WASI. |
| 1993 | 1980 | /// See also `renameat`. |
| 1994 | | pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameatError!void { |
| 1981 | pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, new_path: []const u8) RenameError!void { |
| 1995 | 1982 | switch (wasi.path_rename(old_dir_fd, old_path.ptr, old_path.len, new_dir_fd, new_path.ptr, new_path.len)) { |
| 1996 | 1983 | wasi.ESUCCESS => return, |
| 1997 | 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 | 1999 | wasi.ENOTEMPTY => return error.PathAlreadyExists, |
| 2013 | 2000 | wasi.EROFS => return error.ReadOnlyFileSystem, |
| 2014 | 2001 | wasi.EXDEV => return error.RenameAcrossMountPoints, |
| 2015 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 2002 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 2016 | 2003 | else => |err| return unexpectedErrno(err), |
| 2017 | 2004 | } |
| 2018 | 2005 | } |
| ... | ... | @@ -2023,7 +2010,7 @@ pub fn renameatZ( |
| 2023 | 2010 | old_path: [*:0]const u8, |
| 2024 | 2011 | new_dir_fd: fd_t, |
| 2025 | 2012 | new_path: [*:0]const u8, |
| 2026 | | ) RenameatError!void { |
| 2013 | ) RenameError!void { |
| 2027 | 2014 | if (builtin.os.tag == .windows) { |
| 2028 | 2015 | const old_path_w = try windows.cStrToPrefixedFileW(old_path); |
| 2029 | 2016 | const new_path_w = try windows.cStrToPrefixedFileW(new_path); |
| ... | ... | @@ -2062,7 +2049,7 @@ pub fn renameatW( |
| 2062 | 2049 | new_dir_fd: fd_t, |
| 2063 | 2050 | new_path_w: []const u16, |
| 2064 | 2051 | ReplaceIfExists: windows.BOOLEAN, |
| 2065 | | ) RenameatError!void { |
| 2052 | ) RenameError!void { |
| 2066 | 2053 | const src_fd = windows.OpenFile(old_path_w, .{ |
| 2067 | 2054 | .dir = old_dir_fd, |
| 2068 | 2055 | .access_mask = windows.SYNCHRONIZE | windows.GENERIC_WRITE | windows.DELETE, |
| ... | ... | @@ -2111,13 +2098,7 @@ pub fn renameatW( |
| 2111 | 2098 | } |
| 2112 | 2099 | } |
| 2113 | 2100 | |
| 2114 | | pub const MakeDirAtError = error{ |
| 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 | | |
| 2120 | | pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtError!void { |
| 2101 | pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void { |
| 2121 | 2102 | if (builtin.os.tag == .windows) { |
| 2122 | 2103 | const sub_dir_path_w = try windows.sliceToPrefixedFileW(sub_dir_path); |
| 2123 | 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 | 2112 | |
| 2132 | 2113 | pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ"); |
| 2133 | 2114 | |
| 2134 | | pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirAtError!void { |
| 2115 | pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void { |
| 2135 | 2116 | switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) { |
| 2136 | 2117 | wasi.ESUCCESS => return, |
| 2137 | 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 | 2129 | wasi.ENOSPC => return error.NoSpaceLeft, |
| 2149 | 2130 | wasi.ENOTDIR => return error.NotDir, |
| 2150 | 2131 | wasi.EROFS => return error.ReadOnlyFileSystem, |
| 2151 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 2132 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 2152 | 2133 | else => |err| return unexpectedErrno(err), |
| 2153 | 2134 | } |
| 2154 | 2135 | } |
| 2155 | 2136 | |
| 2156 | | pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirAtError!void { |
| 2137 | pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void { |
| 2157 | 2138 | if (builtin.os.tag == .windows) { |
| 2158 | 2139 | const sub_dir_path_w = try windows.cStrToPrefixedFileW(sub_dir_path); |
| 2159 | 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 | 2159 | } |
| 2179 | 2160 | } |
| 2180 | 2161 | |
| 2181 | | pub fn mkdiratW(dir_fd: fd_t, sub_path_w: [*:0]const u16, mode: u32) MakeDirAtError!void { |
| 2162 | pub fn mkdiratW(dir_fd: fd_t, sub_path_w: [*:0]const u16, mode: u32) MakeDirError!void { |
| 2182 | 2163 | const sub_dir_handle = try windows.CreateDirectoryW(dir_fd, sub_path_w, null); |
| 2183 | 2164 | windows.CloseHandle(sub_dir_handle); |
| 2184 | 2165 | } |
| 2185 | 2166 | |
| 2186 | 2167 | pub 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 | 2170 | AccessDenied, |
| 2188 | 2171 | DiskQuota, |
| 2189 | 2172 | PathAlreadyExists, |
| ... | ... | @@ -2363,6 +2346,8 @@ pub fn fchdir(dirfd: fd_t) FchdirError!void { |
| 2363 | 2346 | } |
| 2364 | 2347 | |
| 2365 | 2348 | pub 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 | 2351 | AccessDenied, |
| 2367 | 2352 | FileSystem, |
| 2368 | 2353 | SymLinkLoop, |
| ... | ... | @@ -2416,16 +2401,10 @@ pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 |
| 2416 | 2401 | } |
| 2417 | 2402 | } |
| 2418 | 2403 | |
| 2419 | | pub 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 | 2404 | /// Similar to `readlink` except reads value of a symbolink link **relative** to `dirfd` directory handle. |
| 2426 | 2405 | /// The return value is a slice of `out_buffer` from index 0. |
| 2427 | 2406 | /// See also `readlinkatWasi`, `realinkatZ` and `realinkatW`. |
| 2428 | | pub fn readlinkat(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkAtError![]u8 { |
| 2407 | pub fn readlinkat(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 2429 | 2408 | if (builtin.os.tag == .wasi) { |
| 2430 | 2409 | return readlinkatWasi(dirfd, file_path, out_buffer); |
| 2431 | 2410 | } |
| ... | ... | @@ -2441,7 +2420,7 @@ pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ"); |
| 2441 | 2420 | |
| 2442 | 2421 | /// WASI-only. Same as `readlinkat` but targets WASI. |
| 2443 | 2422 | /// See also `readlinkat`. |
| 2444 | | pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkAtError![]u8 { |
| 2423 | pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 2445 | 2424 | var bufused: usize = undefined; |
| 2446 | 2425 | switch (wasi.path_readlink(dirfd, file_path.ptr, file_path.len, out_buffer.ptr, out_buffer.len, &bufused)) { |
| 2447 | 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 | 2433 | wasi.ENOENT => return error.FileNotFound, |
| 2455 | 2434 | wasi.ENOMEM => return error.SystemResources, |
| 2456 | 2435 | wasi.ENOTDIR => return error.NotDir, |
| 2457 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 2436 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 2458 | 2437 | else => |err| return unexpectedErrno(err), |
| 2459 | 2438 | } |
| 2460 | 2439 | } |
| 2461 | 2440 | |
| 2462 | 2441 | /// Windows-only. Same as `readlinkat` except `file_path` is null-terminated, WTF16 encoded. |
| 2463 | 2442 | /// See also `readlinkat`. |
| 2464 | | pub fn readlinkatW(dirfd: fd_t, file_path: [*:0]const u16, out_buffer: []u8) ReadLinkAtError![]u8 { |
| 2443 | pub fn readlinkatW(dirfd: fd_t, file_path: [*:0]const u16, out_buffer: []u8) ReadLinkError![]u8 { |
| 2465 | 2444 | @compileError("TODO implement on Windows"); |
| 2466 | 2445 | } |
| 2467 | 2446 | |
| 2468 | 2447 | /// Same as `readlinkat` except `file_path` is null-terminated. |
| 2469 | 2448 | /// See also `readlinkat`. |
| 2470 | | pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkAtError![]u8 { |
| 2449 | pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 2471 | 2450 | if (builtin.os.tag == .windows) { |
| 2472 | 2451 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 2473 | 2452 | return readlinkatW(dirfd, file_path_w.span().ptr, out_buffer); |
| ... | ... | @@ -3132,11 +3111,10 @@ pub fn waitpid(pid: i32, flags: u32) u32 { |
| 3132 | 3111 | |
| 3133 | 3112 | pub const FStatError = error{ |
| 3134 | 3113 | SystemResources, |
| 3135 | | AccessDenied, |
| 3136 | 3114 | |
| 3137 | | /// WASI-only. This error occurs when the file descriptor does |
| 3115 | /// In WASI, this error may occur when the file descriptor does |
| 3138 | 3116 | /// not hold the required rights to get its filestat information. |
| 3139 | | NotCapable, |
| 3117 | AccessDenied, |
| 3140 | 3118 | } || UnexpectedError; |
| 3141 | 3119 | |
| 3142 | 3120 | /// Return information about a file descriptor. |
| ... | ... | @@ -3149,7 +3127,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat { |
| 3149 | 3127 | wasi.EBADF => unreachable, // Always a race condition. |
| 3150 | 3128 | wasi.ENOMEM => return error.SystemResources, |
| 3151 | 3129 | wasi.EACCES => return error.AccessDenied, |
| 3152 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 3130 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3153 | 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 | 3178 | wasi.ENAMETOOLONG => return error.NameTooLong, |
| 3201 | 3179 | wasi.ENOENT => return error.FileNotFound, |
| 3202 | 3180 | wasi.ENOTDIR => return error.FileNotFound, |
| 3203 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 3181 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3204 | 3182 | else => |err| return unexpectedErrno(err), |
| 3205 | 3183 | } |
| 3206 | 3184 | } |
| ... | ... | @@ -3709,9 +3687,9 @@ pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void { |
| 3709 | 3687 | pub const SeekError = error{ |
| 3710 | 3688 | Unseekable, |
| 3711 | 3689 | |
| 3712 | | /// WASI-only. This error occurs when the file descriptor does |
| 3690 | /// In WASI, this error may occur when the file descriptor does |
| 3713 | 3691 | /// not hold the required rights to seek on it. |
| 3714 | | NotCapable, |
| 3692 | AccessDenied, |
| 3715 | 3693 | } || UnexpectedError; |
| 3716 | 3694 | |
| 3717 | 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 | 3718 | wasi.EOVERFLOW => return error.Unseekable, |
| 3741 | 3719 | wasi.ESPIPE => return error.Unseekable, |
| 3742 | 3720 | wasi.ENXIO => return error.Unseekable, |
| 3743 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 3721 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3744 | 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 | 3760 | wasi.EOVERFLOW => return error.Unseekable, |
| 3783 | 3761 | wasi.ESPIPE => return error.Unseekable, |
| 3784 | 3762 | wasi.ENXIO => return error.Unseekable, |
| 3785 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 3763 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3786 | 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 | 3801 | wasi.EOVERFLOW => return error.Unseekable, |
| 3824 | 3802 | wasi.ESPIPE => return error.Unseekable, |
| 3825 | 3803 | wasi.ENXIO => return error.Unseekable, |
| 3826 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 3804 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3827 | 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 | 3842 | wasi.EOVERFLOW => return error.Unseekable, |
| 3865 | 3843 | wasi.ESPIPE => return error.Unseekable, |
| 3866 | 3844 | wasi.ENXIO => return error.Unseekable, |
| 3867 | | wasi.ENOTCAPABLE => return error.NotCapable, |
| 3845 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3868 | 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 | 3990 | if (builtin.os.tag == .linux and !builtin.link_libc) { |
| 4013 | 3991 | const fd = openZ(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0) catch |err| switch (err) { |
| 4014 | 3992 | error.FileLocksNotSupported => unreachable, |
| 4015 | | error.NotCapable => unreachable, // WASI only |
| 4016 | 3993 | else => |e| return e, |
| 4017 | 3994 | }; |
| 4018 | 3995 | defer close(fd); |