authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-05 18:43:39-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-05 18:43:39-05:00
loge2f4df60651e81d0f9d60f990acdadd28cc5b41f
treea1619ce97062a974897e85485f4c1ae5f692d857
parent9c5852aa8674320d2912627708f32fea37d7cd08
signaturelock-open Commit is signed but in an unrecognized format.

std.os.changeCurDir no longer needs an allocator


2 files changed, 15 insertions(+), 21 deletions(-)

std/os.zig+14-20
......@@ -1825,26 +1825,20 @@ pub const Dir = struct {
18251825 }
18261826};
18271827
1828pub fn changeCurDir(allocator: *Allocator, dir_path: []const u8) !void {
1829 const path_buf = try allocator.alloc(u8, dir_path.len + 1);
1830 defer allocator.free(path_buf);
1831
1832 mem.copy(u8, path_buf, dir_path);
1833 path_buf[dir_path.len] = 0;
1834
1835 const err = posix.getErrno(posix.chdir(path_buf.ptr));
1836 if (err > 0) {
1837 return switch (err) {
1838 posix.EACCES => error.AccessDenied,
1839 posix.EFAULT => unreachable,
1840 posix.EIO => error.FileSystem,
1841 posix.ELOOP => error.SymLinkLoop,
1842 posix.ENAMETOOLONG => error.NameTooLong,
1843 posix.ENOENT => error.FileNotFound,
1844 posix.ENOMEM => error.SystemResources,
1845 posix.ENOTDIR => error.NotDir,
1846 else => unexpectedErrorPosix(err),
1847 };
1828pub fn changeCurDir(dir_path: []const u8) !void {
1829 const dir_path_c = try toPosixPath(dir_path);
1830 const err = posix.getErrno(posix.chdir(&dir_path_c));
1831 switch (err) {
1832 0 => return,
1833 posix.EACCES => return error.AccessDenied,
1834 posix.EFAULT => unreachable,
1835 posix.EIO => return error.FileSystem,
1836 posix.ELOOP => return error.SymLinkLoop,
1837 posix.ENAMETOOLONG => return error.NameTooLong,
1838 posix.ENOENT => return error.FileNotFound,
1839 posix.ENOMEM => return error.SystemResources,
1840 posix.ENOTDIR => return error.NotDir,
1841 else => return unexpectedErrorPosix(err),
18481842 }
18491843}
18501844
std/os/child_process.zig+1-1
......@@ -404,7 +404,7 @@ pub const ChildProcess = struct {
404404 }
405405
406406 if (self.cwd) |cwd| {
407 os.changeCurDir(self.allocator, cwd) catch |err| forkChildErrReport(err_pipe[1], err);
407 os.changeCurDir(cwd) catch |err| forkChildErrReport(err_pipe[1], err);
408408 }
409409
410410 if (self.gid) |gid| {