Back to index

glibc  2.9
Functions
ulimit.c File Reference
#include <errno.h>
#include <stdarg.h>
#include <sysdep.h>
#include <ulimit.h>
#include <unistd.h>
#include <sys/resource.h>

Go to the source code of this file.

Functions

long int __ulimit (int cmd,...)
 weak_alias (__ulimit, ulimit)

Function Documentation

long int __ulimit ( int  cmd,
  ... 
)

Definition at line 37 of file ulimit.c.

{
  struct rlimit limit;
  va_list va;
  long int result = -1;

  va_start (va, cmd);

  switch (cmd)
    {
    case UL_GETFSIZE:
      /* Get limit on file size.  */
      if (__getrlimit (RLIMIT_FSIZE, &limit) == 0)
       /* Convert from bytes to 512 byte units.  */
       result =  (limit.rlim_cur == RLIM_INFINITY
                 ? LONG_MAX : limit.rlim_cur / 512);
      break;

    case UL_SETFSIZE:
      /* Set limit on file size.  */
      {
       long int newlimit = va_arg (va, long int);
       long int newlen;

       if ((rlim_t) newlimit > RLIM_INFINITY / 512)
         {
           limit.rlim_cur = RLIM_INFINITY;
           limit.rlim_max = RLIM_INFINITY;
           newlen = LONG_MAX;
         }
       else
         {
           limit.rlim_cur = newlimit * 512;
           limit.rlim_max = newlimit * 512;
           newlen = newlimit;
         }

       result = __setrlimit (RLIMIT_FSIZE, &limit);
       if (result != -1)
         result = newlen;
      }
      break;

    case __UL_GETOPENMAX:
      result = __sysconf (_SC_OPEN_MAX);
      break;

    default:
      __set_errno (EINVAL);
    }

  va_end (va);

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

weak_alias ( __ulimit  ,
ulimit   
)