This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [PATCH, gfortran] Fix trailing whitespace in getenv ...
- From: Janne Blomqvist <jblomqvi at cc dot hut dot fi>
- To: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- Cc: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 31 Aug 2004 09:10:59 +0300
- Subject: Re: [PATCH, gfortran] Fix trailing whitespace in getenv ...
- References: <20040830210528.GB92317@troutmask.apl.washington.edu>
On Mon, Aug 30, 2004 at 02:05:28PM -0700, Steve Kargl wrote:
> The attached patch removes trailing whitespace from the
> the variable NAME prior to the call to getenv.
A big thanks to Steve for volunteering to clean up my mess.
> BTW, g77
> can't handle an environmental variable with a space in the
> variable name.
Nice. Now we can brag that gfortran implements (some) g77 intrinsics
better than g77 itself! ;-)
Well, to the point. *Disclaimer* I don't have the source here at work,
so this is from memory.
As you know, the name_nt array is a copy of the name array with a '\0'
added at the end so that the libc getenv can find the end of the
string. Now, C99 allows variable declarations after executable
statements in a function. Thus, name_nt can be declared after the
whitespace has been counted, saving some stack space (gcc allocates
VLA:s on the stack). E.g. if someone calls getenv with a 1000
character string containing 'HOME' and the rest whitespace, name_nt
would be only 5 characters and not 1001.
Does this sound reasonable or did I forget some crucial detail?
--
Janne Blomqvist