...
This allows an implementation, for example, to copy the environmental variable to an internal static buffer and return a pointer to that buffer.
If you do not immediately use and discard this string, make a copy of the referenced string returned by getenv()
so that this This string should be referenced immediately and discarded, or copied so that the copy may be referenced safely referenced at a later time. The getenv()
function is not thread-safe. Make sure to address any possible race conditions resulting from the use of this function.
...
This non-compliant code example compares the value of the TMP
and TEMP
environment variables to determine if they are the same. This code example is non-compliant because the string referenced by tmpvar
may be overwritten as a result of the second call to the getenv()
function. As a result, it is possible that both tmpvar
and tempvar
will compare equal even if the two environment variables have different values.
...