Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / posix / fpathconf.c
blob7b072fa3ca155929e064adab84be5cbfc5167a7b
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, see
17 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <stddef.h>
21 #include <unistd.h>
22 #include <limits.h>
23 #include <sys/stat.h>
24 #include <sys/statfs.h>
25 #include <sys/statvfs.h>
28 /* Get file-specific information about descriptor FD. */
29 long int
30 __fpathconf (fd, name)
31 int fd;
32 int name;
34 if (fd < 0)
36 __set_errno (EBADF);
37 return -1;
40 switch (name)
42 default:
43 __set_errno (EINVAL);
44 return -1;
46 case _PC_LINK_MAX:
47 #ifdef LINK_MAX
48 return LINK_MAX;
49 #else
50 return -1;
51 #endif
53 case _PC_MAX_CANON:
54 #ifdef MAX_CANON
55 return MAX_CANON;
56 #else
57 return -1;
58 #endif
60 case _PC_MAX_INPUT:
61 #ifdef MAX_INPUT
62 return MAX_INPUT;
63 #else
64 return -1;
65 #endif
67 case _PC_NAME_MAX:
68 #ifdef NAME_MAX
70 struct statfs buf;
71 int save_errno = errno;
73 if (__fstatfs (fd, &buf) < 0)
75 if (errno == ENOSYS)
77 __set_errno (save_errno);
78 return NAME_MAX;
80 else if (errno == ENODEV)
81 __set_errno (EINVAL);
83 return -1;
85 else
87 #ifdef _STATFS_F_NAMELEN
88 return buf.f_namelen;
89 #else
90 # ifdef _STATFS_F_NAME_MAX
91 return buf.f_name_max;
92 # else
93 return NAME_MAX;
94 # endif
95 #endif
98 #else
99 return -1;
100 #endif
102 case _PC_PATH_MAX:
103 #ifdef PATH_MAX
104 return PATH_MAX;
105 #else
106 return -1;
107 #endif
109 case _PC_PIPE_BUF:
110 #ifdef PIPE_BUF
111 return PIPE_BUF;
112 #else
113 return -1;
114 #endif
116 case _PC_CHOWN_RESTRICTED:
117 #ifdef _POSIX_CHOWN_RESTRICTED
118 return _POSIX_CHOWN_RESTRICTED;
119 #else
120 return -1;
121 #endif
123 case _PC_NO_TRUNC:
124 #ifdef _POSIX_NO_TRUNC
125 return _POSIX_NO_TRUNC;
126 #else
127 return -1;
128 #endif
130 case _PC_VDISABLE:
131 #ifdef _POSIX_VDISABLE
132 return _POSIX_VDISABLE;
133 #else
134 return -1;
135 #endif
137 case _PC_SYNC_IO:
138 #ifdef _POSIX_SYNC_IO
139 return _POSIX_SYNC_IO;
140 #else
141 return -1;
142 #endif
144 case _PC_ASYNC_IO:
145 #ifdef _POSIX_ASYNC_IO
147 /* AIO is only allowed on regular files and block devices. */
148 struct stat64 st;
150 if (__fxstat64 (_STAT_VER, fd, &st) < 0
151 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
152 return -1;
153 else
154 return 1;
156 #else
157 return -1;
158 #endif
160 case _PC_PRIO_IO:
161 #ifdef _POSIX_PRIO_IO
162 return _POSIX_PRIO_IO;
163 #else
164 return -1;
165 #endif
167 case _PC_SOCK_MAXBUF:
168 #ifdef SOCK_MAXBUF
169 return SOCK_MAXBUF;
170 #else
171 return -1;
172 #endif
174 case _PC_FILESIZEBITS:
175 #ifdef FILESIZEBITS
176 return FILESIZEBITS;
177 #else
178 /* We let platforms with larger file sizes overwrite this value. */
179 return 32;
180 #endif
182 case _PC_REC_INCR_XFER_SIZE:
183 /* XXX It is not entirely clear what the limit is supposed to do.
184 What is incremented? */
185 return -1;
187 case _PC_REC_MAX_XFER_SIZE:
188 /* XXX It is not entirely clear what the limit is supposed to do.
189 In general there is no top limit of the number of bytes which
190 case be transported at once. */
191 return -1;
193 case _PC_REC_MIN_XFER_SIZE:
195 /* XXX It is not entirely clear what the limit is supposed to do.
196 I assume this is the block size of the filesystem. */
197 struct statvfs64 sv;
199 if (__fstatvfs64 (fd, &sv) < 0)
200 return -1;
201 return sv.f_bsize;
204 case _PC_REC_XFER_ALIGN:
206 /* XXX It is not entirely clear what the limit is supposed to do.
207 I assume that the number should reflect the minimal block
208 alignment. */
209 struct statvfs64 sv;
211 if (__fstatvfs64 (fd, &sv) < 0)
212 return -1;
213 return sv.f_frsize;
216 case _PC_ALLOC_SIZE_MIN:
218 /* XXX It is not entirely clear what the limit is supposed to do.
219 I assume that the number should reflect the minimal block
220 alignment. */
221 struct statvfs64 sv;
223 if (__fstatvfs64 (fd, &sv) < 0)
224 return -1;
225 return sv.f_frsize;
228 case _PC_SYMLINK_MAX:
229 /* In general there are no limits. If a system has one it should
230 overwrite this case. */
231 return -1;
233 case _PC_2_SYMLINKS:
234 /* Unix systems generally have symlinks. */
235 return 1;
239 #undef __fpathconf
240 weak_alias (__fpathconf, fpathconf)