home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixlib_1 / !UnixLib37_src_resource_c_setrlimit < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-09  |  1.4 KB  |  57 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/resource/c/RCS/setrlimit,v $
  4.  * $Date: 1996/05/06 09:03:13 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: setrlimit,v $
  10.  * Revision 1.2  1996/05/06 09:03:13  unixlib
  11.  * Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
  12.  * Saved for 3.7a release.
  13.  *
  14.  * Revision 1.1  1996/04/19 21:29:28  simon
  15.  * Initial revision
  16.  *
  17.  ***************************************************************************/
  18.  
  19. static const char rcs_id[] = "$Id: setrlimit,v 1.2 1996/05/06 09:03:13 unixlib Rel $";
  20.  
  21. #include <sys/resource.h>
  22. #include <sys/unix.h>
  23. #include <errno.h>
  24.  
  25.  
  26. /* Set the soft and hard limits for RESOURCE to *RLIMITS.
  27.    Only the super-user can increase hard limits.
  28.    Return 0 if successful, -1 if not (and sets errno).  */
  29. int
  30. setrlimit (enum __rlimit_resource resource, struct rlimit *rlimits)
  31. {
  32.   struct rlimit lim;
  33.  
  34.   if (rlimits == NULL || (unsigned int) resource >= RLIMIT_NLIMITS)
  35.     {
  36.       errno = EINVAL;
  37.       return -1;
  38.     }
  39.  
  40.   lim = *rlimits;
  41.  
  42. #if 0
  43.   if (lim.rlim_max != RLIM_INFINITY)
  44.     {
  45.       /* We have no enforceable resource limits.  */
  46.       errno = ENOSYS;
  47.       return -1;
  48.     }
  49. #endif
  50.   if (lim.rlim_cur > lim.rlim_max)
  51.     lim.rlim_cur = lim.rlim_max;
  52.  
  53.   __u->limit[resource] = lim;
  54.  
  55.   return 0;
  56. }
  57.