]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/posix/fpathconf.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / posix / fpathconf.c
CommitLineData
b168057a 1/* Copyright (C) 1991-2015 Free Software Foundation, Inc.
68dbb3a6 2 This file is part of the GNU C Library.
28f540f4 3
68dbb3a6 4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
28f540f4 8
68dbb3a6
UD
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
41bdb6e2 12 Lesser General Public License for more details.
28f540f4 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
28f540f4 17
28f540f4
RM
18#include <errno.h>
19#include <stddef.h>
20#include <unistd.h>
21#include <limits.h>
bc183edc 22#include <sys/stat.h>
0e3426bb 23#include <sys/statfs.h>
c1fac803 24#include <sys/statvfs.h>
28f540f4
RM
25
26
27/* Get file-specific information about descriptor FD. */
28long int
c4029823
UD
29__fpathconf (fd, name)
30 int fd;
31 int name;
28f540f4
RM
32{
33 if (fd < 0)
34 {
c4029823 35 __set_errno (EBADF);
28f540f4
RM
36 return -1;
37 }
38
39 switch (name)
40 {
41 default:
c4029823 42 __set_errno (EINVAL);
28f540f4
RM
43 return -1;
44
45 case _PC_LINK_MAX:
46#ifdef LINK_MAX
47 return LINK_MAX;
48#else
28f540f4
RM
49 return -1;
50#endif
51
52 case _PC_MAX_CANON:
53#ifdef MAX_CANON
54 return MAX_CANON;
55#else
28f540f4
RM
56 return -1;
57#endif
58
59 case _PC_MAX_INPUT:
60#ifdef MAX_INPUT
61 return MAX_INPUT;
62#else
28f540f4
RM
63 return -1;
64#endif
65
66 case _PC_NAME_MAX:
67#ifdef NAME_MAX
0e3426bb
RM
68 {
69 struct statfs buf;
2eb45444 70 int save_errno = errno;
0e3426bb
RM
71
72 if (__fstatfs (fd, &buf) < 0)
2eb45444
UD
73 {
74 if (errno == ENOSYS)
75 {
9271a050 76 __set_errno (save_errno);
2eb45444
UD
77 return NAME_MAX;
78 }
9271a050
UD
79 else if (errno == ENODEV)
80 __set_errno (EINVAL);
81
2eb45444
UD
82 return -1;
83 }
0e3426bb 84 else
a808d541
UD
85 {
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
95 }
0e3426bb 96 }
2303f5fd 97#else
2303f5fd
UD
98 return -1;
99#endif
100
101 case _PC_PATH_MAX:
102#ifdef PATH_MAX
103 return PATH_MAX;
28f540f4 104#else
28f540f4
RM
105 return -1;
106#endif
107
108 case _PC_PIPE_BUF:
109#ifdef PIPE_BUF
110 return PIPE_BUF;
111#else
28f540f4
RM
112 return -1;
113#endif
114
115 case _PC_CHOWN_RESTRICTED:
116#ifdef _POSIX_CHOWN_RESTRICTED
117 return _POSIX_CHOWN_RESTRICTED;
118#else
119 return -1;
120#endif
121
122 case _PC_NO_TRUNC:
123#ifdef _POSIX_NO_TRUNC
124 return _POSIX_NO_TRUNC;
125#else
126 return -1;
127#endif
128
129 case _PC_VDISABLE:
130#ifdef _POSIX_VDISABLE
131 return _POSIX_VDISABLE;
132#else
133 return -1;
134#endif
75cd5204
RM
135
136 case _PC_SYNC_IO:
137#ifdef _POSIX_SYNC_IO
138 return _POSIX_SYNC_IO;
139#else
140 return -1;
141#endif
142
143 case _PC_ASYNC_IO:
144#ifdef _POSIX_ASYNC_IO
bc183edc
UD
145 {
146 /* AIO is only allowed on regular files and block devices. */
147 struct stat64 st;
148
149 if (__fxstat64 (_STAT_VER, fd, &st) < 0
150 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
151 return -1;
152 else
153 return 1;
154 }
75cd5204
RM
155#else
156 return -1;
157#endif
158
159 case _PC_PRIO_IO:
160#ifdef _POSIX_PRIO_IO
161 return _POSIX_PRIO_IO;
162#else
163 return -1;
164#endif
503054c0
RM
165
166 case _PC_SOCK_MAXBUF:
167#ifdef SOCK_MAXBUF
168 return SOCK_MAXBUF;
169#else
503054c0
RM
170 return -1;
171#endif
e918a7fe
UD
172
173 case _PC_FILESIZEBITS:
174#ifdef FILESIZEBITS
175 return FILESIZEBITS;
176#else
177 /* We let platforms with larger file sizes overwrite this value. */
178 return 32;
179#endif
87d2f3f0
UD
180
181 case _PC_REC_INCR_XFER_SIZE:
182 /* XXX It is not entirely clear what the limit is supposed to do.
183 What is incremented? */
184 return -1;
185
186 case _PC_REC_MAX_XFER_SIZE:
187 /* XXX It is not entirely clear what the limit is supposed to do.
188 In general there is no top limit of the number of bytes which
189 case be transported at once. */
190 return -1;
191
192 case _PC_REC_MIN_XFER_SIZE:
193 {
194 /* XXX It is not entirely clear what the limit is supposed to do.
195 I assume this is the block size of the filesystem. */
196 struct statvfs64 sv;
197
198 if (__fstatvfs64 (fd, &sv) < 0)
199 return -1;
200 return sv.f_bsize;
201 }
202
203 case _PC_REC_XFER_ALIGN:
204 {
205 /* XXX It is not entirely clear what the limit is supposed to do.
206 I assume that the number should reflect the minimal block
207 alignment. */
208 struct statvfs64 sv;
209
210 if (__fstatvfs64 (fd, &sv) < 0)
211 return -1;
212 return sv.f_frsize;
213 }
a3bbce5b
UD
214
215 case _PC_ALLOC_SIZE_MIN:
216 {
217 /* XXX It is not entirely clear what the limit is supposed to do.
218 I assume that the number should reflect the minimal block
219 alignment. */
220 struct statvfs64 sv;
221
222 if (__fstatvfs64 (fd, &sv) < 0)
223 return -1;
224 return sv.f_frsize;
225 }
226
227 case _PC_SYMLINK_MAX:
228 /* In general there are no limits. If a system has one it should
229 overwrite this case. */
230 return -1;
564cd8b6
UD
231
232 case _PC_2_SYMLINKS:
233 /* Unix systems generally have symlinks. */
234 return 1;
28f540f4 235 }
28f540f4
RM
236}
237
e918a7fe 238#undef __fpathconf
28f540f4 239weak_alias (__fpathconf, fpathconf)