2.3.90-16
[glibc/history.git] / sysdeps / posix / fpathconf.c
blob605cd171d0238c1159bd522f7f705eeb1ac9c121
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.
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <stddef.h>
22 #include <unistd.h>
23 #include <limits.h>
24 #include <sys/stat.h>
25 #include <sys/statfs.h>
26 #include <sys/statvfs.h>
29 /* Get file-specific information about descriptor FD. */
30 long int
31 __fpathconf (fd, name)
32 int fd;
33 int name;
35 if (fd < 0)
37 __set_errno (EBADF);
38 return -1;
41 switch (name)
43 default:
44 __set_errno (EINVAL);
45 return -1;
47 case _PC_LINK_MAX:
48 #ifdef LINK_MAX
49 return LINK_MAX;
50 #else
51 return -1;
52 #endif
54 case _PC_MAX_CANON:
55 #ifdef MAX_CANON
56 return MAX_CANON;
57 #else
58 return -1;
59 #endif
61 case _PC_MAX_INPUT:
62 #ifdef MAX_INPUT
63 return MAX_INPUT;
64 #else
65 return -1;
66 #endif
68 case _PC_NAME_MAX:
69 #ifdef NAME_MAX
71 struct statfs buf;
72 int save_errno = errno;
74 if (__fstatfs (fd, &buf) < 0)
76 if (errno == ENOSYS)
78 __set_errno (save_errno);
79 return NAME_MAX;
81 else if (errno == ENODEV)
82 __set_errno (EINVAL);
84 return -1;
86 else
88 #ifdef _STATFS_F_NAMELEN
89 return buf.f_namelen;
90 #else
91 # ifdef _STATFS_F_NAME_MAX
92 return buf.f_name_max;
93 # else
94 return NAME_MAX;
95 # endif
96 #endif
99 #else
100 return -1;
101 #endif
103 case _PC_PATH_MAX:
104 #ifdef PATH_MAX
105 return PATH_MAX;
106 #else
107 return -1;
108 #endif
110 case _PC_PIPE_BUF:
111 #ifdef PIPE_BUF
112 return PIPE_BUF;
113 #else
114 return -1;
115 #endif
117 case _PC_CHOWN_RESTRICTED:
118 #ifdef _POSIX_CHOWN_RESTRICTED
119 return _POSIX_CHOWN_RESTRICTED;
120 #else
121 return -1;
122 #endif
124 case _PC_NO_TRUNC:
125 #ifdef _POSIX_NO_TRUNC
126 return _POSIX_NO_TRUNC;
127 #else
128 return -1;
129 #endif
131 case _PC_VDISABLE:
132 #ifdef _POSIX_VDISABLE
133 return _POSIX_VDISABLE;
134 #else
135 return -1;
136 #endif
138 case _PC_SYNC_IO:
139 #ifdef _POSIX_SYNC_IO
140 return _POSIX_SYNC_IO;
141 #else
142 return -1;
143 #endif
145 case _PC_ASYNC_IO:
146 #ifdef _POSIX_ASYNC_IO
148 /* AIO is only allowed on regular files and block devices. */
149 struct stat64 st;
151 if (__fxstat64 (_STAT_VER, fd, &st) < 0
152 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
153 return -1;
154 else
155 return 1;
157 #else
158 return -1;
159 #endif
161 case _PC_PRIO_IO:
162 #ifdef _POSIX_PRIO_IO
163 return _POSIX_PRIO_IO;
164 #else
165 return -1;
166 #endif
168 case _PC_SOCK_MAXBUF:
169 #ifdef SOCK_MAXBUF
170 return SOCK_MAXBUF;
171 #else
172 return -1;
173 #endif
175 case _PC_FILESIZEBITS:
176 #ifdef FILESIZEBITS
177 return FILESIZEBITS;
178 #else
179 /* We let platforms with larger file sizes overwrite this value. */
180 return 32;
181 #endif
183 case _PC_REC_INCR_XFER_SIZE:
184 /* XXX It is not entirely clear what the limit is supposed to do.
185 What is incremented? */
186 return -1;
188 case _PC_REC_MAX_XFER_SIZE:
189 /* XXX It is not entirely clear what the limit is supposed to do.
190 In general there is no top limit of the number of bytes which
191 case be transported at once. */
192 return -1;
194 case _PC_REC_MIN_XFER_SIZE:
196 /* XXX It is not entirely clear what the limit is supposed to do.
197 I assume this is the block size of the filesystem. */
198 struct statvfs64 sv;
200 if (__fstatvfs64 (fd, &sv) < 0)
201 return -1;
202 return sv.f_bsize;
205 case _PC_REC_XFER_ALIGN:
207 /* XXX It is not entirely clear what the limit is supposed to do.
208 I assume that the number should reflect the minimal block
209 alignment. */
210 struct statvfs64 sv;
212 if (__fstatvfs64 (fd, &sv) < 0)
213 return -1;
214 return sv.f_frsize;
217 case _PC_ALLOC_SIZE_MIN:
219 /* XXX It is not entirely clear what the limit is supposed to do.
220 I assume that the number should reflect the minimal block
221 alignment. */
222 struct statvfs64 sv;
224 if (__fstatvfs64 (fd, &sv) < 0)
225 return -1;
226 return sv.f_frsize;
229 case _PC_SYMLINK_MAX:
230 /* In general there are no limits. If a system has one it should
231 overwrite this case. */
232 return -1;
234 case _PC_2_SYMLINKS:
235 /* Unix systems generally have symlinks. */
236 return 1;
240 #undef __fpathconf
241 weak_alias (__fpathconf, fpathconf)