commit 65a7d48d6ae3835fb63d2a7c6a40feee16572d95 Author: Jerome Guitton Date: Thu May 24 18:19:23 2012 +0200 environment variables are case-insensitive on mingw gdb/ChangeLog: * environ.c (host_has_case_sensitive_env_vars) (env_var_name_ncmp): New functions. (get_in_environ, set_in_environ, unset_in_environ): Use env_var_name_ncmp instead of strncmp. diff --git a/gdb/environ.c b/gdb/environ.c index 33426eb..98d8ca6 100644 --- a/gdb/environ.c +++ b/gdb/environ.c @@ -96,6 +96,48 @@ environ_vector (struct gdb_environ *e) return e->vector; } + +/* Return 1 if the names of environ variables are case sensitive + on host. */ + +static int +host_has_case_sensitive_env_vars() +{ + static int result = -1; + char *value; + + if (result != -1) + return result; + +#if defined(_WIN32) && !defined(__CYGWIN__) + putenv ("__GDB_TEST_CASE_SENSITIVITY=set"); + +#else + setenv ("__GDB_TEST_CASE_SENSITIVITY", "set", 1); +#endif + + value = getenv ("__GDB_test_CASE_Sensitivity"); + + if (value && (strcmp (value, "set") == 0)) + result = 0; + else + result = 1; + + return result; +} + +/* Compare the first LENGTH characters of the names of two + environment variable A and B. */ + +static int +env_var_name_ncmp(const char *a, const char *b, int length) +{ + if (host_has_case_sensitive_env_vars()) + return strncmp(a, b, length); + else + return strncasecmp (a, b, length); +} + /* Return the value in environment E of variable VAR. */ char * @@ -106,7 +148,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 +165,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 +212,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