mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-09 07:08:59 +00:00
Make std.os.getenv always a compile error on Windows
The _environ variable that is populated when linking libc on Windows does not support Unicode keys/values (or, at least, the encoding is not necessarily UTF-8). So, for Unicode support, _wenviron would need to be used instead. However, this means that the keys/values would be encoded as UTF-16, so they would need to be converted to UTF-8 before being returned by `os.getenv`. This would require allocation which is not part of the `os.getenv` API, so `os.getenv` is not implementable on Windows even when linking libc. Closes https://github.com/ziglang/zig/issues/8456
This commit is contained in:
parent
c1e94b28a3
commit
bc626e8b89
1 changed files with 4 additions and 3 deletions
|
|
@ -1893,6 +1893,9 @@ pub fn execvpeZ(
|
||||||
/// Get an environment variable.
|
/// Get an environment variable.
|
||||||
/// See also `getenvZ`.
|
/// See also `getenvZ`.
|
||||||
pub fn getenv(key: []const u8) ?[:0]const u8 {
|
pub fn getenv(key: []const u8) ?[:0]const u8 {
|
||||||
|
if (builtin.os.tag == .windows) {
|
||||||
|
@compileError("std.os.getenv is unavailable for Windows because environment strings are in WTF-16 format. See std.process.getEnvVarOwned for a cross-platform API or std.os.getenvW for a Windows-specific API.");
|
||||||
|
}
|
||||||
if (builtin.link_libc) {
|
if (builtin.link_libc) {
|
||||||
var ptr = std.c.environ;
|
var ptr = std.c.environ;
|
||||||
while (ptr[0]) |line| : (ptr += 1) {
|
while (ptr[0]) |line| : (ptr += 1) {
|
||||||
|
|
@ -1906,9 +1909,7 @@ pub fn getenv(key: []const u8) ?[:0]const u8 {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (builtin.os.tag == .windows) {
|
if (builtin.os.tag == .wasi) {
|
||||||
@compileError("std.os.getenv is unavailable for Windows because environment string is in WTF-16 format. See std.process.getEnvVarOwned for cross-platform API or std.os.getenvW for Windows-specific API.");
|
|
||||||
} else if (builtin.os.tag == .wasi) {
|
|
||||||
@compileError("std.os.getenv is unavailable for WASI. See std.process.getEnvMap or std.process.getEnvVarOwned for a cross-platform API.");
|
@compileError("std.os.getenv is unavailable for WASI. See std.process.getEnvMap or std.process.getEnvVarOwned for a cross-platform API.");
|
||||||
}
|
}
|
||||||
// The simplified start logic doesn't populate environ.
|
// The simplified start logic doesn't populate environ.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue