dirname.h 2.3 KB

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