filenames.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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-2019 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(__OS2__) || defined (__CYGWIN__)
  26. # ifndef HAVE_DOS_BASED_FILE_SYSTEM
  27. # define HAVE_DOS_BASED_FILE_SYSTEM 1
  28. # endif
  29. # ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
  30. # define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
  31. # endif
  32. # define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f)
  33. # define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c)
  34. # define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f)
  35. #else /* not DOSish */
  36. # if defined(__APPLE__)
  37. # ifndef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
  38. # define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1
  39. # endif
  40. # endif /* __APPLE__ */
  41. # define HAS_DRIVE_SPEC(f) (0)
  42. # define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c)
  43. # define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f)
  44. #endif
  45. #define IS_DIR_SEPARATOR_1(dos_based, c) \
  46. (((c) == '/') \
  47. || (((c) == '\\') && (dos_based)))
  48. #define HAS_DRIVE_SPEC_1(dos_based, f) \
  49. ((f)[0] && ((f)[1] == ':') && (dos_based))
  50. /* Remove the drive spec from F, assuming HAS_DRIVE_SPEC (f).
  51. The result is a pointer to the remainder of F. */
  52. #define STRIP_DRIVE_SPEC(f) ((f) + 2)
  53. #define IS_DOS_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (1, c)
  54. #define IS_DOS_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (1, f)
  55. #define HAS_DOS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
  56. #define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)
  57. #define IS_UNIX_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (0, f)
  58. /* Note that when DOS_BASED is true, IS_ABSOLUTE_PATH accepts d:foo as
  59. well, although it is only semi-absolute. This is because the users
  60. of IS_ABSOLUTE_PATH want to know whether to prepend the current
  61. working directory to a file name, which should not be done with a
  62. name like d:foo. */
  63. #define IS_ABSOLUTE_PATH_1(dos_based, f) \
  64. (IS_DIR_SEPARATOR_1 (dos_based, (f)[0]) \
  65. || HAS_DRIVE_SPEC_1 (dos_based, f))
  66. extern int filename_cmp (const char *s1, const char *s2);
  67. #define FILENAME_CMP(s1, s2) filename_cmp(s1, s2)
  68. extern int filename_ncmp (const char *s1, const char *s2,
  69. size_t n);
  70. extern hashval_t filename_hash (const void *s);
  71. extern int filename_eq (const void *s1, const void *s2);
  72. extern int canonical_filename_eq (const char *a, const char *b);
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif /* FILENAMES_H */