| ... | @@ -15,7 +15,7 @@ block: Block, | ... | @@ -15,7 +15,7 @@ block: Block, |
| 15 | | 15 | |
| 16 | pub const Block = switch (native_os) { | 16 | pub const Block = switch (native_os) { |
| 17 | .windows => []const u16, | 17 | .windows => []const u16, |
| 18 | else => []const [*:0]const u8, | 18 | else => [:null]const ?[*:0]const u8, |
| 19 | }; | 19 | }; |
| 20 | | 20 | |
| 21 | pub const Map = struct { | 21 | pub const Map = struct { |
| ... | @@ -364,7 +364,8 @@ pub fn createMap(env: Environ, allocator: Allocator) CreateMapError!Map { | ... | @@ -364,7 +364,8 @@ pub fn createMap(env: Environ, allocator: Allocator) CreateMapError!Map { |
| 364 | } | 364 | } |
| 365 | return result; | 365 | return result; |
| 366 | } else { | 366 | } else { |
| 367 | for (env.block) |line| { | 367 | for (env.block) |opt_line| { |
| | 368 | const line = opt_line.?; |
| 368 | var line_i: usize = 0; | 369 | var line_i: usize = 0; |
| 369 | while (line[line_i] != 0 and line[line_i] != '=') : (line_i += 1) {} | 370 | while (line[line_i] != 0 and line[line_i] != '=') : (line_i += 1) {} |
| 370 | const key = line[0..line_i]; | 371 | const key = line[0..line_i]; |
| ... | @@ -579,15 +580,10 @@ pub const CreateBlockOptions = struct { | ... | @@ -579,15 +580,10 @@ pub const CreateBlockOptions = struct { |
| 579 | /// Creates a null-delimited environment variable block in the format expected | 580 | /// Creates a null-delimited environment variable block in the format expected |
| 580 | /// by POSIX, from a different one. | 581 | /// by POSIX, from a different one. |
| 581 | pub fn createBlock(existing: Environ, arena: Allocator, options: CreateBlockOptions) Allocator.Error![:null]?[*:0]u8 { | 582 | pub fn createBlock(existing: Environ, arena: Allocator, options: CreateBlockOptions) Allocator.Error![:null]?[*:0]u8 { |
| 582 | const existing_block: [*:null]const ?[*:0]const u8 = @ptrCast(existing.block); | 583 | const contains_zig_progress = for (existing.block) |opt_line| { |
| 583 | const existing_count, const contains_zig_progress = c: { | 584 | if (mem.eql(u8, mem.sliceTo(opt_line.?, '='), "ZIG_PROGRESS")) break true; |
| 584 | var count: usize = 0; | 585 | } else false; |
| 585 | var contains = false; | 586 | |
| 586 | while (existing_block[count]) |line| : (count += 1) { | | |
| 587 | contains = contains or mem.eql(u8, mem.sliceTo(line, '='), "ZIG_PROGRESS"); | | |
| 588 | } | | |
| 589 | break :c .{ count, contains }; | | |
| 590 | }; | | |
| 591 | const ZigProgressAction = enum { nothing, edit, delete, add }; | 587 | const ZigProgressAction = enum { nothing, edit, delete, add }; |
| 592 | const zig_progress_action: ZigProgressAction = a: { | 588 | const zig_progress_action: ZigProgressAction = a: { |
| 593 | const fd = options.zig_progress_fd orelse break :a .nothing; | 589 | const fd = options.zig_progress_fd orelse break :a .nothing; |
| ... | @@ -600,7 +596,7 @@ pub fn createBlock(existing: Environ, arena: Allocator, options: CreateBlockOpti | ... | @@ -600,7 +596,7 @@ pub fn createBlock(existing: Environ, arena: Allocator, options: CreateBlockOpti |
| 600 | }; | 596 | }; |
| 601 | | 597 | |
| 602 | const envp_count: usize = c: { | 598 | const envp_count: usize = c: { |
| 603 | var count: usize = existing_count; | 599 | var count: usize = existing.block.len; |
| 604 | switch (zig_progress_action) { | 600 | switch (zig_progress_action) { |
| 605 | .add => count += 1, | 601 | .add => count += 1, |
| 606 | .delete => count -= 1, | 602 | .delete => count -= 1, |
| ... | @@ -618,7 +614,7 @@ pub fn createBlock(existing: Environ, arena: Allocator, options: CreateBlockOpti | ... | @@ -618,7 +614,7 @@ pub fn createBlock(existing: Environ, arena: Allocator, options: CreateBlockOpti |
| 618 | i += 1; | 614 | i += 1; |
| 619 | } | 615 | } |
| 620 | | 616 | |
| 621 | while (existing_block[existing_index]) |line| : (existing_index += 1) { | 617 | while (existing.block[existing_index]) |line| : (existing_index += 1) { |
| 622 | if (mem.eql(u8, mem.sliceTo(line, '='), "ZIG_PROGRESS")) switch (zig_progress_action) { | 618 | if (mem.eql(u8, mem.sliceTo(line, '='), "ZIG_PROGRESS")) switch (zig_progress_action) { |
| 623 | .add => unreachable, | 619 | .add => unreachable, |
| 624 | .delete => continue, | 620 | .delete => continue, |