1214571Sdim/* File name comparison routine. 2214571Sdim 3214571Sdim Copyright (C) 2007 Free Software Foundation, Inc. 4214571Sdim 5214571Sdim This program is free software; you can redistribute it and/or modify 6214571Sdim it under the terms of the GNU General Public License as published by 7214571Sdim the Free Software Foundation; either version 2, or (at your option) 8214571Sdim any later version. 9214571Sdim 10214571Sdim This program is distributed in the hope that it will be useful, 11214571Sdim but WITHOUT ANY WARRANTY; without even the implied warranty of 12214571Sdim MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13214571Sdim GNU General Public License for more details. 14214571Sdim 15214571Sdim You should have received a copy of the GNU General Public License 16214571Sdim along with this program; if not, write to the Free Software Foundation, 17214571Sdim Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 18214571Sdim 19214571Sdim#ifdef HAVE_CONFIG_H 20214571Sdim#include "config.h" 21214571Sdim#endif 22214571Sdim 23214571Sdim#ifdef HAVE_STRING_H 24214571Sdim#include <string.h> 25214571Sdim#endif 26214571Sdim 27214571Sdim#include "filenames.h" 28214571Sdim#include "safe-ctype.h" 29214571Sdim 30214571Sdim/* 31214571Sdim 32214571Sdim@deftypefn Extension int filename_cmp (const char *@var{s1}, const char *@var{s2}) 33214571Sdim 34214571SdimReturn zero if the two file names @var{s1} and @var{s2} are equivalent. 35214571SdimIf not equivalent, the returned value is similar to what @code{strcmp} 36214571Sdimwould return. In other words, it returns a negative value if @var{s1} 37214571Sdimis less than @var{s2}, or a positive value if @var{s2} is greater than 38214571Sdim@var{s2}. 39214571Sdim 40214571SdimThis function does not normalize file names. As a result, this function 41214571Sdimwill treat filenames that are spelled differently as different even in 42214571Sdimthe case when the two filenames point to the same underlying file. 43214571SdimHowever, it does handle the fact that on DOS-like file systems, forward 44214571Sdimand backward slashes are equal. 45214571Sdim 46214571Sdim@end deftypefn 47214571Sdim 48214571Sdim*/ 49214571Sdim 50214571Sdimint 51214571Sdimfilename_cmp (const char *s1, const char *s2) 52214571Sdim{ 53214571Sdim#ifndef HAVE_DOS_BASED_FILE_SYSTEM 54214571Sdim return strcmp(s1, s2); 55214571Sdim#else 56214571Sdim for (;;) 57214571Sdim { 58214571Sdim int c1 = TOLOWER (*s1); 59214571Sdim int c2 = TOLOWER (*s2); 60214571Sdim 61214571Sdim /* On DOS-based file systems, the '/' and the '\' are equivalent. */ 62214571Sdim if (c1 == '/') 63214571Sdim c1 = '\\'; 64214571Sdim if (c2 == '/') 65214571Sdim c2 = '\\'; 66214571Sdim 67214571Sdim if (c1 != c2) 68214571Sdim return (c1 - c2); 69214571Sdim 70214571Sdim if (c1 == '\0') 71214571Sdim return 0; 72214571Sdim 73214571Sdim s1++; 74214571Sdim s2++; 75214571Sdim } 76214571Sdim#endif 77214571Sdim} 78214571Sdim 79