1109001Sbenno/* Macros for taking apart, interpreting and processing file names. 2109001Sbenno 3109001Sbenno These are here because some non-Posix (a.k.a. DOSish) systems have 4109001Sbenno drive letter brain-damage at the beginning of an absolute file name, 5109001Sbenno use forward- and back-slash in path names interchangeably, and 6109001Sbenno some of them have case-insensitive file names. 7109001Sbenno 8109001Sbenno Copyright (C) 2000-2022 Free Software Foundation, Inc. 9109001Sbenno 10109001SbennoThis file is part of BFD, the Binary File Descriptor library. 11109001Sbenno 12109001SbennoThis program is free software; you can redistribute it and/or modify 13109001Sbennoit under the terms of the GNU General Public License as published by 14109001Sbennothe Free Software Foundation; either version 2 of the License, or 15109001Sbenno(at your option) any later version. 16109001Sbenno 17109001SbennoThis program is distributed in the hope that it will be useful, 18109001Sbennobut WITHOUT ANY WARRANTY; without even the implied warranty of 19109001SbennoMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20109001SbennoGNU General Public License for more details. 21109001Sbenno 22109001SbennoYou should have received a copy of the GNU General Public License 23109001Sbennoalong with this program; if not, write to the Free Software 24109001SbennoFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 25109001Sbenno 26109001Sbenno#ifndef FILENAMES_H 27109001Sbenno#define FILENAMES_H 28109001Sbenno 29109001Sbenno#include "hashtab.h" /* for hashval_t */ 30109001Sbenno 31109001Sbenno#ifdef __cplusplus 32109001Sbennoextern "C" { 33109001Sbenno#endif 34109001Sbenno 35109001Sbenno#if defined(__MSDOS__) || (defined(_WIN32) && ! defined(__CYGWIN__)) || \ 36109001Sbenno defined(__OS2__) 37109001Sbenno# ifndef HAVE_DOS_BASED_FILE_SYSTEM 38109001Sbenno# define HAVE_DOS_BASED_FILE_SYSTEM 1 39109001Sbenno# endif 40119291Simp# ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM 41119291Simp# define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1 42119291Simp# endif 43109001Sbenno# define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f) 44109001Sbenno# define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c) 45109001Sbenno# define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f) 46109001Sbenno#else /* not DOSish */ 47109001Sbenno# if defined(__APPLE__) 48109001Sbenno# ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM 49109001Sbenno# define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1 50109001Sbenno# endif 51109001Sbenno# endif /* __APPLE__ */ 52109001Sbenno# define HAS_DRIVE_SPEC(f) (0) 53109001Sbenno# define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c) 54109001Sbenno# define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f) 55109001Sbenno#endif 56109001Sbenno 57109001Sbenno#define IS_DIR_SEPARATOR_1(dos_based, c) \ 58109001Sbenno (((c) == '/') \ 59109001Sbenno || (((c) == '\\') && (dos_based))) 60109001Sbenno 61109001Sbenno#define HAS_DRIVE_SPEC_1(dos_based, f) \ 62109001Sbenno ((f)[0] && ((f)[1] == ':') && (dos_based)) 63109001Sbenno 64109001Sbenno/* Remove the drive spec from F, assuming HAS_DRIVE_SPEC (f). 65109001Sbenno The result is a pointer to the remainder of F. */ 66109001Sbenno#define STRIP_DRIVE_SPEC(f) ((f) + 2) 67109001Sbenno 68109001Sbenno#define IS_DOS_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (1, c) 69109001Sbenno#define IS_DOS_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (1, f) 70109001Sbenno#define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f) 71109001Sbenno 72109001Sbenno#define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c) 73109001Sbenno#define IS_UNIX_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (0, f) 74109001Sbenno 75109001Sbenno/* Note that when DOS_BASED is true, IS_ABSOLUTE_PATH accepts d:foo as 76109001Sbenno well, although it is only semi-absolute. This is because the users 77109001Sbenno of IS_ABSOLUTE_PATH want to know whether to prepend the current 78109001Sbenno working directory to a file name, which should not be done with a 79109001Sbenno name like d:foo. */ 80109001Sbenno#define IS_ABSOLUTE_PATH_1(dos_based, f) \ 81109001Sbenno (IS_DIR_SEPARATOR_1 (dos_based, (f)[0]) \ 82109001Sbenno || HAS_DRIVE_SPEC_1 (dos_based, f)) 83109001Sbenno 84109001Sbennoextern int filename_cmp (const char *s1, const char *s2); 85109001Sbenno#define FILENAME_CMP(s1, s2) filename_cmp(s1, s2) 86109001Sbenno 87109001Sbennoextern int filename_ncmp (const char *s1, const char *s2, 88109001Sbenno size_t n); 89109001Sbenno 90109001Sbennoextern hashval_t filename_hash (const void *s); 91109001Sbenno 92109001Sbennoextern int filename_eq (const void *s1, const void *s2); 93109001Sbenno 94109001Sbennoextern int canonical_filename_eq (const char *a, const char *b); 95109001Sbenno 96109001Sbenno#ifdef __cplusplus 97109001Sbenno} 98109001Sbenno#endif 99109001Sbenno 100109001Sbenno#endif /* FILENAMES_H */ 101109001Sbenno