import std.stdio; import std.process; import std.path; void test(string envvar) { environment[envvar] = "myvalue"; writefln("check env: %s=%s (%s)", envvar, environment.get(envvar), environment.get(envvar).length); environment[envvar] = null; writefln("check env: %s=%s (%s)", envvar, environment.get(envvar), environment.get(envvar).length); } void main(string[] args) { test("TEST_VAR1"); test("TEST_VAR2"); } This seems to be random. Sometimes it writes junk only to the second variable.
Test case: import std.conv; import std.stdio; import std.string; import core.sys.posix.stdlib; void main() { immutable key = "AAAAAAAA".toStringz; foreach (i; 0 .. 100) { setenv(key, null, 1); const r = getenv(key); if (r && *r) { writefln("%s %s %s", i, r, r.to!string); } } } Result: http://melpon.org/wandbox/permlink/cqfITPRJMSKOD60q It's terrible. What does getenv return?
core.sys.posix.stdlib.setenv is a simple wrapper around the posix function of the same name, and should have the same behavior. This is not a bug in core.sys.posix.stdlib, but one might argue there is one in phobos' std.process.environment. The OS is simply following the standard, which says nothing about how to handle nulls: http://pubs.opengroup.org/onlinepubs/9699919799/functions/setenv.html
Still issue for 2.073.2 Can we just decide that providing the null means removing environment variable or setting it to empty string? Better make it behave the same way as on Windows (not sure what's behavior though).
Was fixed in https://github.com/dlang/phobos/pull/5324 Can we get this closed?
@Roman: If you reference the Bugzilla issue(s) in your PRs, they will be automatically closed: https://github.com/dlang-bots/dlang-bot#automated-references There are other advantages of doing this as well, e.g. referenced issues will be listed on the changelog.