...
Section 7.22.4.6 of the C Standard [ISO/IEC 9899:2011] states that:
The set of environment names and the method for altering the environment list are implementation-defined.
...
The following noncompliant code behaves differently when compiled and run on Linux and Microsoft Windows platforms.:
Code Block | ||||
---|---|---|---|---|
| ||||
if (putenv("TEST_ENV=foo") != 0) { /* Handle error */ } if (putenv("Test_ENV=bar") != 0) { /* Handle error */ } const char *temp = getenv("TEST_ENV"); if (temp == NULL) { /* Handle error */ } printf("%s\n", temp); |
...
Portable code should use environment variables that differ by more than capitalization.:
Code Block | ||||
---|---|---|---|---|
| ||||
if (putenv("TEST_ENV=foo") != 0) { /* Handle error */ } if (putenv("OTHER_ENV=bar") != 0) { /* Handle error */ } const char *temp = getenv("TEST_ENV"); if (temp == NULL) { /* Handle error */ } printf("%s\n", temp); |
...