Update.
[glibc.git] / sysdeps / posix / pathconf.c
blob4ce5c0d1d7d1afade8133c70c56b1f7143bbf18b
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 <fcntl.h>
24 #include <sys/statfs.h>
25 #include <sys/statvfs.h>
28 /* Get file-specific information about PATH. */
29 long int
30 __pathconf (const char *path, int name)
32 if (path[0] == '\0')
34 __set_errno (ENOENT);
35 return -1;
38 switch (name)
40 default:
41 __set_errno (EINVAL);
42 return -1;
44 case _PC_LINK_MAX:
45 #ifdef LINK_MAX
46 return LINK_MAX;
47 #else
48 return -1;
49 #endif
51 case _PC_MAX_CANON:
52 #ifdef MAX_CANON
53 return MAX_CANON;
54 #else
55 return -1;
56 #endif
58 case _PC_MAX_INPUT:
59 #ifdef MAX_INPUT
60 return MAX_INPUT;
61 #else
62 return -1;
63 #endif
65 case _PC_NAME_MAX:
66 #ifdef NAME_MAX
68 struct statfs buf;
69 int save_errno = errno;
71 if (__statfs (path, &buf) < 0)
73 if (errno == ENOSYS)
75 errno = save_errno;
76 return NAME_MAX;
78 return -1;
80 else
82 #ifdef _STATFS_F_NAMELEN
83 return buf.f_namelen;
84 #else
85 # ifdef _STATFS_F_NAME_MAX
86 return buf.f_name_max;
87 # else
88 return NAME_MAX;
89 # endif
90 #endif
93 #else
94 return -1;
95 #endif
97 case _PC_PATH_MAX:
98 #ifdef PATH_MAX
99 return PATH_MAX;
100 #else
101 return -1;
102 #endif
104 case _PC_PIPE_BUF:
105 #ifdef PIPE_BUF
106 return PIPE_BUF;
107 #else
108 return -1;
109 #endif
111 case _PC_CHOWN_RESTRICTED:
112 #ifdef _POSIX_CHOWN_RESTRICTED
113 return _POSIX_CHOWN_RESTRICTED;
114 #else
115 return -1;
116 #endif
118 case _PC_NO_TRUNC:
119 #ifdef _POSIX_NO_TRUNC
120 return _POSIX_NO_TRUNC;
121 #else
122 return -1;
123 #endif
125 case _PC_VDISABLE:
126 #ifdef _POSIX_VDISABLE
127 return _POSIX_VDISABLE;
128 #else
129 return -1;
130 #endif
132 case _PC_SYNC_IO:
133 #ifdef _POSIX_SYNC_IO
134 return _POSIX_SYNC_IO;
135 #else
136 return -1;
137 #endif
139 case _PC_ASYNC_IO:
140 #ifdef _POSIX_ASYNC_IO
141 return _POSIX_ASYNC_IO;
142 #else
143 return -1;
144 #endif
146 case _PC_PRIO_IO:
147 #ifdef _POSIX_PRIO_IO
148 return _POSIX_PRIO_IO;
149 #else
150 return -1;
151 #endif
153 case _PC_SOCK_MAXBUF:
154 #ifdef SOCK_MAXBUF
155 return SOCK_MAXBUF;
156 #else
157 return -1;
158 #endif
160 case _PC_FILESIZEBITS:
161 #ifdef FILESIZEBITS
162 return FILESIZEBITS;
163 #else
164 /* We let platforms with larger file sizes overwrite this value. */
165 return 32;
166 #endif
168 case _PC_REC_INCR_XFER_SIZE:
169 /* XXX It is not entirely clear what the limit is supposed to do.
170 What is incremented? */
171 return -1;
173 case _PC_REC_MAX_XFER_SIZE:
174 /* XXX It is not entirely clear what the limit is supposed to do.
175 In general there is no top limit of the number of bytes which
176 case be transported at once. */
177 return -1;
179 case _PC_REC_MIN_XFER_SIZE:
181 /* XXX It is not entirely clear what the limit is supposed to do.
182 I assume this is the block size of the filesystem. */
183 struct statvfs64 sv;
185 if (__statvfs64 (path, &sv) < 0)
186 return -1;
187 return sv.f_bsize;
190 case _PC_REC_XFER_ALIGN:
192 /* XXX It is not entirely clear what the limit is supposed to do.
193 I assume that the number should reflect the minimal block
194 alignment. */
195 struct statvfs64 sv;
197 if (__statvfs64 (path, &sv) < 0)
198 return -1;
199 return sv.f_frsize;
202 case _PC_ALLOC_SIZE_MIN:
204 /* XXX It is not entirely clear what the limit is supposed to do.
205 I assume that the number should reflect the minimal block
206 alignment. */
207 struct statvfs64 sv;
209 if (__statvfs64 (path, &sv) < 0)
210 return -1;
211 return sv.f_frsize;
214 case _PC_SYMLINK_MAX:
215 /* In general there are no limits. If a system has one it should
216 overwrite this case. */
217 return -1;
221 #undef __pathconf
222 weak_alias (__pathconf, pathconf)