pathconf.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* Copyright (C) 1991,1995,1996,1998,2000,2001,2003
  2. Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. /* pathconf -- adjusted for busybox */
  17. /* It would be great it this could be implemented using fpathconf,
  18. * but that doesn't work out very well (think FIFOs and sockets) */
  19. #include <errno.h>
  20. #include <stddef.h>
  21. #include <unistd.h>
  22. #include <limits.h>
  23. #include <fcntl.h>
  24. #include <sys/stat.h>
  25. #include <sys/statfs.h>
  26. //#include <sys/statvfs.h>
  27. libc_hidden_proto(statfs)
  28. libc_hidden_proto(stat)
  29. /* Get file-specific information about PATH. */
  30. long int
  31. pathconf (const char *path, int name)
  32. {
  33. if (path[0] == '\0')
  34. {
  35. __set_errno (ENOENT);
  36. return -1;
  37. }
  38. switch (name)
  39. {
  40. default:
  41. __set_errno (EINVAL);
  42. return -1;
  43. case _PC_LINK_MAX:
  44. #ifdef LINK_MAX
  45. return LINK_MAX;
  46. #else
  47. return -1;
  48. #endif
  49. case _PC_MAX_CANON:
  50. #ifdef MAX_CANON
  51. return MAX_CANON;
  52. #else
  53. return -1;
  54. #endif
  55. case _PC_MAX_INPUT:
  56. #ifdef MAX_INPUT
  57. return MAX_INPUT;
  58. #else
  59. return -1;
  60. #endif
  61. case _PC_NAME_MAX:
  62. #ifdef NAME_MAX
  63. {
  64. struct statfs buf;
  65. int save_errno = errno;
  66. if (statfs (path, &buf) < 0)
  67. {
  68. if (errno == ENOSYS)
  69. {
  70. errno = save_errno;
  71. return NAME_MAX;
  72. }
  73. return -1;
  74. }
  75. else
  76. {
  77. #ifdef _STATFS_F_NAMELEN
  78. return buf.f_namelen;
  79. #else
  80. # ifdef _STATFS_F_NAME_MAX
  81. return buf.f_name_max;
  82. # else
  83. return NAME_MAX;
  84. # endif
  85. #endif
  86. }
  87. }
  88. #else
  89. return -1;
  90. #endif
  91. case _PC_PATH_MAX:
  92. #ifdef PATH_MAX
  93. return PATH_MAX;
  94. #else
  95. return -1;
  96. #endif
  97. case _PC_PIPE_BUF:
  98. #ifdef PIPE_BUF
  99. return PIPE_BUF;
  100. #else
  101. return -1;
  102. #endif
  103. case _PC_CHOWN_RESTRICTED:
  104. #ifdef _POSIX_CHOWN_RESTRICTED
  105. return _POSIX_CHOWN_RESTRICTED;
  106. #else
  107. return -1;
  108. #endif
  109. case _PC_NO_TRUNC:
  110. #ifdef _POSIX_NO_TRUNC
  111. return _POSIX_NO_TRUNC;
  112. #else
  113. return -1;
  114. #endif
  115. case _PC_VDISABLE:
  116. #ifdef _POSIX_VDISABLE
  117. return _POSIX_VDISABLE;
  118. #else
  119. return -1;
  120. #endif
  121. case _PC_SYNC_IO:
  122. #ifdef _POSIX_SYNC_IO
  123. return _POSIX_SYNC_IO;
  124. #else
  125. return -1;
  126. #endif
  127. case _PC_ASYNC_IO:
  128. #if defined _POSIX_ASYNC_IO && defined __UCLIBC_HAS_LFS__
  129. {
  130. /* AIO is only allowed on regular files and block devices. */
  131. struct stat st;
  132. if (stat (path, &st) < 0
  133. || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
  134. return -1;
  135. else
  136. return 1;
  137. }
  138. #else
  139. return -1;
  140. #endif
  141. case _PC_PRIO_IO:
  142. #ifdef _POSIX_PRIO_IO
  143. return _POSIX_PRIO_IO;
  144. #else
  145. return -1;
  146. #endif
  147. case _PC_SOCK_MAXBUF:
  148. #ifdef SOCK_MAXBUF
  149. return SOCK_MAXBUF;
  150. #else
  151. return -1;
  152. #endif
  153. case _PC_FILESIZEBITS:
  154. #ifdef FILESIZEBITS
  155. return FILESIZEBITS;
  156. #else
  157. /* We let platforms with larger file sizes overwrite this value. */
  158. return 32;
  159. #endif
  160. /* Be lazy -- skip these */
  161. case _PC_REC_INCR_XFER_SIZE:
  162. case _PC_REC_MAX_XFER_SIZE:
  163. case _PC_REC_MIN_XFER_SIZE:
  164. case _PC_REC_XFER_ALIGN:
  165. case _PC_ALLOC_SIZE_MIN:
  166. case _PC_SYMLINK_MAX:
  167. return -1;
  168. }
  169. }