authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-01-15 18:07:08+10:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-03 13:25:40-05:00
log88e27f01c8dbf4bda5726c93d12cc4a1d174989d
tree57428a44a7e5c7c50c4f1583d020f669e73568fd
parent582db68a157520a0cf7777807f466d1f6a2e31e7
signaturelock-open Commit is signed but in an unrecognized format.

std: add mkdirat


2 files changed, 36 insertions(+), 0 deletions(-)

lib/std/c.zig+1
...@@ -101,6 +101,7 @@ pub extern "c" fn faccessat(dirfd: fd_t, path: [*:0]const u8, mode: c_uint, flag...@@ -101,6 +101,7 @@ pub extern "c" fn faccessat(dirfd: fd_t, path: [*:0]const u8, mode: c_uint, flag
101pub extern "c" fn pipe(fds: *[2]fd_t) c_int;101pub extern "c" fn pipe(fds: *[2]fd_t) c_int;
102pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;102pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
103pub extern "c" fn mkdir(path: [*:0]const u8, mode: c_uint) c_int;103pub extern "c" fn mkdir(path: [*:0]const u8, mode: c_uint) c_int;
104pub extern "c" fn mkdirat(dirfd: fd_t, path: [*:0]const u8, mode: u32) c_int;
104pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int;105pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int;
105pub extern "c" fn rename(old: [*:0]const u8, new: [*:0]const u8) c_int;106pub extern "c" fn rename(old: [*:0]const u8, new: [*:0]const u8) c_int;
106pub extern "c" fn chdir(path: [*:0]const u8) c_int;107pub extern "c" fn chdir(path: [*:0]const u8) c_int;
lib/std/os.zig+35
...@@ -1542,6 +1542,41 @@ pub const MakeDirError = error{...@@ -1542,6 +1542,41 @@ pub const MakeDirError = error{
1542 BadPathName,1542 BadPathName,
1543} || UnexpectedError;1543} || UnexpectedError;
15441544
1545pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
1546 if (builtin.os == .windows) {
1547 const sub_dir_path_w = try windows.sliceToPrefixedFileW(sub_dir_path);
1548 @compileError("TODO implement mkdirat for Windows");
1549 } else {
1550 const sub_dir_path_c = try toPosixPath(sub_dir_path);
1551 return mkdiratC(dir_fd, &sub_dir_path_c, mode);
1552 }
1553}
1554
1555pub fn mkdiratC(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
1556 if (builtin.os == .windows) {
1557 const sub_dir_path_w = try windows.cStrToPrefixedFileW(sub_dir_path);
1558 @compileError("TODO implement mkdiratC for Windows");
1559 }
1560 switch (errno(system.mkdirat(dir_fd, sub_dir_path, mode))) {
1561 0 => return,
1562 EACCES => return error.AccessDenied,
1563 EBADF => unreachable,
1564 EPERM => return error.AccessDenied,
1565 EDQUOT => return error.DiskQuota,
1566 EEXIST => return error.PathAlreadyExists,
1567 EFAULT => unreachable,
1568 ELOOP => return error.SymLinkLoop,
1569 EMLINK => return error.LinkQuotaExceeded,
1570 ENAMETOOLONG => return error.NameTooLong,
1571 ENOENT => return error.FileNotFound,
1572 ENOMEM => return error.SystemResources,
1573 ENOSPC => return error.NoSpaceLeft,
1574 ENOTDIR => return error.NotDir,
1575 EROFS => return error.ReadOnlyFileSystem,
1576 else => |err| return unexpectedErrno(err),
1577 }
1578}
1579
1545/// Create a directory.1580/// Create a directory.
1546/// `mode` is ignored on Windows.1581/// `mode` is ignored on Windows.
1547pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void {1582pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void {