/contrib/groff/src/libs/libgroff/maxpathname.cpp

https://bitbucket.org/freebsd/freebsd-head/ · C++ · 71 lines · 39 code · 12 blank · 20 comment · 3 complexity · eb83b28c923085f08a7e272d36130f01 MD5 · raw file

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