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 › Dispatch › execv Private Function execv Doc Source Private Function std.Io.Dispatch.execv
fn execv (
ev : *Evented ,
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 ev : *Evented arg0_expand : process .ArgExpansion file : [*:0 ]const u8 child_argv : [*:null ]?[*:0 ]const u8 env_block : process .Environ .PosixBlock PATH : []const u8 File Io/Dispatch.zig: 4490
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536 fn execv (
ev : *Evented ,
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 ev .execvPath (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 : [c .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 = ev .execvPath (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 ;
}