aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os/linux.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-03-13 15:17:53 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-03-13 15:17:53 -0400
commit656ba530d80e67bc7bb9c40e5c2db26a40743a15 (patch)
tree767f4d57000922cf122ae965dc825f87c62ec64e /lib/std/os/linux.zig
parent96c07674fc2293fa040212ab797c05436dc515b1 (diff)
parent3eff77bfb52accbc16eb831753ff4917fc2b4873 (diff)
downloadzig-656ba530d80e67bc7bb9c40e5c2db26a40743a15.tar.gz
zig-656ba530d80e67bc7bb9c40e5c2db26a40743a15.zip
Merge remote-tracking branch 'origin/master' into llvm10
Diffstat (limited to 'lib/std/os/linux.zig')
-rw-r--r--lib/std/os/linux.zig66
1 files changed, 64 insertions, 2 deletions
diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig
index 719e541846..ba7356d62c 100644
--- a/lib/std/os/linux.zig
+++ b/lib/std/os/linux.zig
@@ -350,7 +350,13 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
);
}
} else {
- return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
+ return syscall4(
+ SYS_pread,
+ @bitCast(usize, @as(isize, fd)),
+ @ptrToInt(buf),
+ count,
+ offset,
+ );
}
}
@@ -384,8 +390,64 @@ pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
return syscall3(SYS_write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
}
+pub fn ftruncate(fd: i32, length: u64) usize {
+ if (@hasDecl(@This(), "SYS_ftruncate64")) {
+ if (require_aligned_register_pair) {
+ return syscall4(
+ SYS_ftruncate64,
+ @bitCast(usize, @as(isize, fd)),
+ 0,
+ @truncate(usize, length),
+ @truncate(usize, length >> 32),
+ );
+ } else {
+ return syscall3(
+ SYS_ftruncate64,
+ @bitCast(usize, @as(isize, fd)),
+ @truncate(usize, length),
+ @truncate(usize, length >> 32),
+ );
+ }
+ } else {
+ return syscall2(
+ SYS_ftruncate,
+ @bitCast(usize, @as(isize, fd)),
+ @truncate(usize, length),
+ );
+ }
+}
+
pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
- return syscall4(SYS_pwrite, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
+ if (@hasDecl(@This(), "SYS_pwrite64")) {
+ if (require_aligned_register_pair) {
+ return syscall6(
+ SYS_pwrite64,
+ @bitCast(usize, @as(isize, fd)),
+ @ptrToInt(buf),
+ count,
+ 0,
+ @truncate(usize, offset),
+ @truncate(usize, offset >> 32),
+ );
+ } else {
+ return syscall5(
+ SYS_pwrite64,
+ @bitCast(usize, @as(isize, fd)),
+ @ptrToInt(buf),
+ count,
+ @truncate(usize, offset),
+ @truncate(usize, offset >> 32),
+ );
+ }
+ } else {
+ return syscall4(
+ SYS_pwrite,
+ @bitCast(usize, @as(isize, fd)),
+ @ptrToInt(buf),
+ count,
+ offset,
+ );
+ }
}
pub fn rename(old: [*:0]const u8, new: [*:0]const u8) usize {