From owner-freebsd-hackers@FreeBSD.ORG Sun Oct 16 06:47:43 2005 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id ADFD216A420 for ; Sun, 16 Oct 2005 06:47:43 +0000 (GMT) (envelope-from danny@cs.huji.ac.il) Received: from cs1.cs.huji.ac.il (cs1.cs.huji.ac.il [132.65.16.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4272F43D46 for ; Sun, 16 Oct 2005 06:47:43 +0000 (GMT) (envelope-from danny@cs.huji.ac.il) Received: from pampa.cs.huji.ac.il ([132.65.80.32]) by cs1.cs.huji.ac.il with esmtp id 1ER2J2-000Cyc-Qy; Sun, 16 Oct 2005 08:47:40 +0200 X-Mailer: exmh version 2.7.0 06/18/2004 with nmh-1.0.4 To: Tony Maher In-Reply-To: Message from Tony Maher of "Sun, 16 Oct 2005 15:02:22 +1000." <4351DEDE.9000900@uts.edu.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 16 Oct 2005 08:47:40 +0200 From: Danny Braniss Message-ID: Cc: hackers@freebsd.org Subject: Re: getenv semantics X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Oct 2005 06:47:43 -0000 > Hello, > > I am trying to create a port of some 3rd party software and while > I can get it to compile ok and (mostly) run there are a few anomalies in > it detecting environment variables. It appears to run ok on linux (I do > not have a convenient linux box for testing with). I believe its the > way the code get the environment variables that is the cause. But if > thats the case then it would appear that getenv semantics differs > slightly on different platforms. > > From http://notabug.com/2002/coherent/man/getenv.html > "When VARIABLE is not found or has no value, getenv() returns NULL." > > But on FreeBSD it would appear that if VARIABLE is found but has no > value it returns a pointer to a NUL ('\0') string. > > Is this analysis correct? Can someone point me to the (a?) standard > that describes this. The FreeBSD behaviour makes sense, I am trying to > understand what is the expected behaviour on other platforms. > > -------------------------------------------------------------------------- > #!/bin/sh > > echo "unset foobar" > unset foobar > ./test-getenv > > echo "export foobar" > export foobar > ./test-getenv > > echo "export foobar=isset" > export foobar=isset > ./test-getenv > > echo "unset foobar" > unset foobar > ./test-getenv > > ---------------------------------------------------------------------------- > > > /* test-getenv.c */ > > #include > #include > > int > main(int argc, char *argv[]) > { > char *p; > p = getenv("foobar"); > fprintf(stderr, "getenv('foobar') string is >%s< pointer is > >%x<\n",p, p); > exit(0); > } > ------------------------------------------------------------------------------- > > ./test-getenv.sh > unset foobar > getenv('foobar') string is >(null)< pointer is >0< > export foobar > getenv('foobar') string is >< pointer is >bfbfe933< > export foobar=isset > getenv('foobar') string is >isset< pointer is >bfbfe92f< > unset foobar > getenv('foobar') string is >(null)< pointer is >0< > > thanks > -- > tonym now why would FreeBSD supply sources? from /usr/src/lib/libc/stlib/getenv.c: ... /* * getenv -- * Returns ptr to value associated with name, if any, else NULL. */ char * getenv(name) const char *name; { int offset; return (__findenv(name, &offset)); } danny