[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: lynx-dev putenv
From: |
Bela Lubkin |
Subject: |
Re: lynx-dev putenv |
Date: |
Wed, 20 Jan 1999 18:23:46 -0800 |
Klaus Weide wrote:
> After I repeatedly sent patches that try to
>
> FREE(lynx_version_putenv_command);
>
> Tom finally added the comment
>
> /_ Note: you must not free the data passed to 'putenv()' until you give it
> * a new value for that variable.
> */
>
> instead, and I see now that there are similar ones about putenv in
> LYPrint.c and LYUtils.c.
>
> Ok, now I am curious, on which systems is that a problem? Does it only
> occur with the putenv repacement in LYUtils.c (apparently taken from an
> old GNU C Library)?
>
> I tried to produce a problem with this (Linux 2.0.33, GNU libc) and
> failed.
According to putenv(3C) on SCO UnixWare 7.0.0:
int putenv (char * string);
Description
string points to a string of the form ``name=value.'' putenv 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. string should not be a local
(stack allocated) variable, since returning from the current function
and calling a new one will change the environment. If name is later
redefined by another putenv, string is no longer used. It may be
altered or reused without affecting the environment.
In other words, putenv stores the pointer you pass in.
I would think this was POSIX/XPG mandated behavior. Try this with Linux
& glibc:
main()
{
char *foo = "foo=bar";
putenv(foo);
printf("%s\n", getenv("foo"));
foo[6] = 'z';
printf("%s\n", getenv("foo"));
}
I get:
bar
baz
>Bela<