delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/10/29/14:32:08

From: marcus AT bighorn DOT dr DOT lucent DOT com
Subject: Re: Problem with getenv("HOME")
29 Oct 1997 14:32:08 -0800 :
Message-ID: <199710291538.IAA07197.cygnus.gnu-win32@chorus.dr.lucent.com>
To: gnu-win32 AT cygnus DOT com, stuerzl AT cs DOT unc DOT edu
Cc: edel AT fnal DOT fov

>When getenv is called with ("HOME") as argument the return value is a
>string "(null)" instead of a NULL pointer. Is this a "standard" behaviour 
>or a bug?

>Wolfgang Stuerzlinger

>P.S.: This breaks commonly used code sequences like:
>	sprintf(newName,"%s/%s",getenv("HOME"),fileName);

Are you sure that this isn't in sprintf?

It is common for printf-like routines to actually print "(null)" when
a NULL pointer is passed for a %s conversion.  Unfortunately, it is
also a rather common implementation for it to blindly use the NULL
pointer and fault or output garbage :-(

Anyhow, I think that getenv() is in fact returning NULL in this case.

Try this:

	if (getenv("HOME") == NULL)
		printf("NULL pointer returned\n");

Or:
	printf("Return of getenv: 0x%x\n", getenv("HOME"));

marcus hall
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019