pathconf.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. extern __typeof(statfs) __libc_statfs;
  28. libc_hidden_proto(__libc_statfs)
  29. libc_hidden_proto(stat)
  30. /* The Linux kernel headers mention this as a kind of generic value. */
  31. #ifndef LINK_MAX
  32. # define LINK_MAX 127
  33. #endif
  34. /* Get file-specific information about PATH. */
  35. long int
  36. pathconf (const char *path, int name)
  37. {
  38. if (path[0] == '\0')
  39. {
  40. __set_errno (ENOENT);
  41. return -1;
  42. }
  43. switch (name)
  44. {
  45. default:
  46. __set_errno (EINVAL);
  47. return -1;
  48. case _PC_LINK_MAX:
  49. #ifdef LINK_MAX
  50. return LINK_MAX;
  51. #else
  52. return -1;
  53. #endif
  54. case _PC_MAX_CANON:
  55. #ifdef MAX_CANON
  56. return MAX_CANON;
  57. #else
  58. return -1;
  59. #endif
  60. case _PC_MAX_INPUT:
  61. #ifdef MAX_INPUT
  62. return MAX_INPUT;
  63. #else
  64. return -1;
  65. #endif
  66. case _PC_NAME_MAX:
  67. #ifdef NAME_MAX
  68. {
  69. struct statfs buf;
  70. int save_errno = errno;
  71. if (__libc_statfs (path, &buf) < 0)
  72. {
  73. if (errno == ENOSYS)
  74. {
  75. errno = save_errno;
  76. return NAME_MAX;
  77. }
  78. return -1;
  79. }
  80. else
  81. {
  82. #ifdef _STATFS_F_NAMELEN
  83. return buf.f_namelen;
  84. #else
  85. # ifdef _STATFS_F_NAME_MAX
  86. return buf.f_name_max;
  87. # else
  88. return NAME_MAX;
  89. # endif
  90. #endif
  91. }
  92. }
  93. #else
  94. return -1;
  95. #endif
  96. case _PC_PATH_MAX:
  97. #ifdef PATH_MAX
  98. return PATH_MAX;
  99. #else
  100. return -1;
  101. #endif
  102. case _PC_PIPE_BUF:
  103. #ifdef PIPE_BUF
  104. return PIPE_BUF;
  105. #else
  106. return -1;
  107. #endif
  108. case _PC_CHOWN_RESTRICTED:
  109. #ifdef _POSIX_CHOWN_RESTRICTED
  110. return _POSIX_CHOWN_RESTRICTED;
  111. #else
  112. return -1;
  113. #endif
  114. case _PC_NO_TRUNC:
  115. #ifdef _POSIX_NO_TRUNC
  116. return _POSIX_NO_TRUNC;
  117. #else
  118. return -1;
  119. #endif
  120. case _PC_VDISABLE:
  121. #ifdef _POSIX_VDISABLE
  122. return _POSIX_VDISABLE;
  123. #else
  124. return -1;
  125. #endif
  126. case _PC_SYNC_IO:
  127. #ifdef _POSIX_SYNC_IO
  128. return _POSIX_SYNC_IO;
  129. #else
  130. return -1;
  131. #endif
  132. case _PC_ASYNC_IO:
  133. #if defined _POSIX_ASYNC_IO && defined __UCLIBC_HAS_LFS__
  134. {
  135. /* AIO is only allowed on regular files and block devices. */
  136. struct stat st;
  137. if (stat (path, &st) < 0
  138. || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
  139. return -1;
  140. else
  141. return 1;
  142. }
  143. #else
  144. return -1;
  145. #endif
  146. case _PC_PRIO_IO:
  147. #ifdef _POSIX_PRIO_IO
  148. return _POSIX_PRIO_IO;
  149. #else
  150. return -1;
  151. #endif
  152. case _PC_SOCK_MAXBUF:
  153. #ifdef SOCK_MAXBUF
  154. return SOCK_MAXBUF;
  155. #else
  156. return -1;
  157. #endif
  158. case _PC_FILESIZEBITS:
  159. #ifdef FILESIZEBITS
  160. return FILESIZEBITS;
  161. #else
  162. /* We let platforms with larger file sizes overwrite this value. */
  163. return 32;
  164. #endif
  165. /* Be lazy -- skip these */
  166. case _PC_REC_INCR_XFER_SIZE:
  167. case _PC_REC_MAX_XFER_SIZE:
  168. case _PC_REC_MIN_XFER_SIZE:
  169. case _PC_REC_XFER_ALIGN:
  170. case _PC_ALLOC_SIZE_MIN:
  171. case _PC_SYMLINK_MAX:
  172. return -1;
  173. }
  174. }