malloc: add glibc compat symbols
[uclibc-ng.git] / libc / unistd / fpathconf.c
blob556343be2aefa4f37be9dee364b7b47295e15987
1 /* fpathconf -- adjusted for busybox
2 Copyright (C) 1991,95,96,98,99,2000,2001 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <unistd.h>
21 #include <limits.h>
22 #include <stddef.h>
23 #include <fcntl.h>
24 #include <sys/stat.h>
25 #include <sys/statfs.h>
28 #ifndef __USE_FILE_OFFSET64
29 extern int fstatfs (int __fildes, struct statfs *__buf)
30 __THROW __nonnull ((2));
31 #else
32 # ifdef __REDIRECT_NTH
33 extern int __REDIRECT_NTH (fstatfs, (int __fildes, struct statfs *__buf),
34 fstatfs64) __nonnull ((2));
35 # else
36 # define fstatfs fstatfs64
37 # endif
38 #endif
40 extern __typeof(fstatfs) __libc_fstatfs;
42 /* The Linux kernel headers mention this as a kind of generic value. */
43 #define LINUX_LINK_MAX 127
46 /* Get file-specific information about descriptor FD. */
47 long int fpathconf(int fd, int name)
49 if (fd < 0)
51 __set_errno (EBADF);
52 return -1;
55 if (name == _PC_LINK_MAX)
57 /* Cut some corners */
58 #if 0
59 struct statfs fsbuf;
61 /* Determine the filesystem type. */
62 if (__libc_fstatfs (fd, &fsbuf) < 0)
64 if (errno == ENOSYS)
65 /* not possible, return the default value. */
66 return LINUX_LINK_MAX;
68 /* Some error occured. */
69 return -1;
72 switch (fsbuf.f_type)
74 case EXT2_SUPER_MAGIC:
75 return EXT2_LINK_MAX;
77 case MINIX_SUPER_MAGIC:
78 case MINIX_SUPER_MAGIC2:
79 return MINIX_LINK_MAX;
81 case MINIX2_SUPER_MAGIC:
82 case MINIX2_SUPER_MAGIC2:
83 return MINIX2_LINK_MAX;
85 case XENIX_SUPER_MAGIC:
86 return XENIX_LINK_MAX;
88 case SYSV4_SUPER_MAGIC:
89 case SYSV2_SUPER_MAGIC:
90 return SYSV_LINK_MAX;
92 case COH_SUPER_MAGIC:
93 return COH_LINK_MAX;
95 case UFS_MAGIC:
96 case UFS_CIGAM:
97 return UFS_LINK_MAX;
99 case REISERFS_SUPER_MAGIC:
100 return REISERFS_LINK_MAX;
102 default:
103 return LINUX_LINK_MAX;
105 #else
106 return LINUX_LINK_MAX;
107 #endif
110 switch (name)
112 default:
113 __set_errno (EINVAL);
114 return -1;
116 case _PC_MAX_CANON:
117 #ifdef MAX_CANON
118 return MAX_CANON;
119 #else
120 return -1;
121 #endif
123 case _PC_MAX_INPUT:
124 #ifdef MAX_INPUT
125 return MAX_INPUT;
126 #else
127 return -1;
128 #endif
130 case _PC_NAME_MAX:
131 #ifdef NAME_MAX
133 struct statfs buf;
134 int save_errno = errno;
136 if (__libc_fstatfs (fd, &buf) < 0)
138 if (errno == ENOSYS)
140 errno = save_errno;
141 return NAME_MAX;
143 return -1;
145 else
147 #ifdef _STATFS_F_NAMELEN
148 return buf.f_namelen;
149 #else
150 # ifdef _STATFS_F_NAME_MAX
151 return buf.f_name_max;
152 # else
153 return NAME_MAX;
154 # endif
155 #endif
158 #else
159 return -1;
160 #endif
162 case _PC_PATH_MAX:
163 #ifdef PATH_MAX
164 return PATH_MAX;
165 #else
166 return -1;
167 #endif
169 case _PC_PIPE_BUF:
170 #ifdef PIPE_BUF
171 return PIPE_BUF;
172 #else
173 return -1;
174 #endif
176 case _PC_CHOWN_RESTRICTED:
177 #ifdef _POSIX_CHOWN_RESTRICTED
178 return _POSIX_CHOWN_RESTRICTED;
179 #else
180 return -1;
181 #endif
183 case _PC_NO_TRUNC:
184 #ifdef _POSIX_NO_TRUNC
185 return _POSIX_NO_TRUNC;
186 #else
187 return -1;
188 #endif
190 case _PC_VDISABLE:
191 #ifdef _POSIX_VDISABLE
192 return _POSIX_VDISABLE;
193 #else
194 return -1;
195 #endif
197 case _PC_SYNC_IO:
198 #ifdef _POSIX_SYNC_IO
199 return _POSIX_SYNC_IO;
200 #else
201 return -1;
202 #endif
204 case _PC_ASYNC_IO:
205 #if defined _POSIX_ASYNC_IO
207 /* AIO is only allowed on regular files and block devices. */
208 struct stat st;
210 if (fstat (fd, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
211 return -1;
212 else
213 return 1;
215 #else
216 return -1;
217 #endif
219 case _PC_PRIO_IO:
220 #ifdef _POSIX_PRIO_IO
221 return _POSIX_PRIO_IO;
222 #else
223 return -1;
224 #endif
226 case _PC_SOCK_MAXBUF:
227 #ifdef SOCK_MAXBUF
228 return SOCK_MAXBUF;
229 #else
230 return -1;
231 #endif
233 case _PC_FILESIZEBITS:
234 #ifdef FILESIZEBITS
235 return FILESIZEBITS;
236 #else
237 /* We let platforms with larger file sizes overwrite this value. */
238 return 32;
239 #endif
241 /* Be lazy -- skip these */
242 case _PC_REC_INCR_XFER_SIZE:
243 case _PC_REC_MAX_XFER_SIZE:
244 case _PC_REC_MIN_XFER_SIZE:
245 case _PC_REC_XFER_ALIGN:
246 case _PC_ALLOC_SIZE_MIN:
247 case _PC_SYMLINK_MAX:
248 return -1;