std.process: Actually use explicit GetCwdError/GetCwdAllocError sets

Also fix GetCwdAllocError to include only the set of possible errors.
This commit is contained in:
Ryan Liptak 2025-11-19 04:09:54 -08:00
parent fb1bd78908
commit 26afcdb7fe

View file

@ -22,16 +22,17 @@ pub const GetCwdError = posix.GetCwdError;
/// The result is a slice of `out_buffer`, from index `0`. /// The result is a slice of `out_buffer`, from index `0`.
/// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/). /// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/).
/// On other platforms, the result is an opaque sequence of bytes with no particular encoding. /// On other platforms, the result is an opaque sequence of bytes with no particular encoding.
pub fn getCwd(out_buffer: []u8) ![]u8 { pub fn getCwd(out_buffer: []u8) GetCwdError![]u8 {
return posix.getcwd(out_buffer); return posix.getcwd(out_buffer);
} }
pub const GetCwdAllocError = Allocator.Error || posix.GetCwdError; // Same as GetCwdError, minus error.NameTooLong + Allocator.Error
pub const GetCwdAllocError = Allocator.Error || error{CurrentWorkingDirectoryUnlinked} || posix.UnexpectedError;
/// Caller must free the returned memory. /// Caller must free the returned memory.
/// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/). /// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/).
/// On other platforms, the result is an opaque sequence of bytes with no particular encoding. /// On other platforms, the result is an opaque sequence of bytes with no particular encoding.
pub fn getCwdAlloc(allocator: Allocator) ![]u8 { pub fn getCwdAlloc(allocator: Allocator) GetCwdAllocError![]u8 {
// The use of max_path_bytes here is just a heuristic: most paths will fit // The use of max_path_bytes here is just a heuristic: most paths will fit
// in stack_buf, avoiding an extra allocation in the common case. // in stack_buf, avoiding an extra allocation in the common case.
var stack_buf: [fs.max_path_bytes]u8 = undefined; var stack_buf: [fs.max_path_bytes]u8 = undefined;