aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os.zig
diff options
context:
space:
mode:
authorSebastien Marie <semarie@users.noreply.github.com>2020-10-17 17:38:23 +0200
committerGitHub <noreply@github.com>2020-10-17 17:38:23 +0200
commit35a7247a2c9ab208d96fdc9a7c0c63f4c852666c (patch)
treed90d927b2c153ef2212dfcb6a0b47346e8896eb5 /lib/std/os.zig
parent161eb4a000923c28d152781dcc8a080905c7ad32 (diff)
parent245d98d32dd29e80de9732f415a4731748008acf (diff)
downloadzig-35a7247a2c9ab208d96fdc9a7c0c63f4c852666c.tar.gz
zig-35a7247a2c9ab208d96fdc9a7c0c63f4c852666c.zip
Merge branch 'master' into openbsd-minimal
Diffstat (limited to 'lib/std/os.zig')
-rw-r--r--lib/std/os.zig40
1 files changed, 23 insertions, 17 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig
index 936d31a007..84adbbeeb8 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -64,7 +64,7 @@ pub const system = if (@hasDecl(root, "os") and root.os != @This())
else if (builtin.link_libc)
std.c
else switch (builtin.os.tag) {
- .macosx, .ios, .watchos, .tvos => darwin,
+ .macos, .ios, .watchos, .tvos => darwin,
.freebsd => freebsd,
.linux => linux,
.netbsd => netbsd,
@@ -357,7 +357,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
// Prevents EINVAL.
const max_count = switch (std.Target.current.os.tag) {
.linux => 0x7ffff000,
- .macosx, .ios, .watchos, .tvos => math.maxInt(i32),
+ .macos, .ios, .watchos, .tvos => math.maxInt(i32),
else => math.maxInt(isize),
};
const adjusted_len = math.min(max_count, buf.len);
@@ -585,7 +585,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
/// On these systems, the read races with concurrent writes to the same file descriptor.
pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
const have_pread_but_not_preadv = switch (std.Target.current.os.tag) {
- .windows, .macosx, .ios, .watchos, .tvos => true,
+ .windows, .macos, .ios, .watchos, .tvos => true,
else => false,
};
if (have_pread_but_not_preadv) {
@@ -712,7 +712,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
const max_count = switch (std.Target.current.os.tag) {
.linux => 0x7ffff000,
- .macosx, .ios, .watchos, .tvos => math.maxInt(i32),
+ .macos, .ios, .watchos, .tvos => math.maxInt(i32),
else => math.maxInt(isize),
};
const adjusted_len = math.min(max_count, bytes.len);
@@ -866,7 +866,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
// Prevent EINVAL.
const max_count = switch (std.Target.current.os.tag) {
.linux => 0x7ffff000,
- .macosx, .ios, .watchos, .tvos => math.maxInt(i32),
+ .macos, .ios, .watchos, .tvos => math.maxInt(i32),
else => math.maxInt(isize),
};
const adjusted_len = math.min(max_count, bytes.len);
@@ -918,7 +918,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
/// If `iov.len` is larger than will fit in a `u31`, a partial write will occur.
pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usize {
const have_pwrite_but_not_pwritev = switch (std.Target.current.os.tag) {
- .windows, .macosx, .ios, .watchos, .tvos => true,
+ .windows, .macos, .ios, .watchos, .tvos => true,
else => false,
};
@@ -3124,16 +3124,24 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
}
}
-pub fn waitpid(pid: i32, flags: u32) u32 {
- // TODO allow implicit pointer cast from *u32 to *c_uint ?
+pub const WaitPidResult = struct {
+ pid: pid_t,
+ status: u32,
+};
+
+pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
const Status = if (builtin.link_libc) c_uint else u32;
var status: Status = undefined;
while (true) {
- switch (errno(system.waitpid(pid, &status, flags))) {
- 0 => return @bitCast(u32, status),
+ const rc = system.waitpid(pid, &status, flags);
+ switch (errno(rc)) {
+ 0 => return .{
+ .pid = @intCast(pid_t, rc),
+ .status = @bitCast(u32, status),
+ },
EINTR => continue,
ECHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.
- EINVAL => unreachable, // The options argument was invalid
+ EINVAL => unreachable, // Invalid flags.
else => unreachable,
}
}
@@ -4094,7 +4102,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
const end_index = std.unicode.utf16leToUtf8(out_buffer, wide_slice) catch unreachable;
return out_buffer[0..end_index];
},
- .macosx, .ios, .watchos, .tvos => {
+ .macos, .ios, .watchos, .tvos => {
// On macOS, we can use F_GETPATH fcntl command to query the OS for
// the path to the file descriptor.
@memset(out_buffer, 0, MAX_PATH_BYTES);
@@ -4691,7 +4699,7 @@ pub fn sendfile(
});
const max_count = switch (std.Target.current.os.tag) {
.linux => 0x7ffff000,
- .macosx, .ios, .watchos, .tvos => math.maxInt(i32),
+ .macos, .ios, .watchos, .tvos => math.maxInt(i32),
else => math.maxInt(size_t),
};
@@ -4849,7 +4857,7 @@ pub fn sendfile(
}
}
},
- .macosx, .ios, .tvos, .watchos => sf: {
+ .macos, .ios, .tvos, .watchos => sf: {
var hdtr_data: std.c.sf_hdtr = undefined;
var hdtr: ?*std.c.sf_hdtr = null;
if (headers.len != 0 or trailers.len != 0) {
@@ -5437,9 +5445,7 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
}
}
-pub const SetrlimitError = error{
- PermissionDenied,
-} || UnexpectedError;
+pub const SetrlimitError = error{PermissionDenied} || UnexpectedError;
pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void {
// TODO implement for systems other than linux and enable test