Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › Io/ › Threaded.zig › processCurrentPath
processCurrentPath
Threaded.processCurrentPath
fn processCurrentPath (userdata : ?*anyopaque , buffer : []u8 ) process .CurrentPathError !usize
File
Code
fn processCurrentPath (userdata : ?*anyopaque , buffer : []u8 ) process .CurrentPathError !usize {
const t : *Threaded = @ptrCast (@alignCast (userdata ));
_ = t ;
if (is_windows ) {
var wtf16le_buf : [windows .PATH_MAX_WIDE :0 ]u16 = undefined ;
const n = windows .ntdll .RtlGetCurrentDirectory_U (wtf16le_buf .len * 2 + 2 , &wtf16le_buf ) / 2 ;
if (n == 0 ) return error .Unexpected ;
assert (n <= wtf16le_buf .len );
const wtf16le_slice = wtf16le_buf [0 ..n ];
var end_index : usize = 0 ;
var it = std .unicode .Wtf16LeIterator .init (wtf16le_slice );
while (it .nextCodepoint ()) |codepoint | {
const seq_len = std .unicode .utf8CodepointSequenceLength (codepoint ) catch unreachable ;
if (end_index + seq_len >= buffer .len )
return error .NameTooLong ;
end_index += std .unicode .wtf8Encode (codepoint , buffer [end_index ..]) catch unreachable ;
}
return end_index ;
} else if (native_os == .wasi and !builtin .link_libc ) {
if (buffer .len == 0 ) return error .NameTooLong ;
buffer [0 ] = '.' ;
return 1 ;
}
const err : posix .E = if (builtin .link_libc ) err : {
const c_err = if (std .c .getcwd (buffer .ptr , buffer .len )) |_ | 0 else std .c ._errno ().*;
break :err @fromBackingInt (@intCast (c_err ));
} else err : {
break :err posix .errno (posix .system .getcwd (buffer .ptr , buffer .len ));
};
switch (err ) {
.SUCCESS => return std .mem .findScalar (u8 , buffer , 0 ).?,
.NOENT => return error .CurrentDirUnlinked ,
.RANGE => return error .NameTooLong ,
.FAULT => |e | return errnoBug (e ),
.INVAL => |e | return errnoBug (e ),
else => return posix .unexpectedErrno (err ),
}
}