Update copyright notices with scripts/update-copyrights.
[glibc.git] / sysdeps / posix / pathconf.c
blob2607d3ede895ff13e38fc68f3b7966909bf34a6e
1 /* Copyright (C) 1991-2013 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 Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <stddef.h>
20 #include <unistd.h>
21 #include <limits.h>
22 #include <fcntl.h>
23 #include <sys/stat.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
142 /* AIO is only allowed on regular files and block devices. */
143 struct stat64 st;
145 if (__xstat64 (_STAT_VER, path, &st) < 0
146 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
147 return -1;
148 else
149 return 1;
151 #else
152 return -1;
153 #endif
155 case _PC_PRIO_IO:
156 #ifdef _POSIX_PRIO_IO
157 return _POSIX_PRIO_IO;
158 #else
159 return -1;
160 #endif
162 case _PC_SOCK_MAXBUF:
163 #ifdef SOCK_MAXBUF
164 return SOCK_MAXBUF;
165 #else
166 return -1;
167 #endif
169 case _PC_FILESIZEBITS:
170 #ifdef FILESIZEBITS
171 return FILESIZEBITS;
172 #else
173 /* We let platforms with larger file sizes overwrite this value. */
174 return 32;
175 #endif
177 case _PC_REC_INCR_XFER_SIZE:
178 /* XXX It is not entirely clear what the limit is supposed to do.
179 What is incremented? */
180 return -1;
182 case _PC_REC_MAX_XFER_SIZE:
183 /* XXX It is not entirely clear what the limit is supposed to do.
184 In general there is no top limit of the number of bytes which
185 case be transported at once. */
186 return -1;
188 case _PC_REC_MIN_XFER_SIZE:
190 /* XXX It is not entirely clear what the limit is supposed to do.
191 I assume this is the block size of the filesystem. */
192 struct statvfs64 sv;
194 if (__statvfs64 (path, &sv) < 0)
195 return -1;
196 return sv.f_bsize;
199 case _PC_REC_XFER_ALIGN:
201 /* XXX It is not entirely clear what the limit is supposed to do.
202 I assume that the number should reflect the minimal block
203 alignment. */
204 struct statvfs64 sv;
206 if (__statvfs64 (path, &sv) < 0)
207 return -1;
208 return sv.f_frsize;
211 case _PC_ALLOC_SIZE_MIN:
213 /* XXX It is not entirely clear what the limit is supposed to do.
214 I assume that the number should reflect the minimal block
215 alignment. */
216 struct statvfs64 sv;
218 if (__statvfs64 (path, &sv) < 0)
219 return -1;
220 return sv.f_frsize;
223 case _PC_SYMLINK_MAX:
224 /* In general there are no limits. If a system has one it should
225 overwrite this case. */
226 return -1;
228 case _PC_2_SYMLINKS:
229 /* Unix systems generally have symlinks. */
230 return 1;
234 #undef __pathconf
235 weak_alias (__pathconf, pathconf)