diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-07-09 12:12:37 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-07-09 12:12:37 -0400 |
| commit | 05f1ea33d2d2f4ffa2bb6686a6a938d1b7983074 (patch) | |
| tree | 4c756014c37eb0299914b155193b6b2ba04dc652 /std/os | |
| parent | 2ee67b7642cfeef36d8ebbc08080202b5b1d1958 (diff) | |
| download | zig-05f1ea33d2d2f4ffa2bb6686a6a938d1b7983074.tar.gz zig-05f1ea33d2d2f4ffa2bb6686a6a938d1b7983074.zip | |
ZIG_DEBUG_COLOR=1 overrides tty detection for runtime stack traces
Diffstat (limited to 'std/os')
| -rw-r--r-- | std/os/index.zig | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/std/os/index.zig b/std/os/index.zig index 52b36c351c..0f9aea914d 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -544,8 +544,13 @@ pub fn getEnvPosix(key: []const u8) ?[]const u8 { return null; } +pub const GetEnvVarOwnedError = error{ + OutOfMemory, + EnvironmentVariableNotFound, +}; + /// Caller must free returned memory. -pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) ![]u8 { +pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwnedError![]u8 { if (is_windows) { const key_with_null = try cstr.addNullByte(allocator, key); defer allocator.free(key_with_null); @@ -554,14 +559,17 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) ![]u8 { errdefer allocator.free(buf); while (true) { - const windows_buf_len = try math.cast(windows.DWORD, buf.len); + const windows_buf_len = math.cast(windows.DWORD, buf.len) catch return error.OutOfMemory; const result = windows.GetEnvironmentVariableA(key_with_null.ptr, buf.ptr, windows_buf_len); if (result == 0) { const err = windows.GetLastError(); return switch (err) { windows.ERROR.ENVVAR_NOT_FOUND => error.EnvironmentVariableNotFound, - else => unexpectedErrorWindows(err), + else => { + _ = unexpectedErrorWindows(err); + return error.EnvironmentVariableNotFound; + }, }; } |
