aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os/linux.zig
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2020-03-11 20:56:43 +0100
committerLemonBoy <thatlemon@gmail.com>2020-03-12 09:43:45 +0100
commit11df0d0cf8c786d5b502c21a42d47631657a42f4 (patch)
treeb860be3c40159ad2ea9c41f44c3873d1b29e33bb /lib/std/os/linux.zig
parent89d7fc773d66609a8d93106f9a6d84d479771690 (diff)
downloadzig-11df0d0cf8c786d5b502c21a42d47631657a42f4.tar.gz
zig-11df0d0cf8c786d5b502c21a42d47631657a42f4.zip
std: Add setEndPos to fs.file
Allow the user to shrink/grow the file size as needed.
Diffstat (limited to 'lib/std/os/linux.zig')
-rw-r--r--lib/std/os/linux.zig27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig
index 79f9ba9c95..ba7356d62c 100644
--- a/lib/std/os/linux.zig
+++ b/lib/std/os/linux.zig
@@ -390,6 +390,33 @@ 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 {
if (@hasDecl(@This(), "SYS_pwrite64")) {
if (require_aligned_register_pair) {