-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.zig
32 lines (28 loc) · 1.14 KB
/
io.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const os = std.os;
const FIFO = @import("fifo.zig").FIFO;
const IO_Linux = @import("io/linux.zig").IO;
const IO_Darwin = @import("io/darwin.zig").IO;
pub const IO = switch (builtin.target.os.tag) {
.linux => IO_Linux,
.macos, .tvos, .watchos, .ios => IO_Darwin,
else => @compileError("IO is not supported for platform"),
};
pub fn buffer_limit(buffer_len: usize) usize {
// Linux limits how much may be written in a `pwrite()/pread()` call, which is `0x7ffff000` on
// both 64-bit and 32-bit systems, due to using a signed C int as the return value, as well as
// stuffing the errno codes into the last `4096` values.
// Darwin limits writes to `0x7fffffff` bytes, more than that returns `EINVAL`.
// The corresponding POSIX limit is `std.math.maxInt(isize)`.
const limit = switch (builtin.target.os.tag) {
.linux => 0x7ffff000,
.macos, .ios, .watchos, .tvos => std.math.maxInt(i32),
else => std.math.maxInt(isize),
};
return @min(limit, buffer_len);
}
test "I/O" {
_ = @import("io/test.zig");
}