1*fae548d3Szrj /* Macros for taking apart, interpreting and processing file names.
2*fae548d3Szrj 
3*fae548d3Szrj    These are here because some non-Posix (a.k.a. DOSish) systems have
4*fae548d3Szrj    drive letter brain-damage at the beginning of an absolute file name,
5*fae548d3Szrj    use forward- and back-slash in path names interchangeably, and
6*fae548d3Szrj    some of them have case-insensitive file names.
7*fae548d3Szrj 
8*fae548d3Szrj    Copyright (C) 2000-2020 Free Software Foundation, Inc.
9*fae548d3Szrj 
10*fae548d3Szrj This file is part of BFD, the Binary File Descriptor library.
11*fae548d3Szrj 
12*fae548d3Szrj This program is free software; you can redistribute it and/or modify
13*fae548d3Szrj it under the terms of the GNU General Public License as published by
14*fae548d3Szrj the Free Software Foundation; either version 2 of the License, or
15*fae548d3Szrj (at your option) any later version.
16*fae548d3Szrj 
17*fae548d3Szrj This program is distributed in the hope that it will be useful,
18*fae548d3Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
19*fae548d3Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20*fae548d3Szrj GNU General Public License for more details.
21*fae548d3Szrj 
22*fae548d3Szrj You should have received a copy of the GNU General Public License
23*fae548d3Szrj along with this program; if not, write to the Free Software
24*fae548d3Szrj Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
25*fae548d3Szrj 
26*fae548d3Szrj #ifndef FILENAMES_H
27*fae548d3Szrj #define FILENAMES_H
28*fae548d3Szrj 
29*fae548d3Szrj #include "hashtab.h" /* for hashval_t */
30*fae548d3Szrj 
31*fae548d3Szrj #ifdef __cplusplus
32*fae548d3Szrj extern "C" {
33*fae548d3Szrj #endif
34*fae548d3Szrj 
35*fae548d3Szrj #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__)
36*fae548d3Szrj #  ifndef HAVE_DOS_BASED_FILE_SYSTEM
37*fae548d3Szrj #    define HAVE_DOS_BASED_FILE_SYSTEM 1
38*fae548d3Szrj #  endif
39*fae548d3Szrj #  ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
40*fae548d3Szrj #    define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
41*fae548d3Szrj #  endif
42*fae548d3Szrj #  define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f)
43*fae548d3Szrj #  define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c)
44*fae548d3Szrj #  define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f)
45*fae548d3Szrj #else /* not DOSish */
46*fae548d3Szrj #  if defined(__APPLE__)
47*fae548d3Szrj #    ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
48*fae548d3Szrj #      define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
49*fae548d3Szrj #    endif
50*fae548d3Szrj #  endif /* __APPLE__ */
51*fae548d3Szrj #  define HAS_DRIVE_SPEC(f) (0)
52*fae548d3Szrj #  define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c)
53*fae548d3Szrj #  define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f)
54*fae548d3Szrj #endif
55*fae548d3Szrj 
56*fae548d3Szrj #define IS_DIR_SEPARATOR_1(dos_based, c)				\
57*fae548d3Szrj   (((c) == '/')								\
58*fae548d3Szrj    || (((c) == '\\') && (dos_based)))
59*fae548d3Szrj 
60*fae548d3Szrj #define HAS_DRIVE_SPEC_1(dos_based, f)			\
61*fae548d3Szrj   ((f)[0] && ((f)[1] == ':') && (dos_based))
62*fae548d3Szrj 
63*fae548d3Szrj /* Remove the drive spec from F, assuming HAS_DRIVE_SPEC (f).
64*fae548d3Szrj    The result is a pointer to the remainder of F.  */
65*fae548d3Szrj #define STRIP_DRIVE_SPEC(f)	((f) + 2)
66*fae548d3Szrj 
67*fae548d3Szrj #define IS_DOS_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (1, c)
68*fae548d3Szrj #define IS_DOS_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (1, f)
69*fae548d3Szrj #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
70*fae548d3Szrj 
71*fae548d3Szrj #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)
72*fae548d3Szrj #define IS_UNIX_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (0, f)
73*fae548d3Szrj 
74*fae548d3Szrj /* Note that when DOS_BASED is true, IS_ABSOLUTE_PATH accepts d:foo as
75*fae548d3Szrj    well, although it is only semi-absolute.  This is because the users
76*fae548d3Szrj    of IS_ABSOLUTE_PATH want to know whether to prepend the current
77*fae548d3Szrj    working directory to a file name, which should not be done with a
78*fae548d3Szrj    name like d:foo.  */
79*fae548d3Szrj #define IS_ABSOLUTE_PATH_1(dos_based, f)		 \
80*fae548d3Szrj   (IS_DIR_SEPARATOR_1 (dos_based, (f)[0])		 \
81*fae548d3Szrj    || HAS_DRIVE_SPEC_1 (dos_based, f))
82*fae548d3Szrj 
83*fae548d3Szrj extern int filename_cmp (const char *s1, const char *s2);
84*fae548d3Szrj #define FILENAME_CMP(s1, s2)	filename_cmp(s1, s2)
85*fae548d3Szrj 
86*fae548d3Szrj extern int filename_ncmp (const char *s1, const char *s2,
87*fae548d3Szrj 			  size_t n);
88*fae548d3Szrj 
89*fae548d3Szrj extern hashval_t filename_hash (const void *s);
90*fae548d3Szrj 
91*fae548d3Szrj extern int filename_eq (const void *s1, const void *s2);
92*fae548d3Szrj 
93*fae548d3Szrj extern int canonical_filename_eq (const char *a, const char *b);
94*fae548d3Szrj 
95*fae548d3Szrj #ifdef __cplusplus
96*fae548d3Szrj }
97*fae548d3Szrj #endif
98*fae548d3Szrj 
99*fae548d3Szrj #endif /* FILENAMES_H */
100