]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/posix/fpathconf.c
Update.
[thirdparty/glibc.git] / sysdeps / posix / fpathconf.c
1 /* Copyright (C) 1991, 1995, 1996, 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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. */
18
19 #include <errno.h>
20 #include <stddef.h>
21 #include <unistd.h>
22 #include <limits.h>
23 #include <sys/statfs.h>
24
25
26 /* Get file-specific information about descriptor FD. */
27 long int
28 __fpathconf (fd, name)
29 int fd;
30 int name;
31 {
32 if (fd < 0)
33 {
34 __set_errno (EBADF);
35 return -1;
36 }
37
38 switch (name)
39 {
40 default:
41 __set_errno (EINVAL);
42 return -1;
43
44 case _PC_LINK_MAX:
45 #ifdef LINK_MAX
46 return LINK_MAX;
47 #else
48 return -1;
49 #endif
50
51 case _PC_MAX_CANON:
52 #ifdef MAX_CANON
53 return MAX_CANON;
54 #else
55 return -1;
56 #endif
57
58 case _PC_MAX_INPUT:
59 #ifdef MAX_INPUT
60 return MAX_INPUT;
61 #else
62 return -1;
63 #endif
64
65 case _PC_NAME_MAX:
66 #ifdef NAME_MAX
67 {
68 struct statfs buf;
69 int save_errno = errno;
70
71 if (__fstatfs (fd, &buf) < 0)
72 {
73 if (errno == ENOSYS)
74 {
75 __set_errno (save_errno);
76 return NAME_MAX;
77 }
78 else if (errno == ENODEV)
79 __set_errno (EINVAL);
80
81 return -1;
82 }
83 else
84 return buf.f_namelen;
85 }
86 #else
87 return -1;
88 #endif
89
90 case _PC_PATH_MAX:
91 #ifdef PATH_MAX
92 return PATH_MAX;
93 #else
94 return -1;
95 #endif
96
97 case _PC_PIPE_BUF:
98 #ifdef PIPE_BUF
99 return PIPE_BUF;
100 #else
101 return -1;
102 #endif
103
104 case _PC_CHOWN_RESTRICTED:
105 #ifdef _POSIX_CHOWN_RESTRICTED
106 return _POSIX_CHOWN_RESTRICTED;
107 #else
108 return -1;
109 #endif
110
111 case _PC_NO_TRUNC:
112 #ifdef _POSIX_NO_TRUNC
113 return _POSIX_NO_TRUNC;
114 #else
115 return -1;
116 #endif
117
118 case _PC_VDISABLE:
119 #ifdef _POSIX_VDISABLE
120 return _POSIX_VDISABLE;
121 #else
122 return -1;
123 #endif
124
125 case _PC_SYNC_IO:
126 #ifdef _POSIX_SYNC_IO
127 return _POSIX_SYNC_IO;
128 #else
129 return -1;
130 #endif
131
132 case _PC_ASYNC_IO:
133 #ifdef _POSIX_ASYNC_IO
134 return _POSIX_ASYNC_IO;
135 #else
136 return -1;
137 #endif
138
139 case _PC_PRIO_IO:
140 #ifdef _POSIX_PRIO_IO
141 return _POSIX_PRIO_IO;
142 #else
143 return -1;
144 #endif
145
146 case _PC_SOCK_MAXBUF:
147 #ifdef SOCK_MAXBUF
148 return SOCK_MAXBUF;
149 #else
150 return -1;
151 #endif
152
153 case _PC_FILESIZEBITS:
154 #ifdef FILESIZEBITS
155 return FILESIZEBITS;
156 #else
157 /* We let platforms with larger file sizes overwrite this value. */
158 return 32;
159 #endif
160 }
161 }
162
163 #undef __fpathconf
164 weak_alias (__fpathconf, fpathconf)