authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-21 14:57:59-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-21 14:57:59-07:00
logc02d39a21c9e6bd73f6ccc388c4ae2f5db173930
treeaf5f896976e7932b722760aae71cfcda471568a9
parentc00966d11d8eabcb9bc4724bb98eb6bd588fe3f3

std.Io.File: explain rationale for no Dir.setLength

closes #35353

1 files changed, 6 insertions(+), 0 deletions(-)

lib/std/Io/File.zig+6
...@@ -268,6 +268,12 @@ pub const SetLengthError = error{...@@ -268,6 +268,12 @@ pub const SetLengthError = error{
268/// Truncates or expands the file, populating any new data with zeroes.268/// Truncates or expands the file, populating any new data with zeroes.
269///269///
270/// The file offset after this call is left unchanged.270/// The file offset after this call is left unchanged.
271///
272/// This function operates on an open file handle. There is not an equivalent
273/// function in `Dir` which operates on paths because generally, such
274/// functionality will introduce Time-Of-Check, Time-Of-Use (TOCTOU) bugs. In
275/// the rare case when those semantics are actually needed, it is reasonable to
276/// open the file with the truncate flag.
271pub fn setLength(file: File, io: Io, new_length: u64) SetLengthError!void {277pub fn setLength(file: File, io: Io, new_length: u64) SetLengthError!void {
272 return io.vtable.fileSetLength(io.userdata, file, new_length);278 return io.vtable.fileSetLength(io.userdata, file, new_length);
273}279}