mirror of
https://github.com/ziglang/zig.git
synced 2025-12-12 17:23:09 +00:00
std.posix.ftruncate: handle NonResizable properly
This commit is contained in:
parent
8752d80c84
commit
733b208256
@ -2029,7 +2029,10 @@ pub const Writer = struct {
|
|||||||
switch (w.mode) {
|
switch (w.mode) {
|
||||||
.positional,
|
.positional,
|
||||||
.positional_reading,
|
.positional_reading,
|
||||||
=> try w.file.setEndPos(w.pos),
|
=> w.file.setEndPos(w.pos) catch |err| switch (err) {
|
||||||
|
error.NonResizable => return,
|
||||||
|
else => |e| return e,
|
||||||
|
},
|
||||||
|
|
||||||
.streaming,
|
.streaming,
|
||||||
.streaming_reading,
|
.streaming_reading,
|
||||||
|
|||||||
@ -1052,6 +1052,7 @@ pub const TruncateError = error{
|
|||||||
FileBusy,
|
FileBusy,
|
||||||
AccessDenied,
|
AccessDenied,
|
||||||
PermissionDenied,
|
PermissionDenied,
|
||||||
|
NonResizable,
|
||||||
} || UnexpectedError;
|
} || UnexpectedError;
|
||||||
|
|
||||||
/// Length must be positive when treated as an i64.
|
/// Length must be positive when treated as an i64.
|
||||||
@ -1091,7 +1092,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
|
|||||||
.PERM => return error.PermissionDenied,
|
.PERM => return error.PermissionDenied,
|
||||||
.TXTBSY => return error.FileBusy,
|
.TXTBSY => return error.FileBusy,
|
||||||
.BADF => unreachable, // Handle not open for writing
|
.BADF => unreachable, // Handle not open for writing
|
||||||
.INVAL => unreachable, // Handle not open for writing, negative length, or non-resizable handle
|
.INVAL => return error.NonResizable,
|
||||||
.NOTCAPABLE => return error.AccessDenied,
|
.NOTCAPABLE => return error.AccessDenied,
|
||||||
else => |err| return unexpectedErrno(err),
|
else => |err| return unexpectedErrno(err),
|
||||||
}
|
}
|
||||||
@ -1107,7 +1108,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
|
|||||||
.PERM => return error.PermissionDenied,
|
.PERM => return error.PermissionDenied,
|
||||||
.TXTBSY => return error.FileBusy,
|
.TXTBSY => return error.FileBusy,
|
||||||
.BADF => unreachable, // Handle not open for writing
|
.BADF => unreachable, // Handle not open for writing
|
||||||
.INVAL => unreachable, // Handle not open for writing, negative length, or non-resizable handle
|
.INVAL => return error.NonResizable, // This is returned for /dev/null for example.
|
||||||
else => |err| return unexpectedErrno(err),
|
else => |err| return unexpectedErrno(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user