Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Jul 2007 15:07:42 -0500 (CDT)
From:      "Sean C. Farley" <scf@FreeBSD.org>
To:        Dirk Meyer <dirk.meyer@dinoex.sub.org>
Cc:        freebsd-current@FreeBSD.org
Subject:   Re: HEADS UP:  getenv() and family API change
Message-ID:  <20070709145418.T52164@thor.farley.org>
In-Reply-To: <Xuu8UV3Bay@dmeyer.dinoex.sub.org>
References:  <20070703182400.Q1449@baba.farley.org> <Xuu8UV3Bay@dmeyer.dinoex.sub.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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@FreeBSD.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070709145418.T52164>