fpathconf.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* POSIX fpathconf (Sec. 5.7.1) Author: Andy Tanenbaum */
  2. #include <lib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #define fstat _fstat
  6. #include <sys/stat.h>
  7. #include <errno.h>
  8. #include <limits.h>
  9. PUBLIC long fpathconf(fd, name)
  10. int fd; /* file descriptor being interrogated */
  11. int name; /* property being inspected */
  12. {
  13. /* POSIX allows some of the values in <limits.h> to be increased at
  14. * run time. The pathconf and fpathconf functions allow these values
  15. * to be checked at run time. MINIX does not use this facility.
  16. * The run-time limits are those given in <limits.h>.
  17. */
  18. struct stat stbuf;
  19. switch(name) {
  20. case _PC_LINK_MAX:
  21. /* Fstat the file. If that fails, return -1. */
  22. if (fstat(fd, &stbuf) != 0) return(-1L);
  23. if (S_ISDIR(stbuf.st_mode))
  24. return(1L); /* no links to directories */
  25. else
  26. return( (long) LINK_MAX);
  27. case _PC_MAX_CANON:
  28. return( (long) MAX_CANON);
  29. case _PC_MAX_INPUT:
  30. return( (long) MAX_INPUT);
  31. case _PC_NAME_MAX:
  32. return( (long) NAME_MAX);
  33. case _PC_PATH_MAX:
  34. return( (long) PATH_MAX);
  35. case _PC_PIPE_BUF:
  36. return( (long) PIPE_BUF);
  37. case _PC_CHOWN_RESTRICTED:
  38. return( (long) 1); /* MINIX defines CHOWN_RESTRICTED */
  39. case _PC_NO_TRUNC: /* MINIX does not define NO_TRUNC */
  40. return( (long) 0);
  41. case _PC_VDISABLE: /* MINIX defines VDISABLE */
  42. return( (long) _POSIX_VDISABLE);
  43. default:
  44. errno = EINVAL;
  45. return(-1L);
  46. }
  47. }