authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-01-15 18:15:24+10:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-03 13:25:43-05:00
logbfc569bc9877a4f305080bc6cde0e42fed7433e0
tree63016c5c1469db9aa9f45edefe0685a639741d54
parent627618a38d291d9cc76c8e30e33cad60dc26cf11
signaturelock-open Commit is signed but in an unrecognized format.

std: add os.fstatat


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

lib/std/c.zig+1
......@@ -75,6 +75,7 @@ pub extern "c" fn isatty(fd: fd_t) c_int;
7575pub extern "c" fn close(fd: fd_t) c_int;
7676pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
7777pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
78pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
7879pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t;
7980pub extern "c" fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int;
8081pub extern "c" fn openat(fd: c_int, path: [*:0]const u8, oflag: c_uint, ...) c_int;
lib/std/os.zig+23
......@@ -2371,6 +2371,29 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
23712371 }
23722372}
23732373
2374const FStatAtError = FStatError || error{NameTooLong};
2375
2376pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError![]Stat {
2377 const pathname_c = try toPosixPath(pathname);
2378 return fstatatC(dirfd, &pathname_c, flags);
2379}
2380
2381pub fn fstatatC(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat {
2382 var stat: Stat = undefined;
2383 switch (errno(system.fstatat(dirfd, pathname, &stat, flags))) {
2384 0 => return stat,
2385 EINVAL => unreachable,
2386 EBADF => unreachable, // Always a race condition.
2387 ENOMEM => return error.SystemResources,
2388 EACCES => return error.AccessDenied,
2389 EFAULT => unreachable,
2390 ENAMETOOLONG => return error.NameTooLong,
2391 ENOENT => return error.FileNotFound,
2392 ENOTDIR => return error.FileNotFound,
2393 else => |err| return unexpectedErrno(err),
2394 }
2395}
2396
23742397pub const KQueueError = error{
23752398 /// The per-process limit on the number of open file descriptors has been reached.
23762399 ProcessFdQuotaExceeded,