getenv in FreeBSD 7

Bakul Shah bakul at bitblocks.com
Sun Apr 6 22:46:08 UTC 2008


On Sun, 06 Apr 2008 14:37:06 PDT Doug Hardie <bc979 at lafn.org>  wrote:
> Somewhere between FreeBSD 6.2 and 7.0 getenv has been changed to  
> return a null if an environment variable is set but has no value.  I  
> don't find anything anywhere in the documentation/man pages on this.   
> As a result, you cannot distinguish between a variable that is not set  
> and one that is set to a value of "".  Is this a bug or a feature  
> change?

This is not what I see on 7.0 or -current (and it would not
be standard compliant).  Try this under /bin/sh:

cat >x.c<<EOF
#include <stdlib.h>
#include <stdio.h>
int main(int c, char**v) {
	char* a = getenv(v[1]);
	printf("%s\n", a? a : "--null--");
	return 0;
}
EOF
cc x.c
foo="" ./a.out foo	# this should return a blank line
./a.out foo		# this should return a line with --null--

If your system behaves differently  may be you can attach a
simple test that shows the bug?


More information about the freebsd-stable mailing list