filenames.h 3.4 KB

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