15796c8dcSSimon Schubert /* Macros for taking apart, interpreting and processing file names. 25796c8dcSSimon Schubert 35796c8dcSSimon Schubert These are here because some non-Posix (a.k.a. DOSish) systems have 45796c8dcSSimon Schubert drive letter brain-damage at the beginning of an absolute file name, 55796c8dcSSimon Schubert use forward- and back-slash in path names interchangeably, and 65796c8dcSSimon Schubert some of them have case-insensitive file names. 75796c8dcSSimon Schubert 8cf7f2e2dSJohn Marino Copyright 2000, 2001, 2007, 2010 Free Software Foundation, Inc. 95796c8dcSSimon Schubert 105796c8dcSSimon Schubert This file is part of BFD, the Binary File Descriptor library. 115796c8dcSSimon Schubert 125796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 135796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 145796c8dcSSimon Schubert the Free Software Foundation; either version 2 of the License, or 155796c8dcSSimon Schubert (at your option) any later version. 165796c8dcSSimon Schubert 175796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 185796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 195796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 205796c8dcSSimon Schubert GNU General Public License for more details. 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 235796c8dcSSimon Schubert along with this program; if not, write to the Free Software 245796c8dcSSimon Schubert Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 255796c8dcSSimon Schubert 265796c8dcSSimon Schubert #ifndef FILENAMES_H 275796c8dcSSimon Schubert #define FILENAMES_H 285796c8dcSSimon Schubert 29*ef5ccd6cSJohn Marino #include "hashtab.h" /* for hashval_t */ 30*ef5ccd6cSJohn Marino 315796c8dcSSimon Schubert #ifdef __cplusplus 325796c8dcSSimon Schubert extern "C" { 335796c8dcSSimon Schubert #endif 345796c8dcSSimon Schubert 355796c8dcSSimon Schubert #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__) 365796c8dcSSimon Schubert # ifndef HAVE_DOS_BASED_FILE_SYSTEM 375796c8dcSSimon Schubert # define HAVE_DOS_BASED_FILE_SYSTEM 1 385796c8dcSSimon Schubert # endif 39a45ae5f8SJohn Marino # ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM 40a45ae5f8SJohn Marino # define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1 41a45ae5f8SJohn Marino # endif 42cf7f2e2dSJohn Marino # define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f) 43cf7f2e2dSJohn Marino # define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c) 44cf7f2e2dSJohn Marino # define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f) 455796c8dcSSimon Schubert #else /* not DOSish */ 46a45ae5f8SJohn Marino # if defined(__APPLE__) 47a45ae5f8SJohn Marino # ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM 48a45ae5f8SJohn Marino # define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1 49a45ae5f8SJohn Marino # endif 50a45ae5f8SJohn Marino # endif /* __APPLE__ */ 51cf7f2e2dSJohn Marino # define HAS_DRIVE_SPEC(f) (0) 52cf7f2e2dSJohn Marino # define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c) 53cf7f2e2dSJohn Marino # define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f) 54cf7f2e2dSJohn Marino #endif 555796c8dcSSimon Schubert 56cf7f2e2dSJohn Marino #define IS_DIR_SEPARATOR_1(dos_based, c) \ 57cf7f2e2dSJohn Marino (((c) == '/') \ 58cf7f2e2dSJohn Marino || (((c) == '\\') && (dos_based))) 595796c8dcSSimon Schubert 60cf7f2e2dSJohn Marino #define HAS_DRIVE_SPEC_1(dos_based, f) \ 61cf7f2e2dSJohn Marino ((f)[0] && ((f)[1] == ':') && (dos_based)) 62cf7f2e2dSJohn Marino 63cf7f2e2dSJohn Marino /* Remove the drive spec from F, assuming HAS_DRIVE_SPEC (f). 64cf7f2e2dSJohn Marino The result is a pointer to the remainder of F. */ 65cf7f2e2dSJohn Marino #define STRIP_DRIVE_SPEC(f) ((f) + 2) 66cf7f2e2dSJohn Marino 67cf7f2e2dSJohn Marino #define IS_DOS_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (1, c) 68cf7f2e2dSJohn Marino #define IS_DOS_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (1, f) 69cf7f2e2dSJohn Marino #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f) 70cf7f2e2dSJohn Marino 71cf7f2e2dSJohn Marino #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c) 72cf7f2e2dSJohn Marino #define IS_UNIX_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (0, f) 73cf7f2e2dSJohn Marino 74cf7f2e2dSJohn Marino /* Note that when DOS_BASED is true, IS_ABSOLUTE_PATH accepts d:foo as 75cf7f2e2dSJohn Marino well, although it is only semi-absolute. This is because the users 76cf7f2e2dSJohn Marino of IS_ABSOLUTE_PATH want to know whether to prepend the current 77cf7f2e2dSJohn Marino working directory to a file name, which should not be done with a 78cf7f2e2dSJohn Marino name like d:foo. */ 79cf7f2e2dSJohn Marino #define IS_ABSOLUTE_PATH_1(dos_based, f) \ 80cf7f2e2dSJohn Marino (IS_DIR_SEPARATOR_1 (dos_based, (f)[0]) \ 81cf7f2e2dSJohn Marino || HAS_DRIVE_SPEC_1 (dos_based, f)) 825796c8dcSSimon Schubert 835796c8dcSSimon Schubert extern int filename_cmp (const char *s1, const char *s2); 845796c8dcSSimon Schubert #define FILENAME_CMP(s1, s2) filename_cmp(s1, s2) 855796c8dcSSimon Schubert 86c50c785cSJohn Marino extern int filename_ncmp (const char *s1, const char *s2, 87c50c785cSJohn Marino size_t n); 88c50c785cSJohn Marino 89*ef5ccd6cSJohn Marino extern hashval_t filename_hash (const void *s); 90*ef5ccd6cSJohn Marino 91*ef5ccd6cSJohn Marino extern int filename_eq (const void *s1, const void *s2); 92*ef5ccd6cSJohn Marino 935796c8dcSSimon Schubert #ifdef __cplusplus 945796c8dcSSimon Schubert } 955796c8dcSSimon Schubert #endif 965796c8dcSSimon Schubert 975796c8dcSSimon Schubert #endif /* FILENAMES_H */ 98