Subject: Re: bug#19874: 25.0.50; encode-time not working as expected

From: Wolfgang Jenkner <[email-masked]>
Date: Fri, 27 Feb 2015 18:33:47 +0100

On Thu, Feb 26 2015, Paul Eggert wrote:

> Emacs's putenv implementation should be portable to any POSIX
> platform, but FreeBSD 10.1 getenv+setenv has a bug.  The attached
> program should work on any POSIX platform, and it does work on
> GNU/Linux and on Solaris, but it doesn't work on FreeBSD 10.1.  Emacs
> has similar code, which apparently also runs afoul of the FreeBSD bug.
>
> #include <stdio.h>
> #include <stdlib.h>
> extern char **environ;
> char env1[] = "abc=def";
> char *small_environ[] = { env1, 0 };
> int
> main (void)
> {
>   environ = small_environ;
>   if (setenv ("mno", "pqr", 0) != 0)
>     return perror ("setenv"), 1;
>   env1[0] = 'x';
>   if (! getenv ("xbc"))
>     return fprintf (stderr, "getenv failed\n"), 1;
>   return 0;
> }

IIUC, the standard explicitly permits the FreeBSD behaviour, so the
program above does not seem to be conforming:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/getenv.html

	If the application switches to a complete new environment by
	assigning a new value to environ, this can be detected by
	getenv(), setenv(), unsetenv(), or putenv() and the
	implementation can at that point reinitialize based on the new
	environment. (This may include copying the environment strings
	into a new array and assigning environ to point to it.)