mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.process: Actually use explicit GetCwdError/GetCwdAllocError sets
Also fix GetCwdAllocError to include only the set of possible errors.
This commit is contained in:
parent
fb1bd78908
commit
26afcdb7fe
1 changed files with 4 additions and 3 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue