maxpathname.cpp revision 256281
1217044Snwhitehorn// -*- C++ -*- 2217044Snwhitehorn/* Copyright (C) 2005 Free Software Foundation, Inc. 3217044Snwhitehorn Written by Werner Lemberg (wl@gnu.org) 4217044Snwhitehorn 5217044SnwhitehornThis file is part of groff. 6217044Snwhitehorn 7217044Snwhitehorngroff is free software; you can redistribute it and/or modify it under 8217044Snwhitehornthe terms of the GNU General Public License as published by the Free 9217044SnwhitehornSoftware Foundation; either version 2, or (at your option) any later 10217044Snwhitehornversion. 11217044Snwhitehorn 12217044Snwhitehorngroff is distributed in the hope that it will be useful, but WITHOUT ANY 13217044SnwhitehornWARRANTY; without even the implied warranty of MERCHANTABILITY or 14217044SnwhitehornFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15217044Snwhitehornfor more details. 16217044Snwhitehorn 17217044SnwhitehornYou should have received a copy of the GNU General Public License along 18217044Snwhitehornwith groff; see the file COPYING. If not, write to the Free Software 19217044SnwhitehornFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 20217044Snwhitehorn 21217044Snwhitehorn/* path_name_max(dir) does the same as pathconf(dir, _PC_PATH_MAX) */ 22217044Snwhitehorn 23217044Snwhitehorn#include "lib.h" 24217044Snwhitehorn 25217044Snwhitehorn#include <sys/types.h> 26217044Snwhitehorn 27217044Snwhitehorn#ifdef HAVE_UNISTD_H 28217044Snwhitehorn#include <unistd.h> 29217044Snwhitehorn#endif /* HAVE_UNISTD_H */ 30217044Snwhitehorn 31217044Snwhitehorn#ifdef _POSIX_VERSION 32217044Snwhitehorn 33217044Snwhitehornsize_t path_name_max() 34217044Snwhitehorn{ 35217044Snwhitehorn return pathconf("/", _PC_PATH_MAX) < 1 ? 1024 : pathconf("/",_PC_PATH_MAX); 36224106Snwhitehorn} 37224106Snwhitehorn 38217044Snwhitehorn#else /* not _POSIX_VERSION */ 39224106Snwhitehorn 40217044Snwhitehorn#include <stdlib.h> 41217044Snwhitehorn 42217044Snwhitehorn#ifdef HAVE_DIRENT_H 43217044Snwhitehorn# include <dirent.h> 44217044Snwhitehorn#else /* not HAVE_DIRENT_H */ 45217044Snwhitehorn# ifdef HAVE_SYS_DIR_H 46217044Snwhitehorn# include <sys/dir.h> 47217044Snwhitehorn# endif /* HAVE_SYS_DIR_H */ 48217044Snwhitehorn#endif /* not HAVE_DIRENT_H */ 49217044Snwhitehorn 50224106Snwhitehorn#ifndef PATH_MAX 51217044Snwhitehorn# ifdef MAXPATHLEN 52217044Snwhitehorn# define PATH_MAX MAXPATHLEN 53217044Snwhitehorn# else /* !MAXPATHLEN */ 54217044Snwhitehorn# ifdef MAX_PATH 55217044Snwhitehorn# define PATH_MAX MAX_PATH 56217044Snwhitehorn# else /* !MAX_PATH */ 57217044Snwhitehorn# ifdef _MAX_PATH 58217044Snwhitehorn# define PATH_MAX _MAX_PATH 59217044Snwhitehorn# else /* !_MAX_PATH */ 60217044Snwhitehorn# define PATH_MAX 255 61217044Snwhitehorn# endif /* !_MAX_PATH */ 62217044Snwhitehorn# endif /* !MAX_PATH */ 63217044Snwhitehorn# endif /* !MAXPATHLEN */ 64217044Snwhitehorn#endif /* !PATH_MAX */ 65217044Snwhitehorn 66217044Snwhitehornsize_t path_name_max() 67217044Snwhitehorn{ 68217044Snwhitehorn return PATH_MAX; 69217044Snwhitehorn} 70217044Snwhitehorn 71217044Snwhitehorn#endif /* not _POSIX_VERSION */ 72217044Snwhitehorn