11debfc3dSmrg /* Macros for taking apart, interpreting and processing file names. 21debfc3dSmrg 31debfc3dSmrg These are here because some non-Posix (a.k.a. DOSish) systems have 41debfc3dSmrg drive letter brain-damage at the beginning of an absolute file name, 51debfc3dSmrg use forward- and back-slash in path names interchangeably, and 61debfc3dSmrg some of them have case-insensitive file names. 71debfc3dSmrg 8*8feb0f0bSmrg Copyright (C) 2000-2020 Free Software Foundation, Inc. 91debfc3dSmrg 101debfc3dSmrg This file is part of BFD, the Binary File Descriptor library. 111debfc3dSmrg 121debfc3dSmrg This program is free software; you can redistribute it and/or modify 131debfc3dSmrg it under the terms of the GNU General Public License as published by 141debfc3dSmrg the Free Software Foundation; either version 2 of the License, or 151debfc3dSmrg (at your option) any later version. 161debfc3dSmrg 171debfc3dSmrg This program is distributed in the hope that it will be useful, 181debfc3dSmrg but WITHOUT ANY WARRANTY; without even the implied warranty of 191debfc3dSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 201debfc3dSmrg GNU General Public License for more details. 211debfc3dSmrg 221debfc3dSmrg You should have received a copy of the GNU General Public License 231debfc3dSmrg along with this program; if not, write to the Free Software 241debfc3dSmrg Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 251debfc3dSmrg 261debfc3dSmrg #ifndef FILENAMES_H 271debfc3dSmrg #define FILENAMES_H 281debfc3dSmrg 291debfc3dSmrg #include "hashtab.h" /* for hashval_t */ 301debfc3dSmrg 311debfc3dSmrg #ifdef __cplusplus 321debfc3dSmrg extern "C" { 331debfc3dSmrg #endif 341debfc3dSmrg 35*8feb0f0bSmrg #if defined(__MSDOS__) || (defined(_WIN32) && ! defined(__CYGWIN__)) || \ 36*8feb0f0bSmrg defined(__OS2__) 371debfc3dSmrg # ifndef HAVE_DOS_BASED_FILE_SYSTEM 381debfc3dSmrg # define HAVE_DOS_BASED_FILE_SYSTEM 1 391debfc3dSmrg # endif 401debfc3dSmrg # ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM 411debfc3dSmrg # define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1 421debfc3dSmrg # endif 431debfc3dSmrg # define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f) 441debfc3dSmrg # define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c) 451debfc3dSmrg # define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f) 461debfc3dSmrg #else /* not DOSish */ 471debfc3dSmrg # if defined(__APPLE__) 481debfc3dSmrg # ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM 491debfc3dSmrg # define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1 501debfc3dSmrg # endif 511debfc3dSmrg # endif /* __APPLE__ */ 521debfc3dSmrg # define HAS_DRIVE_SPEC(f) (0) 531debfc3dSmrg # define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c) 541debfc3dSmrg # define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f) 551debfc3dSmrg #endif 561debfc3dSmrg 571debfc3dSmrg #define IS_DIR_SEPARATOR_1(dos_based, c) \ 581debfc3dSmrg (((c) == '/') \ 591debfc3dSmrg || (((c) == '\\') && (dos_based))) 601debfc3dSmrg 611debfc3dSmrg #define HAS_DRIVE_SPEC_1(dos_based, f) \ 621debfc3dSmrg ((f)[0] && ((f)[1] == ':') && (dos_based)) 631debfc3dSmrg 641debfc3dSmrg /* Remove the drive spec from F, assuming HAS_DRIVE_SPEC (f). 651debfc3dSmrg The result is a pointer to the remainder of F. */ 661debfc3dSmrg #define STRIP_DRIVE_SPEC(f) ((f) + 2) 671debfc3dSmrg 681debfc3dSmrg #define IS_DOS_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (1, c) 691debfc3dSmrg #define IS_DOS_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (1, f) 701debfc3dSmrg #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f) 711debfc3dSmrg 721debfc3dSmrg #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c) 731debfc3dSmrg #define IS_UNIX_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (0, f) 741debfc3dSmrg 751debfc3dSmrg /* Note that when DOS_BASED is true, IS_ABSOLUTE_PATH accepts d:foo as 761debfc3dSmrg well, although it is only semi-absolute. This is because the users 771debfc3dSmrg of IS_ABSOLUTE_PATH want to know whether to prepend the current 781debfc3dSmrg working directory to a file name, which should not be done with a 791debfc3dSmrg name like d:foo. */ 801debfc3dSmrg #define IS_ABSOLUTE_PATH_1(dos_based, f) \ 811debfc3dSmrg (IS_DIR_SEPARATOR_1 (dos_based, (f)[0]) \ 821debfc3dSmrg || HAS_DRIVE_SPEC_1 (dos_based, f)) 831debfc3dSmrg 841debfc3dSmrg extern int filename_cmp (const char *s1, const char *s2); 851debfc3dSmrg #define FILENAME_CMP(s1, s2) filename_cmp(s1, s2) 861debfc3dSmrg 871debfc3dSmrg extern int filename_ncmp (const char *s1, const char *s2, 881debfc3dSmrg size_t n); 891debfc3dSmrg 901debfc3dSmrg extern hashval_t filename_hash (const void *s); 911debfc3dSmrg 921debfc3dSmrg extern int filename_eq (const void *s1, const void *s2); 931debfc3dSmrg 941debfc3dSmrg extern int canonical_filename_eq (const char *a, const char *b); 951debfc3dSmrg 961debfc3dSmrg #ifdef __cplusplus 971debfc3dSmrg } 981debfc3dSmrg #endif 991debfc3dSmrg 1001debfc3dSmrg #endif /* FILENAMES_H */ 101