From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14960 invoked by alias); 10 Dec 2012 15:35:12 -0000 Received: (qmail 14824 invoked by uid 22791); 10 Dec 2012 15:35:11 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 10 Dec 2012 15:35:06 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id AA686CB3CDB; Mon, 10 Dec 2012 16:35:10 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZDAtuIxbamIt; Mon, 10 Dec 2012 16:35:10 +0100 (CET) Received: from chelles.act-europe.fr (chelles.act-europe.fr [10.10.0.160]) by mel.act-europe.fr (Postfix) with ESMTP id 8E5B0CB3CBF; Mon, 10 Dec 2012 16:35:10 +0100 (CET) Received: by chelles.act-europe.fr (Postfix, from userid 560) id 8CB551EA005A; Mon, 10 Dec 2012 16:35:10 +0100 (CET) Date: Mon, 10 Dec 2012 15:35:00 -0000 From: Jerome Guitton To: Joel Brobecker Cc: gdb-patches@sourceware.org Subject: Re: [RFA/mingw32] environment variables are case-insensitive on win32 Message-ID: <20121210153510.GB17188@adacore.com> References: <83y5hjt8ll.fsf@gnu.org> <20121130153401.GH2768@adacore.com> <83wqx3t6r9.fsf@gnu.org> <20121130162852.GD32262@adacore.com> <50B902D0.6060809@redhat.com> <20121203113147.GB12055@adacore.com> <20121209235344.GA12152@ednor.casa.cgf.cx> <20121210105115.GB15147@adacore.com> <20121210110128.GA12570@calimero.vinschen.de> <20121210134935.GL31477@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8t9RHnE3ZwKMSgU+" Content-Disposition: inline In-Reply-To: <20121210134935.GL31477@adacore.com> User-Agent: Mutt/1.5.21 (2010-09-15) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-12/txt/msg00241.txt.bz2 --8t9RHnE3ZwKMSgU+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1070 Joel Brobecker (brobecker@adacore.com): > 1. Decide whether we want GDB to match environment variable names > using case-sensitive or case-insensentive functions on cygwin. > Right now, it's case-sensitive. FWIW, we are offering to change > that behavior, and it seems more user-friencly at the moment, > but either choice is fine with me. If no concensus can be reached > on this, then we'll revert to the original behavior. > > 2. Commit Jerome's patch which implements the decision from (1), > letting a more elaborate handling of environment variables > as a followup patch for someone more involved in cygwin than > we are. At this point my feeling is that there is something to clarify for Cygwin; the symptom being that the new test I submitted for testenv.exp fails on this platform. But for the moment I'd be inclined to let Cygwin's situation unchanged and let an expert handle it. The patch that I would submit would fix mingw32 only. So I guess that would be (2). The corresponding patch is in attachment. --8t9RHnE3ZwKMSgU+ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="environ.c.diff" Content-length: 2483 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 --8t9RHnE3ZwKMSgU+--