Back to index

cell-binutils  2.17cvs20070401
filename_cmp.c
Go to the documentation of this file.
00001 /* File name comparison routine.
00002 
00003    Copyright (C) 2007 Free Software Foundation, Inc.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2, or (at your option)
00008    any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software Foundation,
00017    Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00018 
00019 #ifdef HAVE_STRING_H
00020 #include <string.h>
00021 #endif
00022 
00023 #include <ctype.h>
00024 #include "filenames.h"
00025 
00026 /*
00027 
00028 @deftypefn Extension int filename_cmp (const char *@var{s1}, const char *@var{s2})
00029 
00030 Return zero if the two paths @var{s1} and @var{s2} are equivalent.
00031 If not equivalent, the returned value is similar to what strcmp would
00032 return.  In other words, it returns a negative value if @var{s1} is less
00033 than @var{s2}, or a positive value if @var{s2} is greater than @var{s2}.
00034 
00035 This function does not normalize path names. As a result, this function
00036 will treat filenames that are spelled differently as different even in
00037 the case when the two filenames point to the same underlying file.
00038 However, it does handle the fact that on DOS-like file systems, forward
00039 and backward slashes are equal.
00040 
00041 @end deftypefn
00042 
00043 */
00044 
00045 int
00046 filename_cmp (const char *s1, const char *s2)
00047 {
00048 #ifndef HAVE_DOS_BASED_FILE_SYSTEM
00049   return strcmp(s1, s2);
00050 #else
00051   for (;;)
00052     {
00053       int c1 = tolower (*s1);
00054       int c2 = tolower (*s2);
00055 
00056       /* On DOS-based file systems, the '/' and the '\' are equivalent.  */
00057       if (c1 == '/')
00058         c1 = '\\';
00059       if (c2 == '/')
00060         c2 = '\\';
00061 
00062       if (c1 != c2)
00063         return (c1 - c2);
00064 
00065       if (c1 == '\0')
00066         return 0;
00067 
00068       s1++;
00069       s2++;
00070     }
00071 #endif
00072 }
00073