filename.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Basic filename support macros.
  2. Copyright (C) 2001-2004, 2007-2013 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 _FILENAME_H
  14. #define _FILENAME_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /* Pathname support.
  19. ISSLASH(C) tests whether C is a directory separator character.
  20. IS_ABSOLUTE_PATH(P) tests whether P is an absolute path. If it is not,
  21. it may be concatenated to a directory pathname.
  22. IS_PATH_WITH_DIR(P) tests whether P contains a directory specification.
  23. */
  24. #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
  25. /* Native Windows, Cygwin, OS/2, DOS */
  26. # define ISSLASH(C) ((C) == '/' || (C) == '\\')
  27. # define HAS_DEVICE(P) \
  28. ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
  29. && (P)[1] == ':')
  30. # define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P))
  31. # define IS_PATH_WITH_DIR(P) \
  32. (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
  33. # define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
  34. #else
  35. /* Unix */
  36. # define ISSLASH(C) ((C) == '/')
  37. # define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0])
  38. # define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
  39. # define FILE_SYSTEM_PREFIX_LEN(P) 0
  40. #endif
  41. #ifdef __cplusplus
  42. }
  43. #endif
  44. #endif /* _FILENAME_H */