According to SUS4 - the "Single Unix Specification", v4:
The functionality described on this reference page is aligned with the ISO C
standard. Any conflict between the requirements described here and the ISO C
standard is unintentional. This volume of POSIX.1-2008 defers to the ISO C
standard.
. . .
The string pointed to may be overwritten by a subsequent call to getenv(),
setenv(), unsetenv(), or putenv() but shall not be overwritten by a call to any
other function in this volume of POSIX.1-2008.
Daryl McDaniel
"I have always wished for my computer to be as easy to use as my telephone;
my wish has come true because I can no longer figure out how to use my
telephone."
-- Bjarne Stoustrup
From: Duane Voth [mailto:[email protected]]
Sent: Friday, June 21, 2013 3:02 PM
To: [email protected]
Subject: [edk2] StdLib getenv not POSIX compliant
I suspect the StdLib folks already know this but as a warning to the rest of
us, the getenv(3) in StdLib is reusing the character buffer in which it returns
values for each call to getenv(). The StdLib getenv comments say:
"The getenv function returns a pointer to a string associated with
the matched list member. The string pointed to shall not be
modified by the program, but may be overwritten by a subsequent
call to the getenv function. ..."
POSIX I believe defines something more like this:
"The getenv() function returns a pointer to the value in the environment..."
The later allows multiple calls to getenv() looking up different variables to
return distinct pointers to strings, the former returns the same pointer over
and over modifying the contents of the buffer ...
which btw, breaks Python startup code which essentially performs the equivalent
of:
...
char *rtpypath = getenv("PYTHONPATH");
char *path = getenv("PATH");
...
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel