4 ms·
`getenv()` never returns pointers that can be invalidated. If you `putenv()` something, you commit to never freeing it or overwriting it.
by cryptonector 3y ago
`getenv()` never returns pointers that can be invalidated. If you `putenv()` something, you commit to never freeing it or overwriting it.
- hddqsb 3y agoGood point about `putenv()`; however there is also `setenv()`, which does make a copy, so you are wrong about `getenv()` in general. POSIX explicitly states "The string [returned by getenv] may be overwritten by a subsequent call to getenv(), setenv(), unsetenv(), or putenv()" (https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/functions/getenv.html https://pubs.opengroup.org/onlinepubs/9699919799.2008edition...).
- cryptonector 3y ago"May", but really, it's best for `setenv()` to leak.