aboutsummaryrefslogtreecommitdiff
path: root/std/os.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-07-15 20:46:12 -0400
committerGitHub <noreply@github.com>2019-07-15 20:46:12 -0400
commit3f4abe97bdbe666dbb3532c14a97e414aae4caca (patch)
treeba08f2f14e79a8c8f7e83cea0344826fefffd9a2 /std/os.zig
parent33eaaadd01b20d1327b67758664ce1265216e471 (diff)
parentaff90c22520bbbadd56fbfd1378f161ee8a3cdb2 (diff)
downloadzig-3f4abe97bdbe666dbb3532c14a97e414aae4caca.tar.gz
zig-3f4abe97bdbe666dbb3532c14a97e414aae4caca.zip
Merge pull request #2892 from ziglang/install-with-zig-build
move some of the installation from cmake to zig build
Diffstat (limited to 'std/os.zig')
-rw-r--r--std/os.zig39
1 files changed, 39 insertions, 0 deletions
diff --git a/std/os.zig b/std/os.zig
index 1971b51df4..190f02101e 100644
--- a/std/os.zig
+++ b/std/os.zig
@@ -2546,6 +2546,45 @@ pub fn sigaction(sig: u6, act: *const Sigaction, oact: ?*Sigaction) void {
}
}
+pub const FutimensError = error{
+ /// times is NULL, or both tv_nsec values are UTIME_NOW, and either:
+ /// * the effective user ID of the caller does not match the owner
+ /// of the file, the caller does not have write access to the
+ /// file, and the caller is not privileged (Linux: does not have
+ /// either the CAP_FOWNER or the CAP_DAC_OVERRIDE capability);
+ /// or,
+ /// * the file is marked immutable (see chattr(1)).
+ AccessDenied,
+
+ /// The caller attempted to change one or both timestamps to a value
+ /// other than the current time, or to change one of the timestamps
+ /// to the current time while leaving the other timestamp unchanged,
+ /// (i.e., times is not NULL, neither tv_nsec field is UTIME_NOW,
+ /// and neither tv_nsec field is UTIME_OMIT) and either:
+ /// * the caller's effective user ID does not match the owner of
+ /// file, and the caller is not privileged (Linux: does not have
+ /// the CAP_FOWNER capability); or,
+ /// * the file is marked append-only or immutable (see chattr(1)).
+ PermissionDenied,
+
+ ReadOnlyFileSystem,
+
+ Unexpected,
+};
+
+pub fn futimens(fd: fd_t, times: *const [2]timespec) FutimensError!void {
+ switch (errno(system.futimens(fd, times))) {
+ 0 => return,
+ EACCES => return error.AccessDenied,
+ EPERM => return error.PermissionDenied,
+ EBADF => unreachable, // always a race condition
+ EFAULT => unreachable,
+ EINVAL => unreachable,
+ EROFS => return error.ReadOnlyFileSystem,
+ else => |err| return unexpectedErrno(err),
+ }
+}
+
test "" {
_ = @import("os/darwin.zig");
_ = @import("os/freebsd.zig");