Index: src/include/filenames.h =================================================================== --- src.orig/include/filenames.h 2011-02-26 23:07:15.246909100 +0100 +++ src/include/filenames.h 2011-02-27 12:08:39.608504400 +0100 @@ -73,6 +73,9 @@ extern "C" { extern int filename_cmp (const char *s1, const char *s2); #define FILENAME_CMP(s1, s2) filename_cmp(s1, s2) +extern int filename_ncmp (const char *s1, const char *s2, + size_t n); + #ifdef __cplusplus } #endif Index: src/libiberty/filename_cmp.c =================================================================== --- src.orig/libiberty/filename_cmp.c 2011-02-26 23:07:15.247909100 +0100 +++ src/libiberty/filename_cmp.c 2011-02-27 12:08:39.613504700 +0100 @@ -76,3 +76,52 @@ filename_cmp (const char *s1, const char #endif } +/* + +@deftypefn Extension int filename_ncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n}) + +Return zero if the two file names @var{s1} and @var{s2} are equivalent +in range @var{n}. +If not equivalent, the returned value is similar to what @code{strncmp} +would return. In other words, it returns a negative value if @var{s1} +is less than @var{s2}, or a positive value if @var{s2} is greater than +@var{s2}. + +This function does not normalize file names. As a result, this function +will treat filenames that are spelled differently as different even in +the case when the two filenames point to the same underlying file. +However, it does handle the fact that on DOS-like file systems, forward +and backward slashes are equal. + +@end deftypefn + +*/ + +int +filename_ncmp (const char *s1, const char *s2, size_t n) +{ +#ifndef HAVE_DOS_BASED_FILE_SYSTEM + return strncmp(s1, s2, n); +#else + if (!n) + return 0; + for (; n > 0; --n) + { + int c1 = TOLOWER (*s1); + int c2 = TOLOWER (*s2); + + /* On DOS-based file systems, the '/' and the '\' are equivalent. */ + if (c1 == '/') + c1 = '\\'; + if (c2 == '/') + c2 = '\\'; + + if (c1 == '\0' || c1 != c2) + return (c1 - c2); + + s1++; + s2++; + } + return 0; +#endif +} Index: src/libiberty/functions.texi =================================================================== --- src.orig/libiberty/functions.texi 2011-02-26 23:07:15.258909100 +0100 +++ src/libiberty/functions.texi 2011-02-27 12:08:39.618505000 +0100 @@ -296,6 +296,24 @@ and backward slashes are equal. @end deftypefn +@c filename_cmp.c:81 +@deftypefn Extension int filename_ncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n}) + +Return zero if the two file names @var{s1} and @var{s2} are equivalent +in range @var{n}. +If not equivalent, the returned value is similar to what @code{strncmp} +would return. In other words, it returns a negative value if @var{s1} +is less than @var{s2}, or a positive value if @var{s2} is greater than +@var{s2}. + +This function does not normalize file names. As a result, this function +will treat filenames that are spelled differently as different even in +the case when the two filenames point to the same underlying file. +However, it does handle the fact that on DOS-like file systems, forward +and backward slashes are equal. + +@end deftypefn + @c fnmatch.txh:1 @deftypefn Replacement int fnmatch (const char *@var{pattern}, @ const char *@var{string}, int @var{flags}) Index: src/bfd/archive.c =================================================================== --- src.orig/bfd/archive.c 2011-02-26 23:07:15.222909100 +0100 +++ src/bfd/archive.c 2011-02-27 12:08:39.633505800 +0100 @@ -348,7 +348,7 @@ _bfd_find_nested_archive (bfd *arch_bfd, abfd != NULL; abfd = abfd->archive_next) { - if (strcmp (filename, abfd->filename) == 0) + if (filename_cmp (filename, abfd->filename) == 0) return abfd; } abfd = bfd_openr (filename, NULL); @@ -1355,7 +1355,7 @@ adjust_relative_path (const char * path, while (*e2 && ! IS_DIR_SEPARATOR (*e2)) ++e2; if (*e1 == '\0' || *e2 == '\0' || e1 - pathp != e2 - refp - || strncmp (pathp, refp, e1 - pathp) != 0) + || filename_ncmp (pathp, refp, e1 - pathp) != 0) break; pathp = e1 + 1; refp = e2 + 1; @@ -1460,7 +1460,7 @@ _bfd_construct_extended_name_table (bfd /* If the path is the same as the previous path seen, reuse it. This can happen when flattening a thin archive that contains other archives. */ - if (last_filename && strcmp (last_filename, filename) == 0) + if (last_filename && filename_cmp (last_filename, filename) == 0) continue; last_filename = filename; @@ -1506,7 +1506,7 @@ _bfd_construct_extended_name_table (bfd else { struct ar_hdr *hdr = arch_hdr (current); - if (strncmp (normal, hdr->ar_name, thislen) != 0 + if (filename_ncmp (normal, hdr->ar_name, thislen) != 0 || (thislen < sizeof hdr->ar_name && hdr->ar_name[thislen] != ar_padchar (current))) { @@ -1554,7 +1554,7 @@ _bfd_construct_extended_name_table (bfd archive that contains other archives. If the path is relative, adjust it relative to the containing archive. */ - if (last_filename && strcmp (last_filename, filename) == 0) + if (last_filename && filename_cmp (last_filename, filename) == 0) normal = last_filename; else if (! IS_ABSOLUTE_PATH (filename) && ! IS_ABSOLUTE_PATH (abfd->filename)) Index: src/bfd/corefile.c =================================================================== --- src.orig/bfd/corefile.c 2011-02-26 23:07:15.224909100 +0100 +++ src/bfd/corefile.c 2011-02-27 12:08:39.647506600 +0100 @@ -186,6 +186,6 @@ generic_core_file_matches_executable_p ( if (last_slash != NULL) exec = last_slash + 1; - return strcmp (exec, core) == 0; + return filename_cmp (exec, core) == 0; } Index: src/bfd/elf32-bfin.c =================================================================== --- src.orig/bfd/elf32-bfin.c 2011-02-26 23:07:15.225909100 +0100 +++ src/bfd/elf32-bfin.c 2011-02-27 12:08:39.653507000 +0100 @@ -3103,10 +3103,10 @@ bfinfdpic_relocate_section (bfd * output if (silence_segment_error == 1) silence_segment_error = (strlen (input_bfd->filename) == 6 - && strcmp (input_bfd->filename, "crt0.o") == 0) + && filename_cmp (input_bfd->filename, "crt0.o") == 0) || (strlen (input_bfd->filename) > 6 - && strcmp (input_bfd->filename - + strlen (input_bfd->filename) - 7, + && filename_cmp (input_bfd->filename + + strlen (input_bfd->filename) - 7, "/crt0.o") == 0) ? -1 : 0; #endif Index: src/bfd/elf32-frv.c =================================================================== --- src.orig/bfd/elf32-frv.c 2011-02-26 23:07:15.226909100 +0100 +++ src/bfd/elf32-frv.c 2011-02-27 12:08:39.678508400 +0100 @@ -3957,10 +3957,10 @@ elf32_frv_relocate_section (output_bfd, if (silence_segment_error == 1) silence_segment_error = (strlen (input_bfd->filename) == 6 - && strcmp (input_bfd->filename, "crt0.o") == 0) + && filename_cmp (input_bfd->filename, "crt0.o") == 0) || (strlen (input_bfd->filename) > 6 - && strcmp (input_bfd->filename - + strlen (input_bfd->filename) - 7, + && filename_cmp (input_bfd->filename + + strlen (input_bfd->filename) - 7, "/crt0.o") == 0) ? -1 : 0; if (!silence_segment_error Index: src/bfd/elf32-spu.c =================================================================== --- src.orig/bfd/elf32-spu.c 2011-02-26 23:07:15.227909100 +0100 +++ src/bfd/elf32-spu.c 2011-02-27 12:08:39.704509900 +0100 @@ -4067,7 +4067,7 @@ sort_bfds (const void *a, const void *b) bfd *const *abfd1 = a; bfd *const *abfd2 = b; - return strcmp ((*abfd1)->filename, (*abfd2)->filename); + return filename_cmp ((*abfd1)->filename, (*abfd2)->filename); } static unsigned int @@ -4299,7 +4299,7 @@ spu_elf_auto_overlay (struct bfd_link_in qsort (bfd_arr, bfd_count, sizeof (*bfd_arr), sort_bfds); for (i = 1; i < bfd_count; ++i) - if (strcmp (bfd_arr[i - 1]->filename, bfd_arr[i]->filename) == 0) + if (filename_cmp (bfd_arr[i - 1]->filename, bfd_arr[i]->filename) == 0) { if (bfd_arr[i - 1]->my_archive == bfd_arr[i]->my_archive) { Index: src/bfd/syms.c =================================================================== --- src.orig/bfd/syms.c 2011-02-26 23:07:15.229909100 +0100 +++ src/bfd/syms.c 2011-02-27 12:08:39.726511200 +0100 @@ -1386,8 +1386,8 @@ _bfd_stab_section_find_nearest_line (bfd dirlen = strlen (directory_name); if (info->filename == NULL - || strncmp (info->filename, directory_name, dirlen) != 0 - || strcmp (info->filename + dirlen, file_name) != 0) + || filename_ncmp (info->filename, directory_name, dirlen) != 0 + || filename_cmp (info->filename + dirlen, file_name) != 0) { size_t len; Index: src/bfd/xcofflink.c =================================================================== --- src.orig/bfd/xcofflink.c 2011-02-26 23:07:15.230909100 +0100 +++ src/bfd/xcofflink.c 2011-02-27 12:08:39.737511800 +0100 @@ -758,9 +758,9 @@ xcoff_set_import_path (struct bfd_link_i *pp != NULL; pp = &(*pp)->next, ++c) { - if (strcmp ((*pp)->path, imppath) == 0 - && strcmp ((*pp)->file, impfile) == 0 - && strcmp ((*pp)->member, impmember) == 0) + if (filename_cmp ((*pp)->path, imppath) == 0 + && filename_cmp ((*pp)->file, impfile) == 0 + && filename_cmp ((*pp)->member, impmember) == 0) break; } Index: src/bfd/xtensa-isa.c =================================================================== --- src.orig/bfd/xtensa-isa.c 2011-02-26 23:07:15.238909100 +0100 +++ src/bfd/xtensa-isa.c 2011-02-27 12:08:39.763513300 +0100 @@ -1364,7 +1364,7 @@ xtensa_regfile_lookup (xtensa_isa isa, c /* The expected number of regfiles is small; use a linear search. */ for (n = 0; n < intisa->num_regfiles; n++) { - if (!strcmp (intisa->regfiles[n].name, name)) + if (!filename_cmp (intisa->regfiles[n].name, name)) return n; } @@ -1394,7 +1394,7 @@ xtensa_regfile_lookup_shortname (xtensa_ as their parents. */ if (intisa->regfiles[n].parent != n) continue; - if (!strcmp (intisa->regfiles[n].shortname, shortname)) + if (!filename_cmp (intisa->regfiles[n].shortname, shortname)) return n; }