
On 4/26/05, Martin Wille <mw8329@yahoo.com.au> wrote:
Caleb Epstein wrote:
On 4/26/05, Martin Wille wrote:
[...]
setenv() is a very recent addition to POSIX, IIRC. Older Unix versions might not support it.
OK, would you know of a better way to determine which "type" of putenv is available instead? E.g. is it the one that takes a const char* and copies, or the one that takes a char* and inserts it into the environment in-place. Using the wrong semantic will lead to either memory leak (bad) or undefined behavior (worse).
I once wrote my own version of putenv() in order to avoid the memory leak problem. I'm afraid this is a nasty problem, because POSIX putenv() doesn't copy but doesn't assume ownership, either. setenv() might leak for that reason, too.
You can check for the platforms you know to support setenv by using the various macros they supply (messy, I know). Every *BSD I know of and Linux do. setenv() was added to POSIX in IEEE Std 1003.1-2001, if I understand correctly. So setting _POSIX_C_SOURCE before #including any POSIX header and checking for _POSIX_VERSION >= 200112L should catch all POSIX implementations that added setenv() recently.
[...]
Your patch doesn't check the value returned by setenv() or putenv().
Nor did the original. I'm just trying to get this code working in order to clear up some of the test failures.
Well, I don't know the context of the code. I can't say whether it is ok to ignore the result here. I just wanted to state what I've seen.
Perhaps Genndiy could comment on whether or not this code is really even needed. It seems to only be used in a single test program. -- Caleb Epstein caleb dot epstein at gmail dot com