1 /* Get file-specific information about a file. Linux version.
2 Copyright (C) 2003-2024 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, see
17 <https://www.gnu.org/licenses/>. */
26 #include <sys/resource.h>
27 #include <sys/param.h>
28 #include <not-cancel.h>
30 #include <sysconf-sigstksz.h>
32 /* Legacy value of ARG_MAX. The macro is now not defined since the
33 actual value varies based on the stack size. */
34 #define legacy_ARG_MAX 131072
36 /* Newer kernels (4.13) limit the maximum command line arguments lengths to
38 #define maximum_ARG_MAX (6 * 1024 * 1024)
40 static long int posix_sysconf (int name
);
43 /* Get the value of the system variable NAME. */
47 const char *procfname
= NULL
;
51 case _SC_MONOTONIC_CLOCK
:
53 case _SC_THREAD_CPUTIME
:
54 return _POSIX_VERSION
;
59 /* Use getrlimit to get the stack limit. */
60 if (__getrlimit (RLIMIT_STACK
, &rlimit
) == 0)
62 const long int limit
= MAX (legacy_ARG_MAX
, rlimit
.rlim_cur
/ 4);
63 return MIN (limit
, maximum_ARG_MAX
);
66 return legacy_ARG_MAX
;
70 /* Try to read the information from the /proc/sys/kernel/ngroups_max
72 procfname
= "/proc/sys/kernel/ngroups_max";
75 case _SC_SIGQUEUE_MAX
:
78 if (__getrlimit (RLIMIT_SIGPENDING
, &rlimit
) == 0)
79 return rlimit
.rlim_cur
;
81 /* The /proc/sys/kernel/rtsig-max file contains the answer. */
82 procfname
= "/proc/sys/kernel/rtsig-max";
87 assert (GLRO(dl_minsigstacksize
) != 0);
88 return GLRO(dl_minsigstacksize
);
91 return sysconf_sigstksz ();
97 if (procfname
!= NULL
)
99 int fd
= __open_nocancel (procfname
, O_RDONLY
| O_CLOEXEC
);
102 /* This is more than enough, the file contains a single integer. */
105 n
= TEMP_FAILURE_RETRY (__read_nocancel (fd
, buf
, sizeof (buf
) - 1));
106 __close_nocancel_nostatus (fd
);
110 /* Terminate the string. */
114 long int res
= strtol (buf
, &endp
, 10);
115 if (endp
!= buf
&& (*endp
== '\0' || *endp
== '\n'))
121 return posix_sysconf (name
);
124 /* Now the POSIX version. */
126 #define __sysconf static posix_sysconf
127 #include <sysdeps/posix/sysconf.c>