]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/posix/fpathconf.c
Update.
[thirdparty/glibc.git] / sysdeps / posix / fpathconf.c
1 /* Copyright (C) 1991,1995,1996,1998,2000,2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
18
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>
26
27
28 /* Get file-specific information about descriptor FD. */
29 long int
30 __fpathconf (fd, name)
31 int fd;
32 int name;
33 {
34 if (fd < 0)
35 {
36 __set_errno (EBADF);
37 return -1;
38 }
39
40 switch (name)
41 {
42 default:
43 __set_errno (EINVAL);
44 return -1;
45
46 case _PC_LINK_MAX:
47 #ifdef LINK_MAX
48 return LINK_MAX;
49 #else
50 return -1;
51 #endif
52
53 case _PC_MAX_CANON:
54 #ifdef MAX_CANON
55 return MAX_CANON;
56 #else
57 return -1;
58 #endif
59
60 case _PC_MAX_INPUT:
61 #ifdef MAX_INPUT
62 return MAX_INPUT;
63 #else
64 return -1;
65 #endif
66
67 case _PC_NAME_MAX:
68 #ifdef NAME_MAX
69 {
70 struct statfs buf;
71 int save_errno = errno;
72
73 if (__fstatfs (fd, &buf) < 0)
74 {
75 if (errno == ENOSYS)
76 {
77 __set_errno (save_errno);
78 return NAME_MAX;
79 }
80 else if (errno == ENODEV)
81 __set_errno (EINVAL);
82
83 return -1;
84 }
85 else
86 {
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
96 }
97 }
98 #else
99 return -1;
100 #endif
101
102 case _PC_PATH_MAX:
103 #ifdef PATH_MAX
104 return PATH_MAX;
105 #else
106 return -1;
107 #endif
108
109 case _PC_PIPE_BUF:
110 #ifdef PIPE_BUF
111 return PIPE_BUF;
112 #else
113 return -1;
114 #endif
115
116 case _PC_CHOWN_RESTRICTED:
117 #ifdef _POSIX_CHOWN_RESTRICTED
118 return _POSIX_CHOWN_RESTRICTED;
119 #else
120 return -1;
121 #endif
122
123 case _PC_NO_TRUNC:
124 #ifdef _POSIX_NO_TRUNC
125 return _POSIX_NO_TRUNC;
126 #else
127 return -1;
128 #endif
129
130 case _PC_VDISABLE:
131 #ifdef _POSIX_VDISABLE
132 return _POSIX_VDISABLE;
133 #else
134 return -1;
135 #endif
136
137 case _PC_SYNC_IO:
138 #ifdef _POSIX_SYNC_IO
139 return _POSIX_SYNC_IO;
140 #else
141 return -1;
142 #endif
143
144 case _PC_ASYNC_IO:
145 #ifdef _POSIX_ASYNC_IO
146 {
147 /* AIO is only allowed on regular files and block devices. */
148 struct stat64 st;
149
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;
155 }
156 #else
157 return -1;
158 #endif
159
160 case _PC_PRIO_IO:
161 #ifdef _POSIX_PRIO_IO
162 return _POSIX_PRIO_IO;
163 #else
164 return -1;
165 #endif
166
167 case _PC_SOCK_MAXBUF:
168 #ifdef SOCK_MAXBUF
169 return SOCK_MAXBUF;
170 #else
171 return -1;
172 #endif
173
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
181
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;
186
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;
192
193 case _PC_REC_MIN_XFER_SIZE:
194 {
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;
198
199 if (__fstatvfs64 (fd, &sv) < 0)
200 return -1;
201 return sv.f_bsize;
202 }
203
204 case _PC_REC_XFER_ALIGN:
205 {
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;
210
211 if (__fstatvfs64 (fd, &sv) < 0)
212 return -1;
213 return sv.f_frsize;
214 }
215
216 case _PC_ALLOC_SIZE_MIN:
217 {
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;
222
223 if (__fstatvfs64 (fd, &sv) < 0)
224 return -1;
225 return sv.f_frsize;
226 }
227
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;
232 }
233 }
234
235 #undef __fpathconf
236 weak_alias (__fpathconf, fpathconf)