OSDN Git Service

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