From bd0b51477a6cb0dc7ea7739f61a70110d39ba601 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 12 Mar 2020 19:40:42 +0100 Subject: Address review comments --- lib/std/os.zig | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'lib/std/os.zig') diff --git a/lib/std/os.zig b/lib/std/os.zig index 62347c2ee9..6614453a38 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -439,11 +439,13 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { } pub const TruncateError = error{ - /// The file descriptor is not open for writing. - NotFile, + FileTooBig, + InputOutput, + CannotTruncate, + FileBusy, } || UnexpectedError; -pub fn truncate(fd: fd_t, length: u64) TruncateError!void { +pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { if (std.Target.current.os.tag == .windows) { try windows.SetFilePointerEx_BEGIN(fd, length); @@ -454,18 +456,22 @@ pub fn truncate(fd: fd_t, length: u64) TruncateError!void { } while (true) { - const rc = if (builtin.link_libc) blk: { + const rc = if (builtin.link_libc) if (std.Target.current.os.tag == .linux) - break :blk system.ftruncate64(fd, @bitCast(off_t, length)) + system.ftruncate64(fd, @bitCast(off_t, length)) else - break :blk system.ftruncate(fd, @bitCast(off_t, length)); - } else + system.ftruncate(fd, @bitCast(off_t, length)) + else system.ftruncate(fd, length); switch (errno(rc)) { 0 => return, EINTR => continue, - EBADF, EINVAL => return error.NotFile, + EFBIG => return error.FileTooBig, + EIO => return error.InputOutput, + EPERM => return error.CannotTruncate, + ETXTBSY => return error.FileBusy, + EBADF, EINVAL => unreachable, else => |err| return unexpectedErrno(err), } } -- cgit v1.2.3