xref: /netbsd-src/external/gpl3/gdb/dist/include/filenames.h (revision e663ba6e3a60083e70de702e9d54bf486a57b6a7)
198b9484cSchristos /* Macros for taking apart, interpreting and processing file names.
298b9484cSchristos 
398b9484cSchristos    These are here because some non-Posix (a.k.a. DOSish) systems have
498b9484cSchristos    drive letter brain-damage at the beginning of an absolute file name,
598b9484cSchristos    use forward- and back-slash in path names interchangeably, and
698b9484cSchristos    some of them have case-insensitive file names.
798b9484cSchristos 
8*e663ba6eSchristos    Copyright (C) 2000-2024 Free Software Foundation, Inc.
998b9484cSchristos 
1098b9484cSchristos This file is part of BFD, the Binary File Descriptor library.
1198b9484cSchristos 
1298b9484cSchristos This program is free software; you can redistribute it and/or modify
1398b9484cSchristos it under the terms of the GNU General Public License as published by
1498b9484cSchristos the Free Software Foundation; either version 2 of the License, or
1598b9484cSchristos (at your option) any later version.
1698b9484cSchristos 
1798b9484cSchristos This program is distributed in the hope that it will be useful,
1898b9484cSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of
1998b9484cSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2098b9484cSchristos GNU General Public License for more details.
2198b9484cSchristos 
2298b9484cSchristos You should have received a copy of the GNU General Public License
2398b9484cSchristos along with this program; if not, write to the Free Software
2498b9484cSchristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
2598b9484cSchristos 
2698b9484cSchristos #ifndef FILENAMES_H
2798b9484cSchristos #define FILENAMES_H
2898b9484cSchristos 
29a2e2270fSchristos #include "hashtab.h" /* for hashval_t */
30a2e2270fSchristos 
3198b9484cSchristos #ifdef __cplusplus
3298b9484cSchristos extern "C" {
3398b9484cSchristos #endif
3498b9484cSchristos 
358dffb485Schristos #if defined(__MSDOS__) || (defined(_WIN32) && ! defined(__CYGWIN__)) || \
368dffb485Schristos     defined(__OS2__)
3798b9484cSchristos #  ifndef HAVE_DOS_BASED_FILE_SYSTEM
3898b9484cSchristos #    define HAVE_DOS_BASED_FILE_SYSTEM 1
3998b9484cSchristos #  endif
40a2e2270fSchristos #  ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
41a2e2270fSchristos #    define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
42a2e2270fSchristos #  endif
4398b9484cSchristos #  define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f)
4498b9484cSchristos #  define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c)
4598b9484cSchristos #  define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f)
4698b9484cSchristos #else /* not DOSish */
47a2e2270fSchristos #  if defined(__APPLE__)
48a2e2270fSchristos #    ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
49a2e2270fSchristos #      define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
50a2e2270fSchristos #    endif
51a2e2270fSchristos #  endif /* __APPLE__ */
5298b9484cSchristos #  define HAS_DRIVE_SPEC(f) (0)
5398b9484cSchristos #  define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c)
5498b9484cSchristos #  define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f)
5598b9484cSchristos #endif
5698b9484cSchristos 
5798b9484cSchristos #define IS_DIR_SEPARATOR_1(dos_based, c)				\
5898b9484cSchristos   (((c) == '/')								\
5998b9484cSchristos    || (((c) == '\\') && (dos_based)))
6098b9484cSchristos 
6198b9484cSchristos #define HAS_DRIVE_SPEC_1(dos_based, f)			\
6298b9484cSchristos   ((f)[0] && ((f)[1] == ':') && (dos_based))
6398b9484cSchristos 
6498b9484cSchristos /* Remove the drive spec from F, assuming HAS_DRIVE_SPEC (f).
6598b9484cSchristos    The result is a pointer to the remainder of F.  */
6698b9484cSchristos #define STRIP_DRIVE_SPEC(f)	((f) + 2)
6798b9484cSchristos 
6898b9484cSchristos #define IS_DOS_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (1, c)
6998b9484cSchristos #define IS_DOS_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (1, f)
7098b9484cSchristos #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
7198b9484cSchristos 
7298b9484cSchristos #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)
7398b9484cSchristos #define IS_UNIX_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (0, f)
7498b9484cSchristos 
7598b9484cSchristos /* Note that when DOS_BASED is true, IS_ABSOLUTE_PATH accepts d:foo as
7698b9484cSchristos    well, although it is only semi-absolute.  This is because the users
7798b9484cSchristos    of IS_ABSOLUTE_PATH want to know whether to prepend the current
7898b9484cSchristos    working directory to a file name, which should not be done with a
7998b9484cSchristos    name like d:foo.  */
8098b9484cSchristos #define IS_ABSOLUTE_PATH_1(dos_based, f)		 \
8198b9484cSchristos   (IS_DIR_SEPARATOR_1 (dos_based, (f)[0])		 \
8298b9484cSchristos    || HAS_DRIVE_SPEC_1 (dos_based, f))
8398b9484cSchristos 
8498b9484cSchristos extern int filename_cmp (const char *s1, const char *s2);
8598b9484cSchristos #define FILENAME_CMP(s1, s2)	filename_cmp(s1, s2)
8698b9484cSchristos 
8798b9484cSchristos extern int filename_ncmp (const char *s1, const char *s2,
8898b9484cSchristos 			  size_t n);
8998b9484cSchristos 
90a2e2270fSchristos extern hashval_t filename_hash (const void *s);
91a2e2270fSchristos 
92a2e2270fSchristos extern int filename_eq (const void *s1, const void *s2);
93a2e2270fSchristos 
94212397c6Schristos extern int canonical_filename_eq (const char *a, const char *b);
95212397c6Schristos 
9698b9484cSchristos #ifdef __cplusplus
9798b9484cSchristos }
9898b9484cSchristos #endif
9998b9484cSchristos 
10098b9484cSchristos #endif /* FILENAMES_H */
101