-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's the deal with =
in environment variable names?
#23331
Comments
Given env vars are often system specific, and the embedded For the Here's a bug from NodeJS where they discovered some platforms trim a leading Hmm ... a consistent EnvMap behavior might be funky if the single |
There are basically three behaviors in practice:
In all three,
IMO EnvMap already behaves ideally. |
Context: #23265 and #23272
Environment variable blocks on POSIX and Windows contain strings of the format
name=value
, where the name cannot contain a=
character*Note
On Windows, a
=
is allowed, but only as the first character of an environment variable name (e.g.=FOO
). These are semi-hidden (they don't show up when runningset
) and are used for things like per-drive CWDs, see https://devblogs.microsoft.com/oldnewthing/20100506-00/?p=14133).More about this later
From the POSIX spec on environment variables:
Although the POSIX spec seems fairly clear, C libraries/OS APIs don't seem to agree on how to handle
getenv
calls for a name with a=
in it.Here's the test case:
FOO
set to the valueABC=123
, so in the environment block it looks likeFOO=ABC=123
getenv("FOO=ABC")
or the equivalent OS APITest project
Run with
zig build
Here's the results of that from what @g-logunov and I have tested so far:
123
null
ABC=123
123
123
GetEnvironmentVariableW
returnsERROR_ENVVAR_NOT_FOUND
Note
On Windows, those semi-hidden variables that start with
=
cannot be gotten via the libcgetenv
API, but can be gotten fromGetEnvironmentVariableW
So, what should the Zig APIs do? I can think of a few options:
=
in it (but allow getting semi-hidden environment variables on Windows)getenvW
and a standalone environment variable test #23272 expects currently=
and let whatever happens happen (as long as it doesn't lead to illegal behavior), and focus solely on providing the highest performance implementation possible otherwise=
in optimization modes that have safety enabled (Debug/ReleaseSafe)Personally, I think option 1 or option 3 make the most sense.
(for the hidden Windows environment variables, I think being able to get them makes sense, so no need to change anything there IMO)
The text was updated successfully, but these errors were encountered: