Back to index

glibc  2.9
Defines | Functions
sysconf.c File Reference
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sysdep.h>
#include <time.h>
#include <unistd.h>
#include <sys/resource.h>
#include <not-cancel.h>
#include <ldsodefs.h>
#include <sysdeps/posix/sysconf.c>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


#define legacy_ARG_MAX   131072
#define __sysconf   static posix_sysconf


static long int posix_sysconf (int name)
long int __sysconf (int name)

Define Documentation

#define __sysconf   static posix_sysconf

Definition at line 140 of file sysconf.c.

#define legacy_ARG_MAX   131072

Definition at line 32 of file sysconf.c.

Function Documentation

long int __sysconf ( int  name)

Definition at line 40 of file sysconf.c.

  const char *procfname = NULL;

  switch (name)
#ifdef __NR_clock_getres
      /* Check using the clock_getres system call.  */
       struct timespec ts;
       int r;
       r = INTERNAL_SYSCALL (clock_getres, err, 2, CLOCK_MONOTONIC, &ts);
       return INTERNAL_SYSCALL_ERROR_P (r, err) ? -1 : _POSIX_VERSION;

#if defined __NR_clock_getres || HP_TIMING_AVAIL
    case _SC_CPUTIME:
       /* If we have HP_TIMING, we will fall back on that if the system
          call does not work, so we support it either way.  */
       /* Check using the clock_getres system call.  */
       struct timespec ts;
       int r = INTERNAL_SYSCALL (clock_getres, err, 2,
                              (name == _SC_CPUTIME
                               ? CLOCK_PROCESS_CPUTIME_ID
                               : CLOCK_THREAD_CPUTIME_ID),
       if (INTERNAL_SYSCALL_ERROR_P (r, err))
         return -1;
# endif
       return _POSIX_VERSION;

    case _SC_ARG_MAX:
#if __LINUX_KERNEL_VERSION < 0x020617
      /* Determine whether this is a kernel 2.6.23 or later.  Only
        then do we have an argument limit determined by the stack
        size.  */
      if (GLRO(dl_discover_osversion) () >= 0x020617)
         /* Use getrlimit to get the stack limit.  */
         struct rlimit rlimit;
         if (__getrlimit (RLIMIT_STACK, &rlimit) == 0)
           return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);

      return legacy_ARG_MAX;

    case _SC_NGROUPS_MAX:
      /* Try to read the information from the /proc/sys/kernel/ngroups_max
        file.  */
      procfname = "/proc/sys/kernel/ngroups_max";

    case _SC_SIGQUEUE_MAX:
      /* The /proc/sys/kernel/rtsig-max file contains the answer.  */
      procfname = "/proc/sys/kernel/rtsig-max";


  if (procfname != NULL)
      int fd = open_not_cancel_2 (procfname, O_RDONLY);
      if (fd != -1)
         /* This is more than enough, the file contains a single integer.  */
         char buf[32];
         ssize_t n;
         n = TEMP_FAILURE_RETRY (read_not_cancel (fd, buf, sizeof (buf) - 1));
         close_not_cancel_no_status (fd);

         if (n > 0)
             /* Terminate the string.  */
             buf[n] = '\0';

             char *endp;
             long int res = strtol (buf, &endp, 10);
             if (endp != buf && (*endp == '\0' || *endp == '\n'))
              return res;

  return posix_sysconf (name);

Here is the call graph for this function:

static long int posix_sysconf ( int  name) [static]

Here is the caller graph for this function: