...
This gives an implementation the latitude, for example, to return a pointer to a statically allocated buffer of static storage duration. Consequently, do not to store this pointer because it may be overwritten by a subsequent call to the getenv()
function or invalidated as a result of changes made to the environment list through calls to the POSIX functions putenv()
or setenv()
, or other implementation-specific means. Storing the pointer for later use can result in a dangling pointer or a pointer to incorrect data. This string should be referenced immediately and discarded; if later use is anticipated, the string should be copied so the copy can be safely referenced as needed.
...