xref: /netbsd-src/external/gpl2/groff/dist/src/libs/libgroff/maxpathname.cpp (revision 89a07cf815a29524268025a1139fac4c5190f765)
1*89a07cf8Schristos /*	$NetBSD: maxpathname.cpp,v 1.1.1.1 2016/01/13 18:41:48 christos Exp $	*/
2*89a07cf8Schristos 
3*89a07cf8Schristos // -*- C++ -*-
4*89a07cf8Schristos /* Copyright (C) 2005 Free Software Foundation, Inc.
5*89a07cf8Schristos      Written by Werner Lemberg (wl@gnu.org)
6*89a07cf8Schristos 
7*89a07cf8Schristos This file is part of groff.
8*89a07cf8Schristos 
9*89a07cf8Schristos groff is free software; you can redistribute it and/or modify it under
10*89a07cf8Schristos the terms of the GNU General Public License as published by the Free
11*89a07cf8Schristos Software Foundation; either version 2, or (at your option) any later
12*89a07cf8Schristos version.
13*89a07cf8Schristos 
14*89a07cf8Schristos groff is distributed in the hope that it will be useful, but WITHOUT ANY
15*89a07cf8Schristos WARRANTY; without even the implied warranty of MERCHANTABILITY or
16*89a07cf8Schristos FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17*89a07cf8Schristos for more details.
18*89a07cf8Schristos 
19*89a07cf8Schristos You should have received a copy of the GNU General Public License along
20*89a07cf8Schristos with groff; see the file COPYING.  If not, write to the Free Software
21*89a07cf8Schristos Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
22*89a07cf8Schristos 
23*89a07cf8Schristos /* path_name_max(dir) does the same as pathconf(dir, _PC_PATH_MAX) */
24*89a07cf8Schristos 
25*89a07cf8Schristos #include "lib.h"
26*89a07cf8Schristos 
27*89a07cf8Schristos #include <sys/types.h>
28*89a07cf8Schristos 
29*89a07cf8Schristos #ifdef HAVE_UNISTD_H
30*89a07cf8Schristos #include <unistd.h>
31*89a07cf8Schristos #endif /* HAVE_UNISTD_H */
32*89a07cf8Schristos 
33*89a07cf8Schristos #ifdef _POSIX_VERSION
34*89a07cf8Schristos 
path_name_max()35*89a07cf8Schristos size_t path_name_max()
36*89a07cf8Schristos {
37*89a07cf8Schristos   return pathconf("/", _PC_PATH_MAX) < 1 ? 1024 : pathconf("/",_PC_PATH_MAX);
38*89a07cf8Schristos }
39*89a07cf8Schristos 
40*89a07cf8Schristos #else /* not _POSIX_VERSION */
41*89a07cf8Schristos 
42*89a07cf8Schristos #include <stdlib.h>
43*89a07cf8Schristos 
44*89a07cf8Schristos #ifdef HAVE_DIRENT_H
45*89a07cf8Schristos # include <dirent.h>
46*89a07cf8Schristos #else /* not HAVE_DIRENT_H */
47*89a07cf8Schristos # ifdef HAVE_SYS_DIR_H
48*89a07cf8Schristos #  include <sys/dir.h>
49*89a07cf8Schristos # endif /* HAVE_SYS_DIR_H */
50*89a07cf8Schristos #endif /* not HAVE_DIRENT_H */
51*89a07cf8Schristos 
52*89a07cf8Schristos #ifndef PATH_MAX
53*89a07cf8Schristos # ifdef MAXPATHLEN
54*89a07cf8Schristos #  define PATH_MAX MAXPATHLEN
55*89a07cf8Schristos # else /* !MAXPATHLEN */
56*89a07cf8Schristos #  ifdef MAX_PATH
57*89a07cf8Schristos #   define PATH_MAX MAX_PATH
58*89a07cf8Schristos #  else /* !MAX_PATH */
59*89a07cf8Schristos #   ifdef _MAX_PATH
60*89a07cf8Schristos #    define PATH_MAX _MAX_PATH
61*89a07cf8Schristos #   else /* !_MAX_PATH */
62*89a07cf8Schristos #    define PATH_MAX 255
63*89a07cf8Schristos #   endif /* !_MAX_PATH */
64*89a07cf8Schristos #  endif /* !MAX_PATH */
65*89a07cf8Schristos # endif /* !MAXPATHLEN */
66*89a07cf8Schristos #endif /* !PATH_MAX */
67*89a07cf8Schristos 
path_name_max()68*89a07cf8Schristos size_t path_name_max()
69*89a07cf8Schristos {
70*89a07cf8Schristos   return PATH_MAX;
71*89a07cf8Schristos }
72*89a07cf8Schristos 
73*89a07cf8Schristos #endif /* not _POSIX_VERSION */
74