diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-03-12 19:40:42 +0100 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2020-03-12 19:40:42 +0100 |
| commit | bd0b51477a6cb0dc7ea7739f61a70110d39ba601 (patch) | |
| tree | a323e5300f31f73132ab371b8475ee42c219dbb2 /lib/std/os.zig | |
| parent | 11df0d0cf8c786d5b502c21a42d47631657a42f4 (diff) | |
| download | zig-bd0b51477a6cb0dc7ea7739f61a70110d39ba601.tar.gz zig-bd0b51477a6cb0dc7ea7739f61a70110d39ba601.zip | |
Address review comments
Diffstat (limited to 'lib/std/os.zig')
| -rw-r--r-- | lib/std/os.zig | 22 |
1 files changed, 14 insertions, 8 deletions
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), } } |
