[PATCH, gfortran] Fix trailing whitespace in getenv ...

Steve Kargl sgk@troutmask.apl.washington.edu
Mon Aug 30 21:05:00 GMT 2004


The attached patch removes trailing whitespace from the 
the variable NAME prior to the call to getenv.  BTW, g77
can't handle an environmental variable with a space in the
variable name.

2004-08-30  Steven G. Kargl  <kargls@comcast.net>

        * intrinsics/env.c (getenv, get_environmental_variable): Remove
          trailing white space.

-- 
Steve
-------------- next part --------------
? env.c.diff
Index: env.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/intrinsics/env.c,v
retrieving revision 1.1
diff -u -r1.1 env.c
--- env.c	6 Aug 2004 21:47:03 -0000	1.1
+++ env.c	30 Aug 2004 20:59:46 -0000
@@ -55,7 +55,9 @@
   else
     memset (value, ' ', value_len); /* Blank the string.  */
 
-  memcpy (name_nt, name, name_len);
+  /* Trim trailing spaces from name.  */
+  while(name[--name_len] == ' ');
+  memcpy (name_nt, name, ++name_len);
   memset (&name_nt[name_len], '\0', 1); 
 
   res = getenv(name_nt);
@@ -124,7 +126,9 @@
 	memset (value, ' ', value_len); /* Blank the string.  */
     }
 
-  memcpy (name_nt, name, name_len);
+  /* Trim trailing spaces from name.  */
+  while(name[--name_len] == ' ');
+  memcpy (name_nt, name, ++name_len);
   memset (&name_nt[name_len], '\0', 1); 
   
   res = getenv(name_nt);


More information about the Fortran mailing list