1 /* Get file-specific information about a file. Linux version.
2 Copyright (C) 2003, 2004, 2006, 2008 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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
26 #include <sys/resource.h>
27 #include <not-cancel.h>
30 /* Legacy value of ARG_MAX. The macro is now not defined since the
31 actual value varies based on the stack size. */
32 #define legacy_ARG_MAX 131072
35 static long int posix_sysconf (int name
);
38 /* Get the value of the system variable NAME. */
42 const char *procfname
= NULL
;
46 #ifdef __NR_clock_getres
47 case _SC_MONOTONIC_CLOCK
:
48 /* Check using the clock_getres system call. */
51 INTERNAL_SYSCALL_DECL (err
);
53 r
= INTERNAL_SYSCALL (clock_getres
, err
, 2, CLOCK_MONOTONIC
, &ts
);
54 return INTERNAL_SYSCALL_ERROR_P (r
, err
) ? -1 : _POSIX_VERSION
;
58 #if defined __NR_clock_getres || HP_TIMING_AVAIL
60 case _SC_THREAD_CPUTIME
:
62 /* If we have HP_TIMING, we will fall back on that if the system
63 call does not work, so we support it either way. */
65 /* Check using the clock_getres system call. */
67 INTERNAL_SYSCALL_DECL (err
);
68 int r
= INTERNAL_SYSCALL (clock_getres
, err
, 2,
70 ? CLOCK_PROCESS_CPUTIME_ID
71 : CLOCK_THREAD_CPUTIME_ID
),
73 if (INTERNAL_SYSCALL_ERROR_P (r
, err
))
76 return _POSIX_VERSION
;
81 #if __LINUX_KERNEL_VERSION < 0x020617
82 /* Determine whether this is a kernel 2.6.23 or later. Only
83 then do we have an argument limit determined by the stack
85 if (GLRO(dl_discover_osversion
) () >= 0x020617)
88 /* Use getrlimit to get the stack limit. */
90 if (__getrlimit (RLIMIT_STACK
, &rlimit
) == 0)
91 return MAX (legacy_ARG_MAX
, rlimit
.rlim_cur
/ 4);
94 return legacy_ARG_MAX
;
97 /* Try to read the information from the /proc/sys/kernel/ngroups_max
99 procfname
= "/proc/sys/kernel/ngroups_max";
102 case _SC_SIGQUEUE_MAX
:
103 /* The /proc/sys/kernel/rtsig-max file contains the answer. */
104 procfname
= "/proc/sys/kernel/rtsig-max";
111 if (procfname
!= NULL
)
113 int fd
= open_not_cancel_2 (procfname
, O_RDONLY
);
116 /* This is more than enough, the file contains a single integer. */
119 n
= TEMP_FAILURE_RETRY (read_not_cancel (fd
, buf
, sizeof (buf
) - 1));
120 close_not_cancel_no_status (fd
);
124 /* Terminate the string. */
128 long int res
= strtol (buf
, &endp
, 10);
129 if (endp
!= buf
&& (*endp
== '\0' || *endp
== '\n'))
135 return posix_sysconf (name
);
138 /* Now the POSIX version. */
140 #define __sysconf static posix_sysconf
141 #include <sysdeps/posix/sysconf.c>