1
/* File name comparison routine.
3
Copyright (C) 2007 Free Software Foundation, Inc.
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2, or (at your option)
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software Foundation,
17
Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
27
#include "filenames.h"
28
#include "safe-ctype.h"
32
@deftypefn Extension int filename_cmp (const char *@var{s1}, const char *@var{s2})
34
Return zero if the two file names @var{s1} and @var{s2} are equivalent.
35
If not equivalent, the returned value is similar to what @code{strcmp}
36
would return. In other words, it returns a negative value if @var{s1}
37
is less than @var{s2}, or a positive value if @var{s2} is greater than
40
This function does not normalize file names. As a result, this function
41
will treat filenames that are spelled differently as different even in
42
the case when the two filenames point to the same underlying file.
43
However, it does handle the fact that on DOS-like file systems, forward
44
and backward slashes are equal.
51
filename_cmp (const char *s1, const char *s2)
53
#if !defined(HAVE_DOS_BASED_FILE_SYSTEM) \
54
&& !defined(HAVE_CASE_INSENSITIVE_FILE_SYSTEM)
55
return strcmp(s1, s2);
62
#if defined (HAVE_CASE_INSENSITIVE_FILE_SYSTEM)
67
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
68
/* On DOS-based file systems, the '/' and the '\' are equivalent. */
89
@deftypefn Extension int filename_ncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n})
91
Return zero if the two file names @var{s1} and @var{s2} are equivalent
93
If not equivalent, the returned value is similar to what @code{strncmp}
94
would return. In other words, it returns a negative value if @var{s1}
95
is less than @var{s2}, or a positive value if @var{s2} is greater than
98
This function does not normalize file names. As a result, this function
99
will treat filenames that are spelled differently as different even in
100
the case when the two filenames point to the same underlying file.
101
However, it does handle the fact that on DOS-like file systems, forward
102
and backward slashes are equal.
109
filename_ncmp (const char *s1, const char *s2, size_t n)
111
#if !defined(HAVE_DOS_BASED_FILE_SYSTEM) \
112
&& !defined(HAVE_CASE_INSENSITIVE_FILE_SYSTEM)
113
return strncmp(s1, s2, n);
122
#if defined (HAVE_CASE_INSENSITIVE_FILE_SYSTEM)
127
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
128
/* On DOS-based file systems, the '/' and the '\' are equivalent. */
135
if (c1 == '\0' || c1 != c2)
147
@deftypefn Extension hashval_t filename_hash (const void *@var{s})
149
Return the hash value for file name @var{s} that will be compared
151
This function is for use with hashtab.c hash tables.
158
filename_hash (const void *s)
160
/* The cast is for -Wc++-compat. */
161
const unsigned char *str = (const unsigned char *) s;
165
while ((c = *str++) != 0)
170
r = r * 67 + c - 113;
178
@deftypefn Extension int filename_eq (const void *@var{s1}, const void *@var{s2})
180
Return non-zero if file names @var{s1} and @var{s2} are equivalent.
181
This function is for use with hashtab.c hash tables.
188
filename_eq (const void *s1, const void *s2)
190
/* The casts are for -Wc++-compat. */
191
return filename_cmp ((const char *) s1, (const char *) s2) == 0;