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

https://bitbucket.org/freebsd/freebsd-head/ · C++ · 65 lines · 34 code · 11 blank · 20 comment · 0 complexity · d089c78ec3db5a560b87ba91cf056c79 MD5 · raw file

  1. // -*- C++ -*-
  2. /* Copyright (C) 1992, 2001, 2003, 2005 Free Software Foundation, Inc.
  3. Written by James Clark (jjc@jclark.com)
  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. /* file_name_max(dir) does the same as pathconf(dir, _PC_NAME_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 file_name_max(const char *fname)
  24. {
  25. return pathconf(fname, _PC_NAME_MAX);
  26. }
  27. #else /* not _POSIX_VERSION */
  28. #ifdef HAVE_DIRENT_H
  29. #include <dirent.h>
  30. #else /* not HAVE_DIRENT_H */
  31. #ifdef HAVE_SYS_DIR_H
  32. #include <sys/dir.h>
  33. #endif /* HAVE_SYS_DIR_H */
  34. #endif /* not HAVE_DIRENT_H */
  35. #ifndef NAME_MAX
  36. #ifdef MAXNAMLEN
  37. #define NAME_MAX MAXNAMLEN
  38. #else /* !MAXNAMLEN */
  39. #ifdef MAXNAMELEN
  40. #define NAME_MAX MAXNAMELEN
  41. #else /* !MAXNAMELEN */
  42. #define NAME_MAX 14
  43. #endif /* !MAXNAMELEN */
  44. #endif /* !MAXNAMLEN */
  45. #endif /* !NAME_MAX */
  46. size_t file_name_max(const char *)
  47. {
  48. return NAME_MAX;
  49. }
  50. #endif /* not _POSIX_VERSION */