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 standard library.
std › Io › Threaded › processCurrentPath Private Function processCurrentPath Doc Source Private Function std.Io.Threaded.processCurrentPath
fn processCurrentPath (userdata : ?*anyopaque , buffer : []u8 ) process .CurrentPathError !usize Params userdata : ?*anyopaque buffer : []u8 File Io/Threaded.zig: 14145
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183 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 ),
}
}