]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/sysconf.c
Update.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sysconf.c
CommitLineData
ad0e8eb0 1/* Get file-specific information about a file. Linux version.
d024596d 2 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
ad0e8eb0
UD
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
d024596d 20#include <fcntl.h>
ad0e8eb0
UD
21#include <sysdep.h>
22#include <time.h>
23#include <unistd.h>
5db7adc4 24#include <not-cancel.h>
ad0e8eb0
UD
25
26static long int posix_sysconf (int name);
27
28/* Define this first, so it can be inlined. */
29#define __sysconf static posix_sysconf
30#include <sysdeps/posix/sysconf.c>
31
32
33/* Get the value of the system variable NAME. */
34long int
35__sysconf (int name)
36{
37 switch (name)
38 {
39#ifdef __NR_clock_getres
40 case _SC_MONOTONIC_CLOCK:
41 /* Check using the clock_getres system call. */
42 {
43 struct timespec ts;
44 INTERNAL_SYSCALL_DECL (err);
d15851ec
RM
45 int r;
46 r = INTERNAL_SYSCALL (clock_getres, err, 2, CLOCK_MONOTONIC, &ts);
0ebde03a 47 return INTERNAL_SYSCALL_ERROR_P (r, err) ? -1 : 1;
ad0e8eb0
UD
48 }
49#endif
50
d024596d
UD
51 case _SC_NGROUPS_MAX:
52 {
53 /* Try to read the information from the /proc/sys/kernel/ngroups_max
54 file. */
5db7adc4 55 int fd = open_not_cancel_2 ("/proc/sys/kernel/ngroups_max", O_RDONLY);
d024596d
UD
56 if (fd != -1)
57 {
58 /* This is more than enough, the file contains a single
59 integer. */
60 char buf[32];
5db7adc4
UD
61 ssize_t n;
62 n = TEMP_FAILURE_RETRY (read_not_cancel (fd, buf,
63 sizeof (buf) - 1));
64 close_not_cancel_no_status (fd);
d024596d 65
d024596d
UD
66 if (n > 0)
67 {
68 /* Terminate the string. */
69 buf[n] = '\0';
70
71 char *endp;
5db7adc4
UD
72 long int res = strtol (buf, &endp, 10);
73 if (endp != buf && (*endp == '\0' || *endp == '\n'))
74 return res;
d024596d 75 }
d024596d
UD
76 }
77 }
78 break;
79
ad0e8eb0 80 default:
d024596d 81 break;
ad0e8eb0 82 }
d024596d 83 return posix_sysconf (name);
ad0e8eb0 84}