Skip to content

Instantly share code, notes, and snippets.

@LemonBoy
Created September 25, 2019 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LemonBoy/ff7b0fdfc6bc5e545ee436a7d4663dd1 to your computer and use it in GitHub Desktop.
Save LemonBoy/ff7b0fdfc6bc5e545ee436a7d4663dd1 to your computer and use it in GitHub Desktop.
diff --git a/std/c.zig b/std/c.zig
index bd7e9b64..5d417e9a 100644
--- a/std/c.zig
+++ b/std/c.zig
@@ -70,13 +70,13 @@ pub extern "c" fn raise(sig: c_int) c_int;
pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize;
pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize;
pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: u64) isize;
-pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: usize) isize;
+pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: off_t) isize;
pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize;
-pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: usize) isize;
+pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: off_t) isize;
pub extern "c" fn stat(noalias path: [*]const u8, noalias buf: *Stat) c_int;
pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;
pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: u64) isize;
-pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: isize) *c_void;
+pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: off_t) *c_void;
pub extern "c" fn munmap(addr: *align(page_size) c_void, len: usize) c_int;
pub extern "c" fn mprotect(addr: *align(page_size) c_void, len: usize, prot: c_uint) c_int;
pub extern "c" fn unlink(path: [*]const u8) c_int;
diff --git a/std/os.zig b/std/os.zig
index d29c7d3c..6b399810 100644
--- a/std/os.zig
+++ b/std/os.zig
@@ -359,7 +359,8 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) ReadError!usize {
}
while (true) {
// TODO handle the case when iov_len is too large and get rid of this @intCast
- const rc = system.preadv(fd, iov.ptr, @intCast(u32, iov.len), offset);
+ const ipos = @bitCast(i64, offset);
+ const rc = system.preadv(fd, iov.ptr, @intCast(u32, iov.len), ipos);
switch (errno(rc)) {
0 => return @bitCast(usize, rc),
EINTR => continue,
@@ -513,7 +514,8 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) WriteError!void
while (true) {
// TODO handle the case when iov_len is too large and get rid of this @intCast
- const rc = system.pwritev(fd, iov.ptr, @intCast(u32, iov.len), offset);
+ const ipos = @bitCast(i64, offset);
+ const rc = system.pwritev(fd, iov.ptr, @intCast(u32, iov.len), ipos);
switch (errno(rc)) {
0 => return,
EINTR => continue,
diff --git a/std/os/linux.zig b/std/os/linux.zig
index 375c7eba..2c5936b2 100644
--- a/std/os/linux.zig
+++ b/std/os/linux.zig
@@ -210,25 +210,25 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
return syscall3(SYS_read, @bitCast(usize, isize(fd)), @ptrToInt(buf), count);
}
-pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
+pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize {
return syscall5(
SYS_preadv,
@bitCast(usize, isize(fd)),
@ptrToInt(iov),
count,
- @truncate(usize, offset),
- @truncate(usize, offset >> 32),
+ @truncate(usize, @bitCast(u64, offset)),
+ @truncate(usize, @bitCast(u64, offset) >> 32),
);
}
-pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {
+pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: i64, flags: kernel_rwf) usize {
return syscall6(
SYS_preadv2,
@bitCast(usize, isize(fd)),
@ptrToInt(iov),
count,
- @truncate(usize, offset),
- @truncate(usize, offset >> 32),
+ @truncate(usize, @bitCast(u64, offset)),
+ @truncate(usize, @bitCast(u64, offset) >> 32),
flags,
);
}
@@ -241,25 +241,25 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
return syscall3(SYS_writev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count);
}
-pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {
+pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) usize {
return syscall5(
SYS_pwritev,
@bitCast(usize, isize(fd)),
@ptrToInt(iov),
count,
- @truncate(usize, offset),
- @truncate(usize, offset >> 32),
+ @truncate(usize, @bitCast(u64, offset)),
+ @truncate(usize, @bitCast(u64, offset) >> 32),
);
}
-pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {
+pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64, flags: kernel_rwf) usize {
return syscall6(
SYS_pwritev2,
@bitCast(usize, isize(fd)),
@ptrToInt(iov),
count,
- @truncate(usize, offset),
- @truncate(usize, offset >> 32),
+ @truncate(usize, @bitCast(u64, offset)),
+ @truncate(usize, @bitCast(u64, offset) >> 32),
flags,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment