| author | |
| committer | |
| log | 627618a38d291d9cc76c8e30e33cad60dc26cf11 |
| tree | 147fb6c132985cb88461abb58fcf1d18a36ce5eb |
| parent | dfb420e6d779b9b6d60a277401aadba2800e3572 |
| signature | Commit is signed but in an unrecognized format. |
4 files changed, 23 insertions(+), 0 deletions(-)
lib/std/c.zig+1| ... | @@ -105,6 +105,7 @@ pub extern "c" fn mkdirat(dirfd: fd_t, path: [*:0]const u8, mode: u32) c_int; | ... | @@ -105,6 +105,7 @@ pub extern "c" fn mkdirat(dirfd: fd_t, path: [*:0]const u8, mode: u32) c_int; |
| 105 | pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int; | 105 | pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int; |
| 106 | pub extern "c" fn rename(old: [*:0]const u8, new: [*:0]const u8) c_int; | 106 | pub extern "c" fn rename(old: [*:0]const u8, new: [*:0]const u8) c_int; |
| 107 | pub extern "c" fn chdir(path: [*:0]const u8) c_int; | 107 | pub extern "c" fn chdir(path: [*:0]const u8) c_int; |
| 108 | pub extern "c" fn fchdir(fd: fd_t) c_int; | ||
| 108 | pub extern "c" fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) c_int; | 109 | pub extern "c" fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) c_int; |
| 109 | pub extern "c" fn dup(fd: fd_t) c_int; | 110 | pub extern "c" fn dup(fd: fd_t) c_int; |
| 110 | pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int; | 111 | pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int; |
lib/std/fs.zig+4| ... | @@ -890,6 +890,10 @@ pub const Dir = struct { | ... | @@ -890,6 +890,10 @@ pub const Dir = struct { |
| 890 | try os.mkdiratC(self.fd, sub_path, default_new_dir_mode); | 890 | try os.mkdiratC(self.fd, sub_path, default_new_dir_mode); |
| 891 | } | 891 | } |
| 892 | 892 | ||
| 893 | pub fn changeTo(self: Dir) !void { | ||
| 894 | try os.fchdir(self.fd); | ||
| 895 | } | ||
| 896 | |||
| 893 | /// Deprecated; call `openDirList` directly. | 897 | /// Deprecated; call `openDirList` directly. |
| 894 | pub fn openDir(self: Dir, sub_path: []const u8) OpenError!Dir { | 898 | pub fn openDir(self: Dir, sub_path: []const u8) OpenError!Dir { |
| 895 | return self.openDirList(sub_path); | 899 | return self.openDirList(sub_path); |
lib/std/os.zig+14| ... | @@ -1706,6 +1706,20 @@ pub fn chdirC(dir_path: [*:0]const u8) ChangeCurDirError!void { | ... | @@ -1706,6 +1706,20 @@ pub fn chdirC(dir_path: [*:0]const u8) ChangeCurDirError!void { |
| 1706 | } | 1706 | } |
| 1707 | } | 1707 | } |
| 1708 | 1708 | ||
| 1709 | pub fn fchdir(dirfd: fd_t) ChangeCurDirError!void { | ||
| 1710 | while (true) { | ||
| 1711 | switch (errno(system.fchdir(dirfd))) { | ||
| 1712 | 0 => return, | ||
| 1713 | EACCES => return error.AccessDenied, | ||
| 1714 | EBADF => unreachable, | ||
| 1715 | ENOTDIR => return error.NotDir, | ||
| 1716 | EINTR => continue, | ||
| 1717 | EIO => return error.FileSystem, | ||
| 1718 | else => |err| return unexpectedErrno(err), | ||
| 1719 | } | ||
| 1720 | } | ||
| 1721 | } | ||
| 1722 | |||
| 1709 | pub const ReadLinkError = error{ | 1723 | pub const ReadLinkError = error{ |
| 1710 | AccessDenied, | 1724 | AccessDenied, |
| 1711 | FileSystem, | 1725 | FileSystem, |
lib/std/os/linux.zig+4| ... | @@ -76,6 +76,10 @@ pub fn chdir(path: [*:0]const u8) usize { | ... | @@ -76,6 +76,10 @@ pub fn chdir(path: [*:0]const u8) usize { |
| 76 | return syscall1(SYS_chdir, @ptrToInt(path)); | 76 | return syscall1(SYS_chdir, @ptrToInt(path)); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | pub fn fchdir(fd: fd_t) usize { | ||
| 80 | return syscall1(SYS_fchdir, @bitCast(usize, @as(isize, fd))); | ||
| 81 | } | ||
| 82 | |||
| 79 | pub fn chroot(path: [*:0]const u8) usize { | 83 | pub fn chroot(path: [*:0]const u8) usize { |
| 80 | return syscall1(SYS_chroot, @ptrToInt(path)); | 84 | return syscall1(SYS_chroot, @ptrToInt(path)); |
| 81 | } | 85 | } |