dirname.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Take file names apart into directory and base names.
  2. Copyright (C) 1998, 2001, 2003-2006 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #ifndef DIRNAME_H_
  14. # define DIRNAME_H_ 1
  15. # include <stdbool.h>
  16. # include <stddef.h>
  17. # ifndef DIRECTORY_SEPARATOR
  18. # define DIRECTORY_SEPARATOR '/'
  19. # endif
  20. # ifndef ISSLASH
  21. # define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
  22. # endif
  23. # ifndef FILE_SYSTEM_PREFIX_LEN
  24. # if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX
  25. /* This internal macro assumes ASCII, but all hosts that support drive
  26. letters use ASCII. */
  27. # define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \
  28. <= 'z' - 'a')
  29. # define FILE_SYSTEM_PREFIX_LEN(Filename) \
  30. (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
  31. # else
  32. # define FILE_SYSTEM_PREFIX_LEN(Filename) 0
  33. # endif
  34. # endif
  35. # ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
  36. # define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
  37. # endif
  38. # ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
  39. # define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
  40. # endif
  41. # if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
  42. # define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
  43. # else
  44. # define IS_ABSOLUTE_FILE_NAME(F) \
  45. (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F))
  46. # endif
  47. # define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
  48. char *base_name (char const *file);
  49. char *dir_name (char const *file);
  50. size_t base_len (char const *file);
  51. size_t dir_len (char const *file);
  52. char *last_component (char const *file);
  53. bool strip_trailing_slashes (char *file);
  54. #endif /* not DIRNAME_H_ */