aboutsummaryrefslogtreecommitdiff
path: root/libiberty/filename_cmp.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2012-07-13 23:39:46 +0000
committerDoug Evans <dje@google.com>2012-07-13 23:39:46 +0000
commit0429544a874ce825dffad59bf2b5c0e41d229060 (patch)
treead3d38dd0ee6805e5865606d8efc710883a8efa6 /libiberty/filename_cmp.c
parenta2b6eff5c47ee70428e43a2b9b089d41c4913d89 (diff)
downloadgdb-0429544a874ce825dffad59bf2b5c0e41d229060.zip
gdb-0429544a874ce825dffad59bf2b5c0e41d229060.tar.gz
gdb-0429544a874ce825dffad59bf2b5c0e41d229060.tar.bz2
include/
* filenames.h: #include "hashtab.h". (filename_hash, filename_eq): Declare. libiberty/ * filename_cmp.c (filename_hash, filename_eq): New functions.
Diffstat (limited to 'libiberty/filename_cmp.c')
-rw-r--r--libiberty/filename_cmp.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/libiberty/filename_cmp.c b/libiberty/filename_cmp.c
index 5179f8d..9e16d24 100644
--- a/libiberty/filename_cmp.c
+++ b/libiberty/filename_cmp.c
@@ -141,3 +141,52 @@ filename_ncmp (const char *s1, const char *s2, size_t n)
return 0;
#endif
}
+
+/*
+
+@deftypefn Extension hashval_t filename_hash (const void *@var{s})
+
+Return the hash value for file name @var{s} that will be compared
+using filename_cmp.
+This function is for use with hashtab.c hash tables.
+
+@end deftypefn
+
+*/
+
+hashval_t
+filename_hash (const void *s)
+{
+ /* The cast is for -Wc++-compat. */
+ const unsigned char *str = (const unsigned char *) s;
+ hashval_t r = 0;
+ unsigned char c;
+
+ while ((c = *str++) != 0)
+ {
+ if (c == '\\')
+ c = '/';
+ c = TOLOWER (c);
+ r = r * 67 + c - 113;
+ }
+
+ return r;
+}
+
+/*
+
+@deftypefn Extension int filename_eq (const void *@var{s1}, const void *@var{s2})
+
+Return non-zero if file names @var{s1} and @var{s2} are equivalent.
+This function is for use with hashtab.c hash tables.
+
+@end deftypefn
+
+*/
+
+int
+filename_eq (const void *s1, const void *s2)
+{
+ /* The casts are for -Wc++-compat. */
+ return filename_cmp ((const char *) s1, (const char *) s2) == 0;
+}