diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-03-03 12:08:18 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-03-03 12:08:18 -0700 |
| commit | df4cfc2ecf498bf4615ccbaa93438849322bbd18 (patch) | |
| tree | a71611e86cacd8e021190cc4755574c514acb5c7 /lib/std/os.zig | |
| parent | 72443fb88cfddad8a58868c150eaf5818826cb21 (diff) | |
| parent | 75ff34db9e93056482233f8476a06f78b4a2f3c2 (diff) | |
| download | zig-df4cfc2ecf498bf4615ccbaa93438849322bbd18.tar.gz zig-df4cfc2ecf498bf4615ccbaa93438849322bbd18.zip | |
Merge remote-tracking branch 'origin/master' into llvm16
Diffstat (limited to 'lib/std/os.zig')
| -rw-r--r-- | lib/std/os.zig | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig index bd6719ec8f..fe664302a7 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -302,8 +302,7 @@ pub const FChmodError = error{ /// successfully, or must have the effective user ID matching the owner /// of the file. pub fn fchmod(fd: fd_t, mode: mode_t) FChmodError!void { - if (builtin.os.tag == .windows or builtin.os.tag == .wasi) - @compileError("Unsupported OS"); + if (!std.fs.has_executable_bit) @compileError("fchmod unsupported by target OS"); while (true) { const res = system.fchmod(fd, mode); @@ -311,8 +310,38 @@ pub fn fchmod(fd: fd_t, mode: mode_t) FChmodError!void { switch (system.getErrno(res)) { .SUCCESS => return, .INTR => continue, - .BADF => unreachable, // Can be reached if the fd refers to a non-iterable directory. + .BADF => unreachable, + .FAULT => unreachable, + .INVAL => unreachable, + .ACCES => return error.AccessDenied, + .IO => return error.InputOutput, + .LOOP => return error.SymLinkLoop, + .NOENT => return error.FileNotFound, + .NOMEM => return error.SystemResources, + .NOTDIR => return error.FileNotFound, + .PERM => return error.AccessDenied, + .ROFS => return error.ReadOnlyFileSystem, + else => |err| return unexpectedErrno(err), + } + } +} + +const FChmodAtError = FChmodError || error{ + NameTooLong, +}; +pub fn fchmodat(dirfd: fd_t, path: []const u8, mode: mode_t, flags: u32) FChmodAtError!void { + if (!std.fs.has_executable_bit) @compileError("fchmodat unsupported by target OS"); + + const path_c = try toPosixPath(path); + + while (true) { + const res = system.fchmodat(dirfd, &path_c, mode, flags); + + switch (system.getErrno(res)) { + .SUCCESS => return, + .INTR => continue, + .BADF => unreachable, .FAULT => unreachable, .INVAL => unreachable, .ACCES => return error.AccessDenied, |
