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