🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3708

Re: VERY odd TZ/putenv/tzset problem

#3708
From: Nate Eldredge
Date: Wed, 03 May 2000 00:00
29 lines
2147 bytes
admin@intergrafix.net writes:

> I've figured out HOW the problem occurs, i just dont know WHY it occurs, or
> WHY it should occur. Possibly a bug in the c libs or gcc??
> The HOW is: when you putenv() an array, and then modify the array afterwards,
> the environment automatically gets changed without executing another
> putenv()! This, to me, sounds ludicrous. Even setting the array below to
> static char doesn't help.

Believe it or not, this is correct behavior.  According to the Single
Unix Spec
(http://www.opengroup.org/onlinepubs/7908799/xsh/putenv.html):

# The putenv() function makes the value of the environment variable
# name equal to value by altering an existing variable or creating a
# new one. In either case, the string pointed to by string becomes
# part of the environment, so altering the string will change the
# environment. The space used by string is no longer used once a new
# string-defining name is passed to putenv().

If you want it to be independent, use strdup or something of the sort.

A note to this effect appears to have been added to the glibc
documentation recently; it may not be in your version.

-- 

Nate Eldredge
neldredge@hmc.edu
Technical Details
Message-ID: <83d7n3bdi0.fsf@mercury.st.hmc.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <sh0jbc2j1g2120@corp.supernews.com> <sh0rs5c4a4n48@corp.supernews.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1033b0,f3cb935aae0fcff6
X-Google-Attributes: gid1033b0,public
X-Google-Thread: fc89c,f3cb935aae0fcff6
X-Google-Attributes: gidfc89c,public
X-Google-Thread: 108717,f3cb935aae0fcff6
X-Google-Attributes: gid108717,public
From: Nate Eldredge <neldredge@hmc.edu>
Subject: Re: VERY odd TZ/putenv/tzset problem
Date: 2000/05/03
Message-ID: <83d7n3bdi0.fsf@mercury.st.hmc.edu>
X-Deja-AN: 618836454
References: <sh0jbc2j1g2120@corp.supernews.com> <sh0rs5c4a4n48@corp.supernews.com>
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: usenet@nntp1.interworld.net
X-Trace: nntp1.interworld.net 957384682 57349 134.173.45.219 (3 May 2000 20:11:22 GMT)
Organization: InterWorld Communications
Mime-Version: 1.0
User-Agent: Gnus/5.0802 (Gnus v5.8.2) Emacs/20.5
NNTP-Posting-Date: 3 May 2000 20:11:22 GMT
Newsgroups: comp.unix.programmer,comp.programming,gnu.misc