filenames.h 3.3 KB

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