xref: /netbsd-src/external/gpl3/binutils.old/dist/include/filenames.h (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos /* Macros for taking apart, interpreting and processing file names.
275fd0b74Schristos 
375fd0b74Schristos    These are here because some non-Posix (a.k.a. DOSish) systems have
475fd0b74Schristos    drive letter brain-damage at the beginning of an absolute file name,
575fd0b74Schristos    use forward- and back-slash in path names interchangeably, and
675fd0b74Schristos    some of them have case-insensitive file names.
775fd0b74Schristos 
8*e992f068Schristos    Copyright (C) 2000-2022 Free Software Foundation, Inc.
975fd0b74Schristos 
1075fd0b74Schristos This file is part of BFD, the Binary File Descriptor library.
1175fd0b74Schristos 
1275fd0b74Schristos This program is free software; you can redistribute it and/or modify
1375fd0b74Schristos it under the terms of the GNU General Public License as published by
1475fd0b74Schristos the Free Software Foundation; either version 2 of the License, or
1575fd0b74Schristos (at your option) any later version.
1675fd0b74Schristos 
1775fd0b74Schristos This program is distributed in the hope that it will be useful,
1875fd0b74Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
1975fd0b74Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2075fd0b74Schristos GNU General Public License for more details.
2175fd0b74Schristos 
2275fd0b74Schristos You should have received a copy of the GNU General Public License
2375fd0b74Schristos along with this program; if not, write to the Free Software
2475fd0b74Schristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
2575fd0b74Schristos 
2675fd0b74Schristos #ifndef FILENAMES_H
2775fd0b74Schristos #define FILENAMES_H
2875fd0b74Schristos 
2975fd0b74Schristos #include "hashtab.h" /* for hashval_t */
3075fd0b74Schristos 
3175fd0b74Schristos #ifdef __cplusplus
3275fd0b74Schristos extern "C" {
3375fd0b74Schristos #endif
3475fd0b74Schristos 
35*e992f068Schristos #if defined(__MSDOS__) || (defined(_WIN32) && ! defined(__CYGWIN__)) || \
36*e992f068Schristos     defined(__OS2__)
3775fd0b74Schristos #  ifndef HAVE_DOS_BASED_FILE_SYSTEM
3875fd0b74Schristos #    define HAVE_DOS_BASED_FILE_SYSTEM 1
3975fd0b74Schristos #  endif
4075fd0b74Schristos #  ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
4175fd0b74Schristos #    define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
4275fd0b74Schristos #  endif
4375fd0b74Schristos #  define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f)
4475fd0b74Schristos #  define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c)
4575fd0b74Schristos #  define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f)
4675fd0b74Schristos #else /* not DOSish */
4775fd0b74Schristos #  if defined(__APPLE__)
4875fd0b74Schristos #    ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
4975fd0b74Schristos #      define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
5075fd0b74Schristos #    endif
5175fd0b74Schristos #  endif /* __APPLE__ */
5275fd0b74Schristos #  define HAS_DRIVE_SPEC(f) (0)
5375fd0b74Schristos #  define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c)
5475fd0b74Schristos #  define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f)
5575fd0b74Schristos #endif
5675fd0b74Schristos 
5775fd0b74Schristos #define IS_DIR_SEPARATOR_1(dos_based, c)				\
5875fd0b74Schristos   (((c) == '/')								\
5975fd0b74Schristos    || (((c) == '\\') && (dos_based)))
6075fd0b74Schristos 
6175fd0b74Schristos #define HAS_DRIVE_SPEC_1(dos_based, f)			\
6275fd0b74Schristos   ((f)[0] && ((f)[1] == ':') && (dos_based))
6375fd0b74Schristos 
6475fd0b74Schristos /* Remove the drive spec from F, assuming HAS_DRIVE_SPEC (f).
6575fd0b74Schristos    The result is a pointer to the remainder of F.  */
6675fd0b74Schristos #define STRIP_DRIVE_SPEC(f)	((f) + 2)
6775fd0b74Schristos 
6875fd0b74Schristos #define IS_DOS_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (1, c)
6975fd0b74Schristos #define IS_DOS_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (1, f)
7075fd0b74Schristos #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
7175fd0b74Schristos 
7275fd0b74Schristos #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)
7375fd0b74Schristos #define IS_UNIX_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (0, f)
7475fd0b74Schristos 
7575fd0b74Schristos /* Note that when DOS_BASED is true, IS_ABSOLUTE_PATH accepts d:foo as
7675fd0b74Schristos    well, although it is only semi-absolute.  This is because the users
7775fd0b74Schristos    of IS_ABSOLUTE_PATH want to know whether to prepend the current
7875fd0b74Schristos    working directory to a file name, which should not be done with a
7975fd0b74Schristos    name like d:foo.  */
8075fd0b74Schristos #define IS_ABSOLUTE_PATH_1(dos_based, f)		 \
8175fd0b74Schristos   (IS_DIR_SEPARATOR_1 (dos_based, (f)[0])		 \
8275fd0b74Schristos    || HAS_DRIVE_SPEC_1 (dos_based, f))
8375fd0b74Schristos 
8475fd0b74Schristos extern int filename_cmp (const char *s1, const char *s2);
8575fd0b74Schristos #define FILENAME_CMP(s1, s2)	filename_cmp(s1, s2)
8675fd0b74Schristos 
8775fd0b74Schristos extern int filename_ncmp (const char *s1, const char *s2,
8875fd0b74Schristos 			  size_t n);
8975fd0b74Schristos 
9075fd0b74Schristos extern hashval_t filename_hash (const void *s);
9175fd0b74Schristos 
9275fd0b74Schristos extern int filename_eq (const void *s1, const void *s2);
9375fd0b74Schristos 
9475fd0b74Schristos extern int canonical_filename_eq (const char *a, const char *b);
9575fd0b74Schristos 
9675fd0b74Schristos #ifdef __cplusplus
9775fd0b74Schristos }
9875fd0b74Schristos #endif
9975fd0b74Schristos 
10075fd0b74Schristos #endif /* FILENAMES_H */
101