chunksize(x) => x->size
[glibc.git] / sysdeps / posix / pathconf.c
blob75c99ee5c04e74431e94eb8e059d296cdce19368
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 <fcntl.h>
25 #include <sys/stat.h>
26 #include <sys/statfs.h>
27 #include <sys/statvfs.h>
30 /* Get file-specific information about PATH. */
31 long int
32 __pathconf (const char *path, int name)
34 if (path[0] == '\0')
36 __set_errno (ENOENT);
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 (__statfs (path, &buf) < 0)
75 if (errno == ENOSYS)
77 errno = save_errno;
78 return NAME_MAX;
80 return -1;
82 else
84 #ifdef _STATFS_F_NAMELEN
85 return buf.f_namelen;
86 #else
87 # ifdef _STATFS_F_NAME_MAX
88 return buf.f_name_max;
89 # else
90 return NAME_MAX;
91 # endif
92 #endif
95 #else
96 return -1;
97 #endif
99 case _PC_PATH_MAX:
100 #ifdef PATH_MAX
101 return PATH_MAX;
102 #else
103 return -1;
104 #endif
106 case _PC_PIPE_BUF:
107 #ifdef PIPE_BUF
108 return PIPE_BUF;
109 #else
110 return -1;
111 #endif
113 case _PC_CHOWN_RESTRICTED:
114 #ifdef _POSIX_CHOWN_RESTRICTED
115 return _POSIX_CHOWN_RESTRICTED;
116 #else
117 return -1;
118 #endif
120 case _PC_NO_TRUNC:
121 #ifdef _POSIX_NO_TRUNC
122 return _POSIX_NO_TRUNC;
123 #else
124 return -1;
125 #endif
127 case _PC_VDISABLE:
128 #ifdef _POSIX_VDISABLE
129 return _POSIX_VDISABLE;
130 #else
131 return -1;
132 #endif
134 case _PC_SYNC_IO:
135 #ifdef _POSIX_SYNC_IO
136 return _POSIX_SYNC_IO;
137 #else
138 return -1;
139 #endif
141 case _PC_ASYNC_IO:
142 #ifdef _POSIX_ASYNC_IO
144 /* AIO is only allowed on regular files and block devices. */
145 struct stat64 st;
147 if (__xstat64 (_STAT_VER, path, &st) < 0
148 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
149 return -1;
150 else
151 return 1;
153 #else
154 return -1;
155 #endif
157 case _PC_PRIO_IO:
158 #ifdef _POSIX_PRIO_IO
159 return _POSIX_PRIO_IO;
160 #else
161 return -1;
162 #endif
164 case _PC_SOCK_MAXBUF:
165 #ifdef SOCK_MAXBUF
166 return SOCK_MAXBUF;
167 #else
168 return -1;
169 #endif
171 case _PC_FILESIZEBITS:
172 #ifdef FILESIZEBITS
173 return FILESIZEBITS;
174 #else
175 /* We let platforms with larger file sizes overwrite this value. */
176 return 32;
177 #endif
179 case _PC_REC_INCR_XFER_SIZE:
180 /* XXX It is not entirely clear what the limit is supposed to do.
181 What is incremented? */
182 return -1;
184 case _PC_REC_MAX_XFER_SIZE:
185 /* XXX It is not entirely clear what the limit is supposed to do.
186 In general there is no top limit of the number of bytes which
187 case be transported at once. */
188 return -1;
190 case _PC_REC_MIN_XFER_SIZE:
192 /* XXX It is not entirely clear what the limit is supposed to do.
193 I assume this is the block size of the filesystem. */
194 struct statvfs64 sv;
196 if (__statvfs64 (path, &sv) < 0)
197 return -1;
198 return sv.f_bsize;
201 case _PC_REC_XFER_ALIGN:
203 /* XXX It is not entirely clear what the limit is supposed to do.
204 I assume that the number should reflect the minimal block
205 alignment. */
206 struct statvfs64 sv;
208 if (__statvfs64 (path, &sv) < 0)
209 return -1;
210 return sv.f_frsize;
213 case _PC_ALLOC_SIZE_MIN:
215 /* XXX It is not entirely clear what the limit is supposed to do.
216 I assume that the number should reflect the minimal block
217 alignment. */
218 struct statvfs64 sv;
220 if (__statvfs64 (path, &sv) < 0)
221 return -1;
222 return sv.f_frsize;
225 case _PC_SYMLINK_MAX:
226 /* In general there are no limits. If a system has one it should
227 overwrite this case. */
228 return -1;
230 case _PC_2_SYMLINKS:
231 /* Unix systems generally have symlinks. */
232 return 1;
236 #undef __pathconf
237 weak_alias (__pathconf, pathconf)