Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

About getenv ...

0 views
Skip to first unread message

Dragan Cvetkovic

unread,
Oct 18, 2000, 3:00:00 AM10/18/00
to
Hi,

I have a question regarding getenv() behaviour. What shall it return if the
argument to it is not just an env. variable but a string whose first part
is environment variable? I have come across different behaviour in
different implementations and I don't know which one is correct.

For example, getenv("HOME=/home/dragan") on Solaris and AIX returns the
current value of $HOME env. variable as if I have just called
getenv("HOME") whereas Linux version (GNU libc-2.1.3 on Debian 2.2) returns
NULL since "HOME=/home/dragan" is obviously not an environment
variable. Both version work fine on getenv("HOME") as they should.

Which one is correct (I would think that GNU one is correct)? Is there any
requirement in standard about it?

Thanks, Dragan

--
Dragan Cvetkovic

To be or not to be is true. G. Boole

Nick Maclaren

unread,
Oct 18, 2000, 3:00:00 AM10/18/00
to

Both, though the GNU one is a more faithful implementation of the
wording. And no. The exact wording is:

[#2] The getenv function searches an environment list,
provided by the host environment, for a string that matches
the string pointed to by name. The set of environment names
and the method for altering the environment list are
implementation-defined.

Notice that it says "matches" and not "is equal to", thus leaving
open the possibility of the Solaris behaviour. On some systems,
environment variables are not case-sensitive, which is another way
in that a string may match without textual equality.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email: nm...@cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679

0 new messages