maxfilename.cpp revision 302408
18471Sache// -*- C++ -*-
28471Sache/* Copyright (C) 1992, 2001, 2003, 2005 Free Software Foundation, Inc.
38471Sache     Written by James Clark (jjc@jclark.com)
4105806Sjhb
58471SacheThis file is part of groff.
68471Sache
78471Sachegroff is free software; you can redistribute it and/or modify it under
88471Sachethe terms of the GNU General Public License as published by the Free
98471SacheSoftware Foundation; either version 2, or (at your option) any later
108471Sacheversion.
118471Sache
128471Sachegroff is distributed in the hope that it will be useful, but WITHOUT ANY
138471SacheWARRANTY; without even the implied warranty of MERCHANTABILITY or
148471SacheFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
158471Sachefor more details.
168471Sache
178471SacheYou should have received a copy of the GNU General Public License along
188471Sachewith groff; see the file COPYING.  If not, write to the Free Software
198471SacheFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
208471Sache
218471Sache/* file_name_max(dir) does the same as pathconf(dir, _PC_NAME_MAX) */
228471Sache
238471Sache#include "lib.h"
248471Sache
258471Sache#include <sys/types.h>
268471Sache
2751654Sphk#ifdef HAVE_UNISTD_H
2851654Sphk#include <unistd.h>
298471Sache#endif /* HAVE_UNISTD_H */
308471Sache
318471Sache#ifdef _POSIX_VERSION
328471Sache
338471Sachesize_t file_name_max(const char *fname)
348471Sache{
358471Sache  return pathconf(fname, _PC_NAME_MAX);
369232Sache}
378471Sache
38111899Sdas#else /* not _POSIX_VERSION */
39111899Sdas
408471Sache#ifdef HAVE_DIRENT_H
418471Sache#include <dirent.h>
42105806Sjhb#else /* not HAVE_DIRENT_H */
438471Sache#ifdef HAVE_SYS_DIR_H
4424131Sbde#include <sys/dir.h>
4538246Sbde#endif /* HAVE_SYS_DIR_H */
46105806Sjhb#endif /* not HAVE_DIRENT_H */
47105806Sjhb
48129879Sphk#ifndef NAME_MAX
49105806Sjhb#ifdef MAXNAMLEN
50105806Sjhb#define NAME_MAX MAXNAMLEN
51105806Sjhb#else /* !MAXNAMLEN */
52105806Sjhb#ifdef MAXNAMELEN
5366824Sbde#define NAME_MAX MAXNAMELEN
54105806Sjhb#else /* !MAXNAMELEN */
55105806Sjhb#define NAME_MAX 14
56105806Sjhb#endif /* !MAXNAMELEN */
578471Sache#endif /* !MAXNAMLEN */
58105806Sjhb#endif /* !NAME_MAX */
598471Sache
60105806Sjhbsize_t file_name_max(const char *)
61105806Sjhb{
628471Sache  return NAME_MAX;
63105806Sjhb}
64105806Sjhb
658471Sache#endif /* not _POSIX_VERSION */
66105806Sjhb