merge from gcc
[deliverable/binutils-gdb.git] / libiberty / filename_cmp.c
1 /* File name comparison routine.
2
3 Copyright (C) 2007 Free Software Foundation, Inc.
4
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.
9
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.
14
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. */
18
19 #ifdef HAVE_STRING_H
20 #include <string.h>
21 #endif
22
23 #include <ctype.h>
24 #include "filenames.h"
25
26 /*
27
28 @deftypefn Extension int filename_cmp (const char *@var{s1}, const char *@var{s2})
29
30 Return zero if the two paths @var{s1} and @var{s2} are equivalent.
31 If not equivalent, the returned value is similar to what strcmp would
32 return. In other words, it returns a negative value if @var{s1} is less
33 than @var{s2}, or a positive value if @var{s2} is greater than @var{s2}.
34
35 This function does not normalize path names. As a result, this function
36 will treat filenames that are spelled differently as different even in
37 the case when the two filenames point to the same underlying file.
38 However, it does handle the fact that on DOS-like file systems, forward
39 and backward slashes are equal.
40
41 @end deftypefn
42
43 */
44
45 int
46 filename_cmp (const char *s1, const char *s2)
47 {
48 #ifndef HAVE_DOS_BASED_FILE_SYSTEM
49 return strcmp(s1, s2);
50 #else
51 for (;;)
52 {
53 int c1 = tolower (*s1);
54 int c2 = tolower (*s2);
55
56 /* On DOS-based file systems, the '/' and the '\' are equivalent. */
57 if (c1 == '/')
58 c1 = '\\';
59 if (c2 == '/')
60 c2 = '\\';
61
62 if (c1 != c2)
63 return (c1 - c2);
64
65 if (c1 == '\0')
66 return 0;
67
68 s1++;
69 s2++;
70 }
71 #endif
72 }
73
This page took 0.033762 seconds and 5 git commands to generate.