1114402Sru// -*- C++ -*-
2151497Sru/* Copyright (C) 1992, 2001, 2003, 2005 Free Software Foundation, Inc.
3114402Sru     Written by James Clark (jjc@jclark.com)
4114402Sru
5114402SruThis file is part of groff.
6114402Sru
7114402Srugroff is free software; you can redistribute it and/or modify it under
8114402Sruthe terms of the GNU General Public License as published by the Free
9114402SruSoftware Foundation; either version 2, or (at your option) any later
10114402Sruversion.
11114402Sru
12114402Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY
13114402SruWARRANTY; without even the implied warranty of MERCHANTABILITY or
14114402SruFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15114402Srufor more details.
16114402Sru
17114402SruYou should have received a copy of the GNU General Public License along
18114402Sruwith groff; see the file COPYING.  If not, write to the Free Software
19151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
20114402Sru
21114402Sru/* file_name_max(dir) does the same as pathconf(dir, _PC_NAME_MAX) */
22114402Sru
23114402Sru#include "lib.h"
24114402Sru
25114402Sru#include <sys/types.h>
26114402Sru
27114402Sru#ifdef HAVE_UNISTD_H
28114402Sru#include <unistd.h>
29114402Sru#endif /* HAVE_UNISTD_H */
30114402Sru
31114402Sru#ifdef _POSIX_VERSION
32114402Sru
33114402Srusize_t file_name_max(const char *fname)
34114402Sru{
35114402Sru  return pathconf(fname, _PC_NAME_MAX);
36114402Sru}
37114402Sru
38114402Sru#else /* not _POSIX_VERSION */
39114402Sru
40114402Sru#ifdef HAVE_DIRENT_H
41114402Sru#include <dirent.h>
42114402Sru#else /* not HAVE_DIRENT_H */
43114402Sru#ifdef HAVE_SYS_DIR_H
44114402Sru#include <sys/dir.h>
45114402Sru#endif /* HAVE_SYS_DIR_H */
46114402Sru#endif /* not HAVE_DIRENT_H */
47114402Sru
48114402Sru#ifndef NAME_MAX
49114402Sru#ifdef MAXNAMLEN
50114402Sru#define NAME_MAX MAXNAMLEN
51114402Sru#else /* !MAXNAMLEN */
52114402Sru#ifdef MAXNAMELEN
53114402Sru#define NAME_MAX MAXNAMELEN
54114402Sru#else /* !MAXNAMELEN */
55114402Sru#define NAME_MAX 14
56114402Sru#endif /* !MAXNAMELEN */
57114402Sru#endif /* !MAXNAMLEN */
58114402Sru#endif /* !NAME_MAX */
59114402Sru
60114402Srusize_t file_name_max(const char *)
61114402Sru{
62114402Sru  return NAME_MAX;
63114402Sru}
64114402Sru
65114402Sru#endif /* not _POSIX_VERSION */
66