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;...@@ -75,6 +75,7 @@ pub extern "c" fn isatty(fd: fd_t) c_int;
75pub extern "c" fn close(fd: fd_t) c_int;75pub extern "c" fn close(fd: fd_t) c_int;
76pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;76pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
77pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;77pub 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;
78pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t;79pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t;
79pub extern "c" fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int;80pub extern "c" fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int;
80pub extern "c" fn openat(fd: c_int, path: [*:0]const u8, oflag: c_uint, ...) c_int;81pub 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 {...@@ -2371,6 +2371,29 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
2371 }2371 }
2372}2372}
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
2374pub const KQueueError = error{2397pub const KQueueError = error{
2375 /// The per-process limit on the number of open file descriptors has been reached.2398 /// The per-process limit on the number of open file descriptors has been reached.
2376 ProcessFdQuotaExceeded,2399 ProcessFdQuotaExceeded,