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 › posixExecv Private Function posixExecv Doc Source Private Function std.Io.Threaded.posixExecv
fn posixExecv (
arg0_expand : process .ArgExpansion ,
file : [*:0 ]const u8 ,
child_argv : [*:null ]?[*:0 ]const u8 ,
env_block : process .Environ .PosixBlock ,
PATH : []const u8 ,
) process .ReplaceError Params arg0_expand : process .ArgExpansion file : [*:0 ]const u8 child_argv : [*:null ]?[*:0 ]const u8 env_block : process .Environ .PosixBlock PATH : []const u8 File Io/Threaded.zig: 17030
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075 fn posixExecv (
arg0_expand : process .ArgExpansion ,
file : [*:0 ]const u8 ,
child_argv : [*:null ]?[*:0 ]const u8 ,
env_block : process .Environ .PosixBlock ,
PATH : []const u8 ,
) process .ReplaceError {
const file_slice = std .mem .sliceTo (file , 0 );
if (std .mem .findScalar (u8 , file_slice , '/' ) != null ) return posixExecvPath (file , child_argv , env_block );
// Use of PATH_MAX here is valid as the path_buf will be passed
// directly to the operating system in posixExecvPath.
var path_buf : [posix .PATH_MAX ]u8 = undefined ;
var it = std .mem .tokenizeScalar (u8 , PATH , ':' );
var seen_eacces = false ;
var err : process .ReplaceError = error .FileNotFound ;
// In case of expanding arg0 we must put it back if we return with an error.
const prev_arg0 = child_argv [0 ];
defer switch (arg0_expand ) {
.expand => child_argv [0 ] = prev_arg0 ,
.no_expand => {},
};
while (it .next ()) |search_path | {
const path_len = search_path .len + file_slice .len + 1 ;
if (path_buf .len < path_len + 1 ) return error .NameTooLong ;
@memcpy (path_buf [0 ..search_path .len ], search_path );
path_buf [search_path .len ] = '/' ;
@memcpy (path_buf [search_path .len + 1 ..][0 ..file_slice .len ], file_slice );
path_buf [path_len ] = 0 ;
const full_path = path_buf [0 ..path_len :0 ].ptr ;
switch (arg0_expand ) {
.expand => child_argv [0 ] = full_path ,
.no_expand => {},
}
err = posixExecvPath (full_path , child_argv , env_block );
switch (err ) {
error .AccessDenied => seen_eacces = true ,
error .FileNotFound , error .NotDir => {},
else => |e | return e ,
}
}
if (seen_eacces ) return error .AccessDenied ;
return err ;
}