HEADS UP: getenv() and family API change
Sean C. Farley
scf at FreeBSD.org
Mon Jul 9 20:08:38 UTC 2007
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
just remove this function. While they are at it, they should remove
direct access to environ. Some helper functions would be best. I rant
every time I think about putenv() and an exposed environ variable. :)
The best is to replace putenv() with setenv() in any applications with
issues as it is less error-prone.
Sean
--
scf at FreeBSD.org
More information about the freebsd-current
mailing list