]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/posix/fpathconf.c
Update.
[thirdparty/glibc.git] / sysdeps / posix / fpathconf.c
CommitLineData
87d2f3f0 1/* Copyright (C) 1991,1995,1996,1998,2000,2001 Free Software Foundation, Inc.
68dbb3a6 2 This file is part of the GNU C Library.
28f540f4 3
68dbb3a6
UD
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.
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
12 Library General Public License for more details.
28f540f4 13
68dbb3a6
UD
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. */
28f540f4 18
28f540f4
RM
19#include <errno.h>
20#include <stddef.h>
21#include <unistd.h>
22#include <limits.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
145 return _POSIX_ASYNC_IO;
146#else
147 return -1;
148#endif
149
150 case _PC_PRIO_IO:
151#ifdef _POSIX_PRIO_IO
152 return _POSIX_PRIO_IO;
153#else
154 return -1;
155#endif
503054c0
RM
156
157 case _PC_SOCK_MAXBUF:
158#ifdef SOCK_MAXBUF
159 return SOCK_MAXBUF;
160#else
503054c0
RM
161 return -1;
162#endif
e918a7fe
UD
163
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
87d2f3f0
UD
171
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;
176
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;
182
183 case _PC_REC_MIN_XFER_SIZE:
184 {
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;
188
189 if (__fstatvfs64 (fd, &sv) < 0)
190 return -1;
191 return sv.f_bsize;
192 }
193
194 case _PC_REC_XFER_ALIGN:
195 {
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;
200
201 if (__fstatvfs64 (fd, &sv) < 0)
202 return -1;
203 return sv.f_frsize;
204 }
28f540f4 205 }
28f540f4
RM
206}
207
e918a7fe 208#undef __fpathconf
28f540f4 209weak_alias (__fpathconf, fpathconf)