-
Notifications
You must be signed in to change notification settings - Fork 547
/
Copy pathio.zig
34 lines (30 loc) · 1.2 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
33
34
const std = @import("std");
const builtin = @import("builtin");
const os = std.os;
const IO_Linux = @import("io/linux.zig").IO;
const IO_Darwin = @import("io/darwin.zig").IO;
const IO_Windows = @import("io/windows.zig").IO;
pub const IO = switch (builtin.target.os.tag) {
.linux => IO_Linux,
.windows => IO_Windows,
.macos, .tvos, .watchos, .ios => IO_Darwin,
else => @compileError("IO is not supported for platform"),
};
pub const DirectIO = enum {
direct_io_required,
direct_io_optional,
direct_io_disabled,
};
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);
}