(Chunk I forgot to commit on 2008-11-14).
[binutils.git] / libiberty / filename_cmp.c
blob0a4d0d85091709f6d15d15ba1fb3e608fa6e5413
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)
8 any later version.
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. */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
23 #ifdef HAVE_STRING_H
24 #include <string.h>
25 #endif
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
38 @var{s2}.
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.
46 @end deftypefn
50 int
51 filename_cmp (const char *s1, const char *s2)
53 #ifndef HAVE_DOS_BASED_FILE_SYSTEM
54 return strcmp(s1, s2);
55 #else
56 for (;;)
58 int c1 = TOLOWER (*s1);
59 int c2 = TOLOWER (*s2);
61 /* On DOS-based file systems, the '/' and the '\' are equivalent. */
62 if (c1 == '/')
63 c1 = '\\';
64 if (c2 == '/')
65 c2 = '\\';
67 if (c1 != c2)
68 return (c1 - c2);
70 if (c1 == '\0')
71 return 0;
73 s1++;
74 s2++;
76 #endif