| ... | @@ -355,7 +355,7 @@ pub const GetEnvVarOwnedError = error{ | ... | @@ -355,7 +355,7 @@ pub const GetEnvVarOwnedError = error{ |
| 355 | }; | 355 | }; |
| 356 | | 356 | |
| 357 | /// Caller must free returned memory. | 357 | /// Caller must free returned memory. |
| 358 | pub fn getEnvVarOwned(allocator: mem.Allocator, key: []const u8) GetEnvVarOwnedError![]u8 { | 358 | pub fn getEnvVarOwned(allocator: Allocator, key: []const u8) GetEnvVarOwnedError![]u8 { |
| 359 | if (builtin.os.tag == .windows) { | 359 | if (builtin.os.tag == .windows) { |
| 360 | const result_w = blk: { | 360 | const result_w = blk: { |
| 361 | const key_w = try std.unicode.utf8ToUtf16LeWithNull(allocator, key); | 361 | const key_w = try std.unicode.utf8ToUtf16LeWithNull(allocator, key); |
| ... | @@ -430,7 +430,7 @@ pub const ArgIteratorPosix = struct { | ... | @@ -430,7 +430,7 @@ pub const ArgIteratorPosix = struct { |
| 430 | }; | 430 | }; |
| 431 | | 431 | |
| 432 | pub const ArgIteratorWasi = struct { | 432 | pub const ArgIteratorWasi = struct { |
| 433 | allocator: mem.Allocator, | 433 | allocator: Allocator, |
| 434 | index: usize, | 434 | index: usize, |
| 435 | args: [][:0]u8, | 435 | args: [][:0]u8, |
| 436 | | 436 | |
| ... | @@ -438,7 +438,7 @@ pub const ArgIteratorWasi = struct { | ... | @@ -438,7 +438,7 @@ pub const ArgIteratorWasi = struct { |
| 438 | | 438 | |
| 439 | /// You must call deinit to free the internal buffer of the | 439 | /// You must call deinit to free the internal buffer of the |
| 440 | /// iterator after you are done. | 440 | /// iterator after you are done. |
| 441 | pub fn init(allocator: mem.Allocator) InitError!ArgIteratorWasi { | 441 | pub fn init(allocator: Allocator) InitError!ArgIteratorWasi { |
| 442 | const fetched_args = try ArgIteratorWasi.internalInit(allocator); | 442 | const fetched_args = try ArgIteratorWasi.internalInit(allocator); |
| 443 | return ArgIteratorWasi{ | 443 | return ArgIteratorWasi{ |
| 444 | .allocator = allocator, | 444 | .allocator = allocator, |
| ... | @@ -447,7 +447,7 @@ pub const ArgIteratorWasi = struct { | ... | @@ -447,7 +447,7 @@ pub const ArgIteratorWasi = struct { |
| 447 | }; | 447 | }; |
| 448 | } | 448 | } |
| 449 | | 449 | |
| 450 | fn internalInit(allocator: mem.Allocator) InitError![][:0]u8 { | 450 | fn internalInit(allocator: Allocator) InitError![][:0]u8 { |
| 451 | const w = os.wasi; | 451 | const w = os.wasi; |
| 452 | var count: usize = undefined; | 452 | var count: usize = undefined; |
| 453 | var buf_size: usize = undefined; | 453 | var buf_size: usize = undefined; |
| ... | @@ -760,7 +760,7 @@ pub const ArgIterator = struct { | ... | @@ -760,7 +760,7 @@ pub const ArgIterator = struct { |
| 760 | }; | 760 | }; |
| 761 | | 761 | |
| 762 | /// You must deinitialize iterator's internal buffers by calling `deinit` when done. | 762 | /// You must deinitialize iterator's internal buffers by calling `deinit` when done. |
| 763 | pub fn initWithAllocator(allocator: mem.Allocator) InitError!ArgIterator { | 763 | pub fn initWithAllocator(allocator: Allocator) InitError!ArgIterator { |
| 764 | if (builtin.os.tag == .wasi and !builtin.link_libc) { | 764 | if (builtin.os.tag == .wasi and !builtin.link_libc) { |
| 765 | return ArgIterator{ .inner = try InnerType.init(allocator) }; | 765 | return ArgIterator{ .inner = try InnerType.init(allocator) }; |
| 766 | } | 766 | } |
| ... | @@ -804,7 +804,7 @@ pub fn args() ArgIterator { | ... | @@ -804,7 +804,7 @@ pub fn args() ArgIterator { |
| 804 | } | 804 | } |
| 805 | | 805 | |
| 806 | /// You must deinitialize iterator's internal buffers by calling `deinit` when done. | 806 | /// You must deinitialize iterator's internal buffers by calling `deinit` when done. |
| 807 | pub fn argsWithAllocator(allocator: mem.Allocator) ArgIterator.InitError!ArgIterator { | 807 | pub fn argsWithAllocator(allocator: Allocator) ArgIterator.InitError!ArgIterator { |
| 808 | return ArgIterator.initWithAllocator(allocator); | 808 | return ArgIterator.initWithAllocator(allocator); |
| 809 | } | 809 | } |
| 810 | | 810 | |
| ... | @@ -827,7 +827,7 @@ test "args iterator" { | ... | @@ -827,7 +827,7 @@ test "args iterator" { |
| 827 | } | 827 | } |
| 828 | | 828 | |
| 829 | /// Caller must call argsFree on result. | 829 | /// Caller must call argsFree on result. |
| 830 | pub fn argsAlloc(allocator: mem.Allocator) ![][:0]u8 { | 830 | pub fn argsAlloc(allocator: Allocator) ![][:0]u8 { |
| 831 | // TODO refactor to only make 1 allocation. | 831 | // TODO refactor to only make 1 allocation. |
| 832 | var it = try argsWithAllocator(allocator); | 832 | var it = try argsWithAllocator(allocator); |
| 833 | defer it.deinit(); | 833 | defer it.deinit(); |
| ... | @@ -864,7 +864,7 @@ pub fn argsAlloc(allocator: mem.Allocator) ![][:0]u8 { | ... | @@ -864,7 +864,7 @@ pub fn argsAlloc(allocator: mem.Allocator) ![][:0]u8 { |
| 864 | return result_slice_list; | 864 | return result_slice_list; |
| 865 | } | 865 | } |
| 866 | | 866 | |
| 867 | pub fn argsFree(allocator: mem.Allocator, args_alloc: []const [:0]u8) void { | 867 | pub fn argsFree(allocator: Allocator, args_alloc: []const [:0]u8) void { |
| 868 | var total_bytes: usize = 0; | 868 | var total_bytes: usize = 0; |
| 869 | for (args_alloc) |arg| { | 869 | for (args_alloc) |arg| { |
| 870 | total_bytes += @sizeOf([]u8) + arg.len + 1; | 870 | total_bytes += @sizeOf([]u8) + arg.len + 1; |
| ... | @@ -1089,7 +1089,7 @@ pub const ExecvError = std.os.ExecveError || error{OutOfMemory}; | ... | @@ -1089,7 +1089,7 @@ pub const ExecvError = std.os.ExecveError || error{OutOfMemory}; |
| 1089 | /// This function also uses the PATH environment variable to get the full path to the executable. | 1089 | /// This function also uses the PATH environment variable to get the full path to the executable. |
| 1090 | /// Due to the heap-allocation, it is illegal to call this function in a fork() child. | 1090 | /// Due to the heap-allocation, it is illegal to call this function in a fork() child. |
| 1091 | /// For that use case, use the `std.os` functions directly. | 1091 | /// For that use case, use the `std.os` functions directly. |
| 1092 | pub fn execv(allocator: mem.Allocator, argv: []const []const u8) ExecvError { | 1092 | pub fn execv(allocator: Allocator, argv: []const []const u8) ExecvError { |
| 1093 | return execve(allocator, argv, null); | 1093 | return execve(allocator, argv, null); |
| 1094 | } | 1094 | } |
| 1095 | | 1095 | |
| ... | @@ -1102,7 +1102,7 @@ pub fn execv(allocator: mem.Allocator, argv: []const []const u8) ExecvError { | ... | @@ -1102,7 +1102,7 @@ pub fn execv(allocator: mem.Allocator, argv: []const []const u8) ExecvError { |
| 1102 | /// Due to the heap-allocation, it is illegal to call this function in a fork() child. | 1102 | /// Due to the heap-allocation, it is illegal to call this function in a fork() child. |
| 1103 | /// For that use case, use the `std.os` functions directly. | 1103 | /// For that use case, use the `std.os` functions directly. |
| 1104 | pub fn execve( | 1104 | pub fn execve( |
| 1105 | allocator: mem.Allocator, | 1105 | allocator: Allocator, |
| 1106 | argv: []const []const u8, | 1106 | argv: []const []const u8, |
| 1107 | env_map: ?*const EnvMap, | 1107 | env_map: ?*const EnvMap, |
| 1108 | ) ExecvError { | 1108 | ) ExecvError { |