HEADS UP: getenv() and family API change
Andrey Chernov
ache at nagual.pp.ru
Tue Jul 10 15:42:29 UTC 2007
On Mon, Jul 09, 2007 at 03:07:42PM -0500, Sean C. Farley wrote:
> On Sun, 8 Jul 2007, Dirk Meyer wrote:
>
>> Hallo Sean C. Farley,
>>
>>> Changes in moving to POSIX from historic BSD API:
>>> b. putenv takes a char * instead of const char *.
>>> c. putenv no longer makes a copy of the input string.
>>
>> Can you give more details?
>>
>> An application will break in using this:
>> putenv("PATH=/bin")
>>
>> now taking a char *, this will break with gcc42.
>
> True. As Andrey said, you should pass a copy of a const string into
> putenv(). putenv() is designed to allow changing a value at any time by
> manipulating the string. This is why I really wish the Open Group would
To say strictly, copying somewhere is not neccessary since this way works
too:
static char *s = "PATH=/bin";
putenv(s);
(don't forget static)
--
http://ache.pp.ru/
More information about the freebsd-current
mailing list