1cf28ed85SJohn Marino /* Define PATH_MAX somehow. Requires sys/types.h. 2*09d4459fSDaniel Fojt Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2020 Free Software 3cf28ed85SJohn Marino Foundation, Inc. 4cf28ed85SJohn Marino 5cf28ed85SJohn Marino This program is free software; you can redistribute it and/or modify 6cf28ed85SJohn Marino it under the terms of the GNU General Public License as published by 7cf28ed85SJohn Marino the Free Software Foundation; either version 3, or (at your option) 8cf28ed85SJohn Marino any later version. 9cf28ed85SJohn Marino 10cf28ed85SJohn Marino This program is distributed in the hope that it will be useful, 11cf28ed85SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 12cf28ed85SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13cf28ed85SJohn Marino GNU General Public License for more details. 14cf28ed85SJohn Marino 15cf28ed85SJohn Marino You should have received a copy of the GNU General Public License 16*09d4459fSDaniel Fojt along with this program; if not, see <https://www.gnu.org/licenses/>. */ 17cf28ed85SJohn Marino 18cf28ed85SJohn Marino #ifndef _PATHMAX_H 19cf28ed85SJohn Marino # define _PATHMAX_H 20cf28ed85SJohn Marino 21cf28ed85SJohn Marino /* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename, 22cf28ed85SJohn Marino including the terminating NUL byte. 23*09d4459fSDaniel Fojt <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html> 24cf28ed85SJohn Marino PATH_MAX is not defined on systems which have no limit on filename length, 25cf28ed85SJohn Marino such as GNU/Hurd. 26cf28ed85SJohn Marino 27cf28ed85SJohn Marino This file does *not* define PATH_MAX always. Programs that use this file 28cf28ed85SJohn Marino can handle the GNU/Hurd case in several ways: 29cf28ed85SJohn Marino - Either with a package-wide handling, or with a per-file handling, 30cf28ed85SJohn Marino - Either through a 31cf28ed85SJohn Marino #ifdef PATH_MAX 32cf28ed85SJohn Marino or through a fallback like 33cf28ed85SJohn Marino #ifndef PATH_MAX 34cf28ed85SJohn Marino # define PATH_MAX 8192 35cf28ed85SJohn Marino #endif 36cf28ed85SJohn Marino or through a fallback like 37cf28ed85SJohn Marino #ifndef PATH_MAX 38cf28ed85SJohn Marino # define PATH_MAX pathconf ("/", _PC_PATH_MAX) 39cf28ed85SJohn Marino #endif 40cf28ed85SJohn Marino */ 41cf28ed85SJohn Marino 42cf28ed85SJohn Marino # include <unistd.h> 43cf28ed85SJohn Marino 44cf28ed85SJohn Marino # include <limits.h> 45cf28ed85SJohn Marino 46cf28ed85SJohn Marino # ifndef _POSIX_PATH_MAX 47cf28ed85SJohn Marino # define _POSIX_PATH_MAX 256 48cf28ed85SJohn Marino # endif 49cf28ed85SJohn Marino 50cf28ed85SJohn Marino /* Don't include sys/param.h if it already has been. */ 51cf28ed85SJohn Marino # if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN 52cf28ed85SJohn Marino # include <sys/param.h> 53cf28ed85SJohn Marino # endif 54cf28ed85SJohn Marino 55cf28ed85SJohn Marino # if !defined PATH_MAX && defined MAXPATHLEN 56cf28ed85SJohn Marino # define PATH_MAX MAXPATHLEN 57cf28ed85SJohn Marino # endif 58cf28ed85SJohn Marino 59cf28ed85SJohn Marino # ifdef __hpux 60cf28ed85SJohn Marino /* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename, 61cf28ed85SJohn Marino *not* including the terminating NUL byte, and is set to 1023. 62cf28ed85SJohn Marino Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is 63cf28ed85SJohn Marino not defined at all any more. */ 64cf28ed85SJohn Marino # undef PATH_MAX 65cf28ed85SJohn Marino # define PATH_MAX 1024 66cf28ed85SJohn Marino # endif 67cf28ed85SJohn Marino 68*09d4459fSDaniel Fojt # if defined _WIN32 && ! defined __CYGWIN__ 69cf28ed85SJohn Marino /* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com, 70cf28ed85SJohn Marino section "Maximum Path Length Limitation", 71*09d4459fSDaniel Fojt <https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation> 72cf28ed85SJohn Marino explains that the maximum size of a filename, including the terminating 73cf28ed85SJohn Marino NUL byte, is 260 = 3 + 256 + 1. 74cf28ed85SJohn Marino This is the same value as 75cf28ed85SJohn Marino - FILENAME_MAX in <stdio.h>, 76cf28ed85SJohn Marino - _MAX_PATH in <stdlib.h>, 77cf28ed85SJohn Marino - MAX_PATH in <windef.h>. 78cf28ed85SJohn Marino Undefine the original value, because mingw's <limits.h> gets it wrong. */ 79cf28ed85SJohn Marino # undef PATH_MAX 80cf28ed85SJohn Marino # define PATH_MAX 260 81cf28ed85SJohn Marino # endif 82cf28ed85SJohn Marino 83cf28ed85SJohn Marino #endif /* _PATHMAX_H */ 84