xref: /netbsd-src/external/gpl3/binutils/dist/include/filenames.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
12a6b7db3Sskrll /* Macros for taking apart, interpreting and processing file names.
22a6b7db3Sskrll 
32a6b7db3Sskrll    These are here because some non-Posix (a.k.a. DOSish) systems have
42a6b7db3Sskrll    drive letter brain-damage at the beginning of an absolute file name,
52a6b7db3Sskrll    use forward- and back-slash in path names interchangeably, and
62a6b7db3Sskrll    some of them have case-insensitive file names.
72a6b7db3Sskrll 
8*cb63e24eSchristos    Copyright (C) 2000-2024 Free Software Foundation, Inc.
92a6b7db3Sskrll 
102a6b7db3Sskrll This file is part of BFD, the Binary File Descriptor library.
112a6b7db3Sskrll 
122a6b7db3Sskrll This program is free software; you can redistribute it and/or modify
132a6b7db3Sskrll it under the terms of the GNU General Public License as published by
142a6b7db3Sskrll the Free Software Foundation; either version 2 of the License, or
152a6b7db3Sskrll (at your option) any later version.
162a6b7db3Sskrll 
172a6b7db3Sskrll This program is distributed in the hope that it will be useful,
182a6b7db3Sskrll but WITHOUT ANY WARRANTY; without even the implied warranty of
192a6b7db3Sskrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
202a6b7db3Sskrll GNU General Public License for more details.
212a6b7db3Sskrll 
222a6b7db3Sskrll You should have received a copy of the GNU General Public License
232a6b7db3Sskrll along with this program; if not, write to the Free Software
242a6b7db3Sskrll Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
252a6b7db3Sskrll 
262a6b7db3Sskrll #ifndef FILENAMES_H
272a6b7db3Sskrll #define FILENAMES_H
282a6b7db3Sskrll 
29883529b6Schristos #include "hashtab.h" /* for hashval_t */
30883529b6Schristos 
312a6b7db3Sskrll #ifdef __cplusplus
322a6b7db3Sskrll extern "C" {
332a6b7db3Sskrll #endif
342a6b7db3Sskrll 
354f645668Schristos #if defined(__MSDOS__) || (defined(_WIN32) && ! defined(__CYGWIN__)) || \
364f645668Schristos     defined(__OS2__)
372a6b7db3Sskrll #  ifndef HAVE_DOS_BASED_FILE_SYSTEM
382a6b7db3Sskrll #    define HAVE_DOS_BASED_FILE_SYSTEM 1
392a6b7db3Sskrll #  endif
40883529b6Schristos #  ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
41883529b6Schristos #    define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
42883529b6Schristos #  endif
4345548106Schristos #  define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f)
4445548106Schristos #  define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c)
4545548106Schristos #  define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f)
462a6b7db3Sskrll #else /* not DOSish */
47883529b6Schristos #  if defined(__APPLE__)
48883529b6Schristos #    ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
49883529b6Schristos #      define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
50883529b6Schristos #    endif
51883529b6Schristos #  endif /* __APPLE__ */
5245548106Schristos #  define HAS_DRIVE_SPEC(f) (0)
5345548106Schristos #  define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c)
5445548106Schristos #  define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f)
5545548106Schristos #endif
562a6b7db3Sskrll 
5745548106Schristos #define IS_DIR_SEPARATOR_1(dos_based, c)				\
5845548106Schristos   (((c) == '/')								\
5945548106Schristos    || (((c) == '\\') && (dos_based)))
602a6b7db3Sskrll 
6145548106Schristos #define HAS_DRIVE_SPEC_1(dos_based, f)			\
6245548106Schristos   ((f)[0] && ((f)[1] == ':') && (dos_based))
6345548106Schristos 
6445548106Schristos /* Remove the drive spec from F, assuming HAS_DRIVE_SPEC (f).
6545548106Schristos    The result is a pointer to the remainder of F.  */
6645548106Schristos #define STRIP_DRIVE_SPEC(f)	((f) + 2)
6745548106Schristos 
6845548106Schristos #define IS_DOS_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (1, c)
6945548106Schristos #define IS_DOS_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (1, f)
7045548106Schristos #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
7145548106Schristos 
7245548106Schristos #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)
7345548106Schristos #define IS_UNIX_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (0, f)
7445548106Schristos 
7545548106Schristos /* Note that when DOS_BASED is true, IS_ABSOLUTE_PATH accepts d:foo as
7645548106Schristos    well, although it is only semi-absolute.  This is because the users
7745548106Schristos    of IS_ABSOLUTE_PATH want to know whether to prepend the current
7845548106Schristos    working directory to a file name, which should not be done with a
7945548106Schristos    name like d:foo.  */
8045548106Schristos #define IS_ABSOLUTE_PATH_1(dos_based, f)		 \
8145548106Schristos   (IS_DIR_SEPARATOR_1 (dos_based, (f)[0])		 \
8245548106Schristos    || HAS_DRIVE_SPEC_1 (dos_based, f))
832a6b7db3Sskrll 
842a6b7db3Sskrll extern int filename_cmp (const char *s1, const char *s2);
852a6b7db3Sskrll #define FILENAME_CMP(s1, s2)	filename_cmp(s1, s2)
862a6b7db3Sskrll 
87883529b6Schristos extern int filename_ncmp (const char *s1, const char *s2,
88883529b6Schristos 			  size_t n);
89883529b6Schristos 
90883529b6Schristos extern hashval_t filename_hash (const void *s);
91883529b6Schristos 
92883529b6Schristos extern int filename_eq (const void *s1, const void *s2);
93883529b6Schristos 
949573673dSchristos extern int canonical_filename_eq (const char *a, const char *b);
959573673dSchristos 
962a6b7db3Sskrll #ifdef __cplusplus
972a6b7db3Sskrll }
982a6b7db3Sskrll #endif
992a6b7db3Sskrll 
1002a6b7db3Sskrll #endif /* FILENAMES_H */
101