* RE: Problem with getenv("HOME")
@ 1997-10-29 2:35 Sergey Okhapkin
0 siblings, 0 replies; 3+ messages in thread
From: Sergey Okhapkin @ 1997-10-29 2:35 UTC (permalink / raw)
To: 'gnu-win32@cygnus.com', 'Wolfgang Stuerzlinger'
Cc: 'edel@fnal.fov'
Wolfgang Stuerzlinger wrote:
> By default the environment variable HOME is not set in the GNU-Win32
> environment.
> 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);
It's a bug in your example. getenv() returns NULL pointer, but sprintf
formats it as a "(null)" string. You have to check getenv's return value
before passing it somwhere.
--
Sergey Okhapkin, http://www.lexa.ru/sos
Moscow, Russia
Looking for a job.
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem with getenv("HOME")
@ 1997-10-29 9:11 marcus
0 siblings, 0 replies; 3+ messages in thread
From: marcus @ 1997-10-29 9:11 UTC (permalink / raw)
To: gnu-win32, stuerzl; +Cc: edel
>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@cygnus.com" with one line of text: "help".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Problem with getenv("HOME")
1997-10-27 14:36 Nedit5 for Windows95/NT Wolfgang Stuerzlinger
@ 1997-10-28 7:55 ` Wolfgang Stuerzlinger
0 siblings, 0 replies; 3+ messages in thread
From: Wolfgang Stuerzlinger @ 1997-10-28 7:55 UTC (permalink / raw)
To: gnu-win32; +Cc: edel
By default the environment variable HOME is not set in the GNU-Win32
environment.
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);
--
Wolfgang Stuerzlinger
Dept. of Computer Science, UNC, Chapel Hill, NC 27599-3175
stuerzl@cs.unc.edu http://www.cs.unc.edu/~stuerzl
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1997-10-29 9:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-29 2:35 Problem with getenv("HOME") Sergey Okhapkin
-- strict thread matches above, loose matches on Subject: below --
1997-10-29 9:11 marcus
1997-10-27 14:36 Nedit5 for Windows95/NT Wolfgang Stuerzlinger
1997-10-28 7:55 ` Problem with getenv("HOME") Wolfgang Stuerzlinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).