pathmax.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Define PATH_MAX somehow. Requires sys/types.h.
  2. Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2014 Free Software
  3. Foundation, Inc.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. 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 Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef _PATHMAX_H
  15. # define _PATHMAX_H
  16. /* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename,
  17. including the terminating NUL byte.
  18. <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html>
  19. PATH_MAX is not defined on systems which have no limit on filename length,
  20. such as GNU/Hurd.
  21. This file does *not* define PATH_MAX always. Programs that use this file
  22. can handle the GNU/Hurd case in several ways:
  23. - Either with a package-wide handling, or with a per-file handling,
  24. - Either through a
  25. #ifdef PATH_MAX
  26. or through a fallback like
  27. #ifndef PATH_MAX
  28. # define PATH_MAX 8192
  29. #endif
  30. or through a fallback like
  31. #ifndef PATH_MAX
  32. # define PATH_MAX pathconf ("/", _PC_PATH_MAX)
  33. #endif
  34. */
  35. # include <unistd.h>
  36. # include <limits.h>
  37. # ifndef _POSIX_PATH_MAX
  38. # define _POSIX_PATH_MAX 256
  39. # endif
  40. /* Don't include sys/param.h if it already has been. */
  41. # if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
  42. # include <sys/param.h>
  43. # endif
  44. # if !defined PATH_MAX && defined MAXPATHLEN
  45. # define PATH_MAX MAXPATHLEN
  46. # endif
  47. # ifdef __hpux
  48. /* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename,
  49. *not* including the terminating NUL byte, and is set to 1023.
  50. Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is
  51. not defined at all any more. */
  52. # undef PATH_MAX
  53. # define PATH_MAX 1024
  54. # endif
  55. # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
  56. /* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com,
  57. section "Maximum Path Length Limitation",
  58. <http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#maxpath>
  59. explains that the maximum size of a filename, including the terminating
  60. NUL byte, is 260 = 3 + 256 + 1.
  61. This is the same value as
  62. - FILENAME_MAX in <stdio.h>,
  63. - _MAX_PATH in <stdlib.h>,
  64. - MAX_PATH in <windef.h>.
  65. Undefine the original value, because mingw's <limits.h> gets it wrong. */
  66. # undef PATH_MAX
  67. # define PATH_MAX 260
  68. # endif
  69. #endif /* _PATHMAX_H */