From owner-freebsd-hackers@FreeBSD.ORG Sun Oct 16 05:02:25 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 5E74816A41F for ; Sun, 16 Oct 2005 05:02:25 +0000 (GMT) (envelope-from anthony.maher@uts.edu.au) Received: from tak.itd.uts.edu.au (tak.itd.uts.EDU.AU [138.25.198.144]) by mx1.FreeBSD.org (Postfix) with ESMTP id C06FB43D48 for ; Sun, 16 Oct 2005 05:02:24 +0000 (GMT) (envelope-from anthony.maher@uts.edu.au) Received: by tak.itd.uts.edu.au (Postfix, from userid 900) id 1F3E45D81B8; Sun, 16 Oct 2005 15:02:24 +1000 (EST) Received: from vimes (vimes.itd.uts.edu.au [138.25.243.34])by tak.itd.uts.edu.au (Postfix/Ingress) with ESMTP id 7A5355D80CFfor ; Sun, 16 Oct 2005 15:02:23 +1000 (EST) Received: from [192.168.0.16](d211-29-178-238.dsl.nsw.optusnet.com.au [211.29.178.238])by postoffice.uts.edu.au(Sun Java System Messaging Server 6.1 HotFix 0.09 (built Dec 14 2004))with ESMTPSA id <0IOF00902SNYOPB0@postoffice.uts.edu.au> forhackers@freebsd.org; Sun, 16 Oct 2005 15:02:23 +1000 (EST) Date: Sun, 16 Oct 2005 15:02:22 +1000 From: Tony Maher To: hackers@freebsd.org Message-id: <4351DEDE.9000900@uts.edu.au> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.11) Gecko/20050903 X-Virus-Scanned: amavisd-new at uts.edu.au Cc: Subject: 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 05:02:25 -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 -- UTS CRICOS Provider Code: 00099F DISCLAIMER: This email message and any accompanying attachments may contain confidential information. If you are not the intended recipient, do not read, use, disseminate, distribute or copy this message or attachments. If you have received this message in error, please notify the sender immediately and delete this message. Any views expressed in this message are those of the individual sender, except where the sender expressly, and with authority, states them to be the views the University of Technology Sydney. Before opening any attachments, please check them for viruses and defects.