This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA/mingw32] environment variables are case-insensitive on win32


A patch that I sent a few months ago, I think, but never got in:
environment variables are case-insensitive on windows, this patch would
take that into account.

It would have been nice to have a configure test for that, using
setenv/getenv to detect the case insensitivity.  Unfortunately we
don't have setenv on win32. So I ended up using _WIN32 just like we do
to handle the .exe extension. Any other idea?

I could not run the testsuite on Windows though; so I run it on
x86-linux just to make sure that it had no effect on it. Note that the
problem does not reproduce when GDB is run from cygwin, which makes it
even harder to test. So I ended up using AdaCore's internal testsuite
to validate this.

gdb/ChangeLog:

	* environ.c (env_var_name_ncmp): New macro.
	(get_in_environ, set_in_environ, unset_in_environ): Use
	env_var_name_ncmp instead of strncmp.
---
 gdb/environ.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/gdb/environ.c b/gdb/environ.c
index 33426eb..2201926 100644
--- a/gdb/environ.c
+++ b/gdb/environ.c
@@ -96,6 +96,13 @@ environ_vector (struct gdb_environ *e)
   return e->vector;
 }
 
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define env_var_name_ncmp(a, b, length) strncasecmp (a, b, length)
+#else
+#define env_var_name_ncmp(a, b, length) strncmp(a, b, length)
+#endif
+
 /* Return the value in environment E of variable VAR.  */
 
 char *
@@ -106,7 +113,7 @@ get_in_environ (const struct gdb_environ *e, const char *var)
   char *s;
 
   for (; (s = *vector) != NULL; vector++)
-    if (strncmp (s, var, len) == 0 && s[len] == '=')
+    if (env_var_name_ncmp (s, var, len) == 0 && s[len] == '=')
       return &s[len + 1];
 
   return 0;
@@ -123,7 +130,7 @@ set_in_environ (struct gdb_environ *e, const char *var, const char *value)
   char *s;
 
   for (i = 0; (s = vector[i]) != NULL; i++)
-    if (strncmp (s, var, len) == 0 && s[len] == '=')
+    if (env_var_name_ncmp (s, var, len) == 0 && s[len] == '=')
       break;
 
   if (s == 0)
@@ -170,7 +177,7 @@ unset_in_environ (struct gdb_environ *e, char *var)
 
   for (; (s = *vector) != NULL; vector++)
     {
-      if (strncmp (s, var, len) == 0 && s[len] == '=')
+      if (env_var_name_ncmp (s, var, len) == 0 && s[len] == '=')
 	{
 	  xfree (s);
 	  /* Walk through the vector, shuffling args down by one, including
-- 
1.7.10.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]