Blame gnulib/lib/pathmax.h

Packit 06dd63
/* Define PATH_MAX somehow.  Requires sys/types.h.
Packit 06dd63
   Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2019 Free Software
Packit 06dd63
   Foundation, Inc.
Packit 06dd63
Packit 06dd63
   This program is free software; you can redistribute it and/or modify
Packit 06dd63
   it under the terms of the GNU Lesser General Public License as published by
Packit 06dd63
   the Free Software Foundation; either version 2.1, or (at your option)
Packit 06dd63
   any later version.
Packit 06dd63
Packit 06dd63
   This program is distributed in the hope that it will be useful,
Packit 06dd63
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 06dd63
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 06dd63
   GNU Lesser General Public License for more details.
Packit 06dd63
Packit 06dd63
   You should have received a copy of the GNU Lesser General Public License
Packit 06dd63
   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
Packit 06dd63
Packit 06dd63
#ifndef _PATHMAX_H
Packit 06dd63
# define _PATHMAX_H
Packit 06dd63
Packit 06dd63
/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename,
Packit 06dd63
   including the terminating NUL byte.
Packit 06dd63
   <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html>
Packit 06dd63
   PATH_MAX is not defined on systems which have no limit on filename length,
Packit 06dd63
   such as GNU/Hurd.
Packit 06dd63
Packit 06dd63
   This file does *not* define PATH_MAX always.  Programs that use this file
Packit 06dd63
   can handle the GNU/Hurd case in several ways:
Packit 06dd63
     - Either with a package-wide handling, or with a per-file handling,
Packit 06dd63
     - Either through a
Packit 06dd63
         #ifdef PATH_MAX
Packit 06dd63
       or through a fallback like
Packit 06dd63
         #ifndef PATH_MAX
Packit 06dd63
         # define PATH_MAX 8192
Packit 06dd63
         #endif
Packit 06dd63
       or through a fallback like
Packit 06dd63
         #ifndef PATH_MAX
Packit 06dd63
         # define PATH_MAX pathconf ("/", _PC_PATH_MAX)
Packit 06dd63
         #endif
Packit 06dd63
 */
Packit 06dd63
Packit 06dd63
# include <unistd.h>
Packit 06dd63
Packit 06dd63
# include <limits.h>
Packit 06dd63
Packit 06dd63
# ifndef _POSIX_PATH_MAX
Packit 06dd63
#  define _POSIX_PATH_MAX 256
Packit 06dd63
# endif
Packit 06dd63
Packit 06dd63
/* Don't include sys/param.h if it already has been.  */
Packit 06dd63
# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
Packit 06dd63
#  include <sys/param.h>
Packit 06dd63
# endif
Packit 06dd63
Packit 06dd63
# if !defined PATH_MAX && defined MAXPATHLEN
Packit 06dd63
#  define PATH_MAX MAXPATHLEN
Packit 06dd63
# endif
Packit 06dd63
Packit 06dd63
# ifdef __hpux
Packit 06dd63
/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename,
Packit 06dd63
   *not* including the terminating NUL byte, and is set to 1023.
Packit 06dd63
   Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is
Packit 06dd63
   not defined at all any more.  */
Packit 06dd63
#  undef PATH_MAX
Packit 06dd63
#  define PATH_MAX 1024
Packit 06dd63
# endif
Packit 06dd63
Packit 06dd63
# if defined _WIN32 && ! defined __CYGWIN__
Packit 06dd63
/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com,
Packit 06dd63
   section "Maximum Path Length Limitation",
Packit 06dd63
   <https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation>
Packit 06dd63
   explains that the maximum size of a filename, including the terminating
Packit 06dd63
   NUL byte, is 260 = 3 + 256 + 1.
Packit 06dd63
   This is the same value as
Packit 06dd63
     - FILENAME_MAX in <stdio.h>,
Packit 06dd63
     - _MAX_PATH in <stdlib.h>,
Packit 06dd63
     - MAX_PATH in <windef.h>.
Packit 06dd63
   Undefine the original value, because mingw's <limits.h> gets it wrong.  */
Packit 06dd63
#  undef PATH_MAX
Packit 06dd63
#  define PATH_MAX 260
Packit 06dd63
# endif
Packit 06dd63
Packit 06dd63
#endif /* _PATHMAX_H */