Subject: Re: putenv(3) POSIX - XPG compliance
To: <>
From: David Laight <>
List: tech-userlevel
Date: 01/30/2003 15:14:16
> >>From the current standard at
> (
>      The putenv() function shall use the string argument to set
>      environment variable values. The string argument should point to a
>      string of the form "name=value". The putenv() function shall make
>      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 shall become part of the
>      environment, so altering the string shall change the environment.
>      The space used by string is no longer used once a new
>      string-defining name is passed to putenv().

Shame it says 'shall' and not 'may'.

That definition is trully horrid!
It allows such abberations as:

	static char a[] = "a=a";
	static char b[] = "b=b";

	b[0] = 'a';

    or even:
	(getenv("b") - 2)[0] = 'a';

It also is a memory leak, since if you ever putenv() a malloc()ed
pointer you never, ever, know when it is safe to free the value.

Have you found some code that relies on this beaviour?
Otherwise I'd be tempted to add some worms to the 'bugs' section
and leave the code alone!

Oh - and file a CR against the posix spec!


David Laight: