Re: HEADS UP: getenv() and family API change

From: Sean C. Farley <scf_at_FreeBSD.org>
Date: Mon, 9 Jul 2007 15:07:42 -0500 (CDT)
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
Received on Mon Jul 09 2007 - 18:08:38 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:14 UTC