From: Joel Brobecker <brobecker@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: gdb-patches@sourceware.org, Joel Brobecker <brobecker@adacore.com>
Subject: [RFA/libiberty] Darwin has case-insensitive filesystems
Date: Tue, 14 Jun 2011 21:57:00 -0000 [thread overview]
Message-ID: <1308087182-26577-1-git-send-email-brobecker@adacore.com> (raw)
Hello,
HFS+, the FS on Darwin, is case insensitive. So this patch adjusts
filename_cmp.c to ignore the casing when comparing filenames on Darwin.
This is visible in GDB when trying to break on a file whose name
is, say 'Mixed_Case.adb', but was compiled using 'mixed_case.adb'
as the filename. In that case, GDB says it cannot find 'Mixed_Case.adb'.
There are two parts:
1. in include/filenames.h: I add a new macro
HAVE_CASE_INSENSITIVE_FILE_SYSTEM, which is defined on systems
that have DOS-like file systems, as well as on Darwin.
2. Adjust filename_cmp and filename_ncmp to take it into account.
I am also wondering whether it makes sense or not to keep the
case-sensitive & no DOS-like features case separate, or whether
we should handle this case using the same code as on Windows/Darwin.
In other words, does it make a difference to be using strcmp/strncmp
when we can, versus always using our loop that compares character by
character?
include/ChangeLog:
* filenames.h (HAVE_CASE_INSENSITIVE_FILE_SYSTEM): Define
on Darwin, as well as on the systems that use a DOS-like
filesystem.
libiberty/ChangeLog:
* filename_cmp.c (filename_cmp, filename_ncmp): Add handling of
HAVE_CASE_INSENSITIVE_FILE_SYSTEM.
Tested on x86_64-darwin as well as on x86_64-linux. I haven't tested
on a Windows system yet, but I will get our gdb-testsuite's daily
results before tomorrow.
Does this look OK to commit?
Thanks!
--
Joel
---
include/filenames.h | 8 ++++++++
libiberty/filename_cmp.c | 28 ++++++++++++++++++++++------
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/include/filenames.h b/include/filenames.h
index d4955df..75ec330 100644
--- a/include/filenames.h
+++ b/include/filenames.h
@@ -34,10 +34,18 @@ extern "C" {
# ifndef HAVE_DOS_BASED_FILE_SYSTEM
# define HAVE_DOS_BASED_FILE_SYSTEM 1
# endif
+# ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
+# define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
+# endif
# define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f)
# define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c)
# define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f)
#else /* not DOSish */
+# if defined(__APPLE__)
+# ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
+# define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
+# endif
+# endif /* __APPLE__ */
# define HAS_DRIVE_SPEC(f) (0)
# define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c)
# define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f)
diff --git a/libiberty/filename_cmp.c b/libiberty/filename_cmp.c
index 0eed120..5179f8d 100644
--- a/libiberty/filename_cmp.c
+++ b/libiberty/filename_cmp.c
@@ -50,19 +50,27 @@ and backward slashes are equal.
int
filename_cmp (const char *s1, const char *s2)
{
-#ifndef HAVE_DOS_BASED_FILE_SYSTEM
+#if !defined(HAVE_DOS_BASED_FILE_SYSTEM) \
+ && !defined(HAVE_CASE_INSENSITIVE_FILE_SYSTEM)
return strcmp(s1, s2);
#else
for (;;)
{
- int c1 = TOLOWER (*s1);
- int c2 = TOLOWER (*s2);
+ int c1 = *s1;
+ int c2 = *s2;
+#if defined (HAVE_CASE_INSENSITIVE_FILE_SYSTEM)
+ c1 = TOLOWER (c1);
+ c2 = TOLOWER (c2);
+#endif
+
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
/* On DOS-based file systems, the '/' and the '\' are equivalent. */
if (c1 == '/')
c1 = '\\';
if (c2 == '/')
c2 = '\\';
+#endif
if (c1 != c2)
return (c1 - c2);
@@ -100,21 +108,29 @@ and backward slashes are equal.
int
filename_ncmp (const char *s1, const char *s2, size_t n)
{
-#ifndef HAVE_DOS_BASED_FILE_SYSTEM
+#if !defined(HAVE_DOS_BASED_FILE_SYSTEM) \
+ && !defined(HAVE_CASE_INSENSITIVE_FILE_SYSTEM)
return strncmp(s1, s2, n);
#else
if (!n)
return 0;
for (; n > 0; --n)
{
- int c1 = TOLOWER (*s1);
- int c2 = TOLOWER (*s2);
+ int c1 = *s1;
+ int c2 = *s2;
+#if defined (HAVE_CASE_INSENSITIVE_FILE_SYSTEM)
+ c1 = TOLOWER (c1);
+ c2 = TOLOWER (c2);
+#endif
+
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
/* On DOS-based file systems, the '/' and the '\' are equivalent. */
if (c1 == '/')
c1 = '\\';
if (c2 == '/')
c2 = '\\';
+#endif
if (c1 == '\0' || c1 != c2)
return (c1 - c2);
--
1.7.1
next reply other threads:[~2011-06-14 21:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-14 21:57 Joel Brobecker [this message]
2011-06-14 22:02 ` DJ Delorie
2011-07-01 17:58 ` Joel Brobecker
2011-06-14 22:06 ` Andrew Pinski
2011-06-14 22:13 ` DJ Delorie
2011-06-15 4:25 ` Tristan Gingold
2011-06-15 8:14 ` Joel Brobecker
2011-06-15 9:30 ` Corinna Vinschen
2011-06-15 10:44 ` Mark Kettenis
2011-06-15 10:55 ` Corinna Vinschen
2011-06-15 11:00 ` Pedro Alves
2011-06-15 11:26 ` Robert Dewar
2011-06-15 17:47 ` Eli Zaretskii
2011-06-15 10:59 ` Joseph S. Myers
2011-06-15 11:07 ` Corinna Vinschen
2011-06-15 17:35 ` Eli Zaretskii
2011-06-15 21:11 ` Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1308087182-26577-1-git-send-email-brobecker@adacore.com \
--to=brobecker@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).