pathmax.h 2.9 KB

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