Update.
[glibc.git] / sysdeps / posix / fpathconf.c
blob93f0b995900043f094f46c656de5193ce9dcc034
1 /* Copyright (C) 1991,1995,1996,1998,2000,2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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. */
19 #include <errno.h>
20 #include <stddef.h>
21 #include <unistd.h>
22 #include <limits.h>
23 #include <sys/statfs.h>
24 #include <sys/statvfs.h>
27 /* Get file-specific information about descriptor FD. */
28 long int
29 __fpathconf (fd, name)
30 int fd;
31 int name;
33 if (fd < 0)
35 __set_errno (EBADF);
36 return -1;
39 switch (name)
41 default:
42 __set_errno (EINVAL);
43 return -1;
45 case _PC_LINK_MAX:
46 #ifdef LINK_MAX
47 return LINK_MAX;
48 #else
49 return -1;
50 #endif
52 case _PC_MAX_CANON:
53 #ifdef MAX_CANON
54 return MAX_CANON;
55 #else
56 return -1;
57 #endif
59 case _PC_MAX_INPUT:
60 #ifdef MAX_INPUT
61 return MAX_INPUT;
62 #else
63 return -1;
64 #endif
66 case _PC_NAME_MAX:
67 #ifdef NAME_MAX
69 struct statfs buf;
70 int save_errno = errno;
72 if (__fstatfs (fd, &buf) < 0)
74 if (errno == ENOSYS)
76 __set_errno (save_errno);
77 return NAME_MAX;
79 else if (errno == ENODEV)
80 __set_errno (EINVAL);
82 return -1;
84 else
86 #ifdef _STATFS_F_NAMELEN
87 return buf.f_namelen;
88 #else
89 # ifdef _STATFS_F_NAME_MAX
90 return buf.f_name_max;
91 # else
92 return NAME_MAX;
93 # endif
94 #endif
97 #else
98 return -1;
99 #endif
101 case _PC_PATH_MAX:
102 #ifdef PATH_MAX
103 return PATH_MAX;
104 #else
105 return -1;
106 #endif
108 case _PC_PIPE_BUF:
109 #ifdef PIPE_BUF
110 return PIPE_BUF;
111 #else
112 return -1;
113 #endif
115 case _PC_CHOWN_RESTRICTED:
116 #ifdef _POSIX_CHOWN_RESTRICTED
117 return _POSIX_CHOWN_RESTRICTED;
118 #else
119 return -1;
120 #endif
122 case _PC_NO_TRUNC:
123 #ifdef _POSIX_NO_TRUNC
124 return _POSIX_NO_TRUNC;
125 #else
126 return -1;
127 #endif
129 case _PC_VDISABLE:
130 #ifdef _POSIX_VDISABLE
131 return _POSIX_VDISABLE;
132 #else
133 return -1;
134 #endif
136 case _PC_SYNC_IO:
137 #ifdef _POSIX_SYNC_IO
138 return _POSIX_SYNC_IO;
139 #else
140 return -1;
141 #endif
143 case _PC_ASYNC_IO:
144 #ifdef _POSIX_ASYNC_IO
145 return _POSIX_ASYNC_IO;
146 #else
147 return -1;
148 #endif
150 case _PC_PRIO_IO:
151 #ifdef _POSIX_PRIO_IO
152 return _POSIX_PRIO_IO;
153 #else
154 return -1;
155 #endif
157 case _PC_SOCK_MAXBUF:
158 #ifdef SOCK_MAXBUF
159 return SOCK_MAXBUF;
160 #else
161 return -1;
162 #endif
164 case _PC_FILESIZEBITS:
165 #ifdef FILESIZEBITS
166 return FILESIZEBITS;
167 #else
168 /* We let platforms with larger file sizes overwrite this value. */
169 return 32;
170 #endif
172 case _PC_REC_INCR_XFER_SIZE:
173 /* XXX It is not entirely clear what the limit is supposed to do.
174 What is incremented? */
175 return -1;
177 case _PC_REC_MAX_XFER_SIZE:
178 /* XXX It is not entirely clear what the limit is supposed to do.
179 In general there is no top limit of the number of bytes which
180 case be transported at once. */
181 return -1;
183 case _PC_REC_MIN_XFER_SIZE:
185 /* XXX It is not entirely clear what the limit is supposed to do.
186 I assume this is the block size of the filesystem. */
187 struct statvfs64 sv;
189 if (__fstatvfs64 (fd, &sv) < 0)
190 return -1;
191 return sv.f_bsize;
194 case _PC_REC_XFER_ALIGN:
196 /* XXX It is not entirely clear what the limit is supposed to do.
197 I assume that the number should reflect the minimal block
198 alignment. */
199 struct statvfs64 sv;
201 if (__fstatvfs64 (fd, &sv) < 0)
202 return -1;
203 return sv.f_frsize;
208 #undef __fpathconf
209 weak_alias (__fpathconf, fpathconf)