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