diff options
author | Doug Evans <dje@sebabeach.org> | 2012-07-13 23:39:45 +0000 |
---|---|---|
committer | Doug Evans <dje@sebabeach.org> | 2012-07-13 23:39:45 +0000 |
commit | f07834de578759669ad21b21669d6bf198b28612 (patch) | |
tree | bfe1bd36a14e44e6960f804b38bad1f359110439 /libiberty | |
parent | eb9c9a3b4ab7cc0a17b302eff209ca40dd64fc22 (diff) | |
download | binutils-redhat-f07834de578759669ad21b21669d6bf198b28612.tar.gz |
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')
-rw-r--r-- | libiberty/ChangeLog | 4 | ||||
-rw-r--r-- | libiberty/filename_cmp.c | 49 |
2 files changed, 53 insertions, 0 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 9628e2c4ae..4ece5ab747 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,7 @@ +2012-07-13 Doug Evans <dje@google.com> + + * filename_cmp.c (filename_hash, filename_eq): New functions. + 2012-06-29 Andreas Schwab <schwab@linux-m68k.org> * copying-lib.texi (Library Copying): Don't use @heading inside diff --git a/libiberty/filename_cmp.c b/libiberty/filename_cmp.c index 5179f8dd14..9e16d24208 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; +} |