Fix access after end of search string in regex matcher
[platform/upstream/glibc.git] / posix / sysconf.c
1 /* Copyright (C) 1991,1993,1995-1997,2001,2002,2003,2009
2    Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #include <errno.h>
21 #include <grp.h>
22 #include <pwd.h>
23 #include <stdio.h>
24 #include <unistd.h>
25 #include <time.h>
26 #include <limits.h>
27 #include <sys/param.h>
28 #include <sys/sysinfo.h>
29
30
31 /* Get the value of the system variable NAME.  */
32 long int
33 __sysconf (name)
34      int name;
35 {
36   switch (name)
37     {
38     default:
39       __set_errno (EINVAL);
40       return -1;
41
42     case _SC_TZNAME_MAX:
43       return MAX (__tzname_max (), _POSIX_TZNAME_MAX);
44
45     case _SC_CHARCLASS_NAME_MAX:
46 #ifdef  CHARCLASS_NAME_MAX
47       return CHARCLASS_NAME_MAX;
48 #else
49       return -1;
50 #endif
51
52     case _SC_COLL_WEIGHTS_MAX:
53 #ifdef  COLL_WEIGHTS_MAX
54       return COLL_WEIGHTS_MAX;
55 #else
56       return -1;
57 #endif
58
59     case _SC_EQUIV_CLASS_MAX:
60 #ifdef  EQUIV_CLASS_MAX
61       return EQUIV_CLASS_MAX;
62 #else
63       return -1;
64 #endif
65
66     case _SC_2_LOCALEDEF:
67 #ifdef  _POSIX2_LOCALEDEF
68       return _POSIX2_LOCALEDEF;
69 #else
70       return -1;
71 #endif
72
73     case _SC_NPROCESSORS_CONF:
74       return __get_nprocs_conf ();
75
76     case _SC_NPROCESSORS_ONLN:
77       return __get_nprocs ();
78
79     case _SC_PHYS_PAGES:
80       return __get_phys_pages ();
81
82     case _SC_AVPHYS_PAGES:
83       return __get_avphys_pages ();
84
85     case _SC_ATEXIT_MAX:
86       /* We have no limit since we use lists.  */
87       return INT_MAX;
88
89     case _SC_PASS_MAX:
90       /* We have no limit but since the return value might be used to
91          allocate a buffer we restrict the value.  */
92       return BUFSIZ;
93
94     case _SC_CHAR_BIT:
95       return CHAR_BIT;
96
97     case _SC_CHAR_MAX:
98       return CHAR_MAX;
99
100     case _SC_CHAR_MIN:
101       return CHAR_MIN;
102
103     case _SC_INT_MAX:
104       return INT_MAX;
105
106     case _SC_INT_MIN:
107       return INT_MIN;
108
109     case _SC_LONG_BIT:
110       return sizeof (long int) * CHAR_BIT;
111
112     case _SC_WORD_BIT:
113       return sizeof (int) * CHAR_BIT;
114
115     case _SC_MB_LEN_MAX:
116       return MB_LEN_MAX;
117
118     case _SC_NZERO:
119       return NZERO;
120
121     case _SC_SSIZE_MAX:
122       return _POSIX_SSIZE_MAX;
123
124     case _SC_SCHAR_MAX:
125       return SCHAR_MAX;
126
127     case _SC_SCHAR_MIN:
128       return SCHAR_MIN;
129
130     case _SC_SHRT_MAX:
131       return SHRT_MAX;
132
133     case _SC_SHRT_MIN:
134       return SHRT_MIN;
135
136     case _SC_UCHAR_MAX:
137       return UCHAR_MAX;
138
139     case _SC_UINT_MAX:
140       return UINT_MAX;
141
142     case _SC_ULONG_MAX:
143       return ULONG_MAX;
144
145     case _SC_USHRT_MAX:
146       return USHRT_MAX;
147
148     case _SC_GETGR_R_SIZE_MAX:
149       return NSS_BUFLEN_GROUP;
150
151     case _SC_GETPW_R_SIZE_MAX:
152       return NSS_BUFLEN_PASSWD;
153
154     case _SC_ARG_MAX:
155     case _SC_CHILD_MAX:
156     case _SC_CLK_TCK:
157     case _SC_NGROUPS_MAX:
158     case _SC_OPEN_MAX:
159     case _SC_STREAM_MAX:
160     case _SC_JOB_CONTROL:
161     case _SC_SAVED_IDS:
162     case _SC_REALTIME_SIGNALS:
163     case _SC_PRIORITY_SCHEDULING:
164     case _SC_TIMERS:
165     case _SC_ASYNCHRONOUS_IO:
166     case _SC_PRIORITIZED_IO:
167     case _SC_SYNCHRONIZED_IO:
168     case _SC_FSYNC:
169     case _SC_MAPPED_FILES:
170     case _SC_MEMLOCK:
171     case _SC_MEMLOCK_RANGE:
172     case _SC_MEMORY_PROTECTION:
173     case _SC_MESSAGE_PASSING:
174     case _SC_SEMAPHORES:
175     case _SC_SHARED_MEMORY_OBJECTS:
176
177     case _SC_AIO_LISTIO_MAX:
178     case _SC_AIO_MAX:
179     case _SC_AIO_PRIO_DELTA_MAX:
180     case _SC_DELAYTIMER_MAX:
181     case _SC_MQ_OPEN_MAX:
182     case _SC_MQ_PRIO_MAX:
183     case _SC_VERSION:
184     case _SC_PAGESIZE:
185     case _SC_RTSIG_MAX:
186     case _SC_SEM_NSEMS_MAX:
187     case _SC_SEM_VALUE_MAX:
188     case _SC_SIGQUEUE_MAX:
189     case _SC_TIMER_MAX:
190
191     case _SC_PII:
192     case _SC_PII_XTI:
193     case _SC_PII_SOCKET:
194     case _SC_PII_OSI:
195     case _SC_POLL:
196     case _SC_SELECT:
197     case _SC_UIO_MAXIOV:
198     case _SC_PII_INTERNET_STREAM:
199     case _SC_PII_INTERNET_DGRAM:
200     case _SC_PII_OSI_COTS:
201     case _SC_PII_OSI_CLTS:
202     case _SC_PII_OSI_M:
203     case _SC_T_IOV_MAX:
204
205     case _SC_BC_BASE_MAX:
206     case _SC_BC_DIM_MAX:
207     case _SC_BC_SCALE_MAX:
208     case _SC_BC_STRING_MAX:
209     case _SC_EXPR_NEST_MAX:
210     case _SC_LINE_MAX:
211     case _SC_RE_DUP_MAX:
212     case _SC_2_VERSION:
213     case _SC_2_C_BIND:
214     case _SC_2_C_DEV:
215     case _SC_2_FORT_DEV:
216     case _SC_2_SW_DEV:
217     case _SC_2_CHAR_TERM:
218     case _SC_2_C_VERSION:
219     case _SC_2_UPE:
220
221     case _SC_THREADS:
222     case _SC_THREAD_SAFE_FUNCTIONS:
223     case _SC_LOGIN_NAME_MAX:
224     case _SC_TTY_NAME_MAX:
225     case _SC_THREAD_DESTRUCTOR_ITERATIONS:
226     case _SC_THREAD_KEYS_MAX:
227     case _SC_THREAD_STACK_MIN:
228     case _SC_THREAD_THREADS_MAX:
229     case _SC_THREAD_ATTR_STACKADDR:
230     case _SC_THREAD_ATTR_STACKSIZE:
231     case _SC_THREAD_PRIORITY_SCHEDULING:
232     case _SC_THREAD_PRIO_INHERIT:
233     case _SC_THREAD_PRIO_PROTECT:
234     case _SC_THREAD_PROCESS_SHARED:
235
236     case _SC_XOPEN_VERSION:
237     case _SC_XOPEN_XCU_VERSION:
238     case _SC_XOPEN_UNIX:
239     case _SC_XOPEN_CRYPT:
240     case _SC_XOPEN_ENH_I18N:
241     case _SC_XOPEN_SHM:
242     case _SC_XOPEN_XPG2:
243     case _SC_XOPEN_XPG3:
244     case _SC_XOPEN_XPG4:
245
246     case _SC_NL_ARGMAX:
247     case _SC_NL_LANGMAX:
248     case _SC_NL_MSGMAX:
249     case _SC_NL_NMAX:
250     case _SC_NL_SETMAX:
251     case _SC_NL_TEXTMAX:
252
253     case _SC_XBS5_ILP32_OFF32:
254     case _SC_XBS5_ILP32_OFFBIG:
255     case _SC_XBS5_LP64_OFF64:
256     case _SC_XBS5_LPBIG_OFFBIG:
257
258     case _SC_POSIX_V6_ILP32_OFF32:
259     case _SC_POSIX_V6_ILP32_OFFBIG:
260     case _SC_POSIX_V6_LP64_OFF64:
261     case _SC_POSIX_V6_LPBIG_OFFBIG:
262
263     case _SC_POSIX_V7_ILP32_OFF32:
264     case _SC_POSIX_V7_ILP32_OFFBIG:
265     case _SC_POSIX_V7_LP64_OFF64:
266     case _SC_POSIX_V7_LPBIG_OFFBIG:
267
268     case _SC_XOPEN_LEGACY:
269     case _SC_XOPEN_REALTIME:
270     case _SC_XOPEN_REALTIME_THREADS:
271
272       break;
273     }
274
275   __set_errno (ENOSYS);
276   return -1;
277 }
278
279 weak_alias (__sysconf, sysconf)
280 libc_hidden_def (__sysconf)
281
282 stub_warning (sysconf)
283 #include <stub-tag.h>