xref: /netbsd-src/external/gpl3/gcc/dist/include/filenames.h (revision b1e838363e3c6fc78a55519254d99869742dd33c)
14fee23f9Smrg /* Macros for taking apart, interpreting and processing file names.
24fee23f9Smrg 
34fee23f9Smrg    These are here because some non-Posix (a.k.a. DOSish) systems have
44fee23f9Smrg    drive letter brain-damage at the beginning of an absolute file name,
54fee23f9Smrg    use forward- and back-slash in path names interchangeably, and
64fee23f9Smrg    some of them have case-insensitive file names.
74fee23f9Smrg 
8*b1e83836Smrg    Copyright (C) 2000-2022 Free Software Foundation, Inc.
94fee23f9Smrg 
104fee23f9Smrg This file is part of BFD, the Binary File Descriptor library.
114fee23f9Smrg 
124fee23f9Smrg This program is free software; you can redistribute it and/or modify
134fee23f9Smrg it under the terms of the GNU General Public License as published by
144fee23f9Smrg the Free Software Foundation; either version 2 of the License, or
154fee23f9Smrg (at your option) any later version.
164fee23f9Smrg 
174fee23f9Smrg This program is distributed in the hope that it will be useful,
184fee23f9Smrg but WITHOUT ANY WARRANTY; without even the implied warranty of
194fee23f9Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
204fee23f9Smrg GNU General Public License for more details.
214fee23f9Smrg 
224fee23f9Smrg You should have received a copy of the GNU General Public License
234fee23f9Smrg along with this program; if not, write to the Free Software
244fee23f9Smrg Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
254fee23f9Smrg 
264fee23f9Smrg #ifndef FILENAMES_H
274fee23f9Smrg #define FILENAMES_H
284fee23f9Smrg 
2948fb7bfaSmrg #include "hashtab.h" /* for hashval_t */
3048fb7bfaSmrg 
314fee23f9Smrg #ifdef __cplusplus
324fee23f9Smrg extern "C" {
334fee23f9Smrg #endif
344fee23f9Smrg 
35ad640425Smrg #if defined(__MSDOS__) || (defined(_WIN32) && ! defined(__CYGWIN__)) || \
36ad640425Smrg     defined(__OS2__)
374fee23f9Smrg #  ifndef HAVE_DOS_BASED_FILE_SYSTEM
384fee23f9Smrg #    define HAVE_DOS_BASED_FILE_SYSTEM 1
394fee23f9Smrg #  endif
4048fb7bfaSmrg #  ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
4148fb7bfaSmrg #    define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
4248fb7bfaSmrg #  endif
4348fb7bfaSmrg #  define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f)
4448fb7bfaSmrg #  define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c)
4548fb7bfaSmrg #  define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f)
464fee23f9Smrg #else /* not DOSish */
4748fb7bfaSmrg #  if defined(__APPLE__)
4848fb7bfaSmrg #    ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
4948fb7bfaSmrg #      define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
5048fb7bfaSmrg #    endif
5148fb7bfaSmrg #  endif /* __APPLE__ */
5248fb7bfaSmrg #  define HAS_DRIVE_SPEC(f) (0)
5348fb7bfaSmrg #  define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c)
5448fb7bfaSmrg #  define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f)
5548fb7bfaSmrg #endif
564fee23f9Smrg 
5748fb7bfaSmrg #define IS_DIR_SEPARATOR_1(dos_based, c)				\
5848fb7bfaSmrg   (((c) == '/')								\
5948fb7bfaSmrg    || (((c) == '\\') && (dos_based)))
604fee23f9Smrg 
6148fb7bfaSmrg #define HAS_DRIVE_SPEC_1(dos_based, f)			\
6248fb7bfaSmrg   ((f)[0] && ((f)[1] == ':') && (dos_based))
6348fb7bfaSmrg 
6448fb7bfaSmrg /* Remove the drive spec from F, assuming HAS_DRIVE_SPEC (f).
6548fb7bfaSmrg    The result is a pointer to the remainder of F.  */
6648fb7bfaSmrg #define STRIP_DRIVE_SPEC(f)	((f) + 2)
6748fb7bfaSmrg 
6848fb7bfaSmrg #define IS_DOS_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (1, c)
6948fb7bfaSmrg #define IS_DOS_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (1, f)
7048fb7bfaSmrg #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
7148fb7bfaSmrg 
7248fb7bfaSmrg #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)
7348fb7bfaSmrg #define IS_UNIX_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (0, f)
7448fb7bfaSmrg 
7548fb7bfaSmrg /* Note that when DOS_BASED is true, IS_ABSOLUTE_PATH accepts d:foo as
7648fb7bfaSmrg    well, although it is only semi-absolute.  This is because the users
7748fb7bfaSmrg    of IS_ABSOLUTE_PATH want to know whether to prepend the current
7848fb7bfaSmrg    working directory to a file name, which should not be done with a
7948fb7bfaSmrg    name like d:foo.  */
8048fb7bfaSmrg #define IS_ABSOLUTE_PATH_1(dos_based, f)		 \
8148fb7bfaSmrg   (IS_DIR_SEPARATOR_1 (dos_based, (f)[0])		 \
8248fb7bfaSmrg    || HAS_DRIVE_SPEC_1 (dos_based, f))
834fee23f9Smrg 
844fee23f9Smrg extern int filename_cmp (const char *s1, const char *s2);
854fee23f9Smrg #define FILENAME_CMP(s1, s2)	filename_cmp(s1, s2)
864fee23f9Smrg 
8748fb7bfaSmrg extern int filename_ncmp (const char *s1, const char *s2,
8848fb7bfaSmrg 			  size_t n);
8948fb7bfaSmrg 
9048fb7bfaSmrg extern hashval_t filename_hash (const void *s);
9148fb7bfaSmrg 
9248fb7bfaSmrg extern int filename_eq (const void *s1, const void *s2);
9348fb7bfaSmrg 
944d5abbe8Smrg extern int canonical_filename_eq (const char *a, const char *b);
954d5abbe8Smrg 
964fee23f9Smrg #ifdef __cplusplus
974fee23f9Smrg }
984fee23f9Smrg #endif
994fee23f9Smrg 
1004fee23f9Smrg #endif /* FILENAMES_H */
101