home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / getrlimit.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  2.2 KB  |  105 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.1
  10. date    92.05.14.19.55.40;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @obtain current resource limits
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  *  This file is part of ixemul.library for the Amiga.
  27.  *  Copyright (C) 1991, 1992  Markus M. Wild
  28.  *
  29.  *  This library is free software; you can redistribute it and/or
  30.  *  modify it under the terms of the GNU Library General Public
  31.  *  License as published by the Free Software Foundation; either
  32.  *  version 2 of the License, or (at your option) any later version.
  33.  *
  34.  *  This library is distributed in the hope that it will be useful,
  35.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  36.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  37.  *  Library General Public License for more details.
  38.  *
  39.  *  You should have received a copy of the GNU Library General Public
  40.  *  License along with this library; if not, write to the Free
  41.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  42.  *
  43.  *  $Id$
  44.  *
  45.  *  $Log$
  46.  */
  47.  
  48. #define KERNEL
  49. #include "ixemul.h"
  50.  
  51. #include <sys/time.h>
  52. #include <sys/resource.h>
  53.  
  54. int
  55. getrlimit(int resource, struct rlimit *rlp)
  56. {
  57.   struct Task *task = (struct Task *) FindTask (0);
  58.  
  59.   if (resource < RLIMIT_CPU || resource > RLIMIT_RSS || !rlp)
  60.     {
  61.       errno = EINVAL;
  62.       return -1;
  63.     }
  64.  
  65.   if (task->tc_Node.ln_Type == NT_PROCESS)
  66.     {
  67.       /* in that case, we're not a task, but a process */
  68.       struct Process *proc = (struct Process *)task;
  69.     
  70.       switch (resource)
  71.         {
  72.         case RLIMIT_CPU:
  73.     case RLIMIT_FSIZE:
  74.     case RLIMIT_CORE:
  75.     case RLIMIT_RSS:
  76.         case RLIMIT_DATA:
  77.       rlp->rlim_cur = rlp->rlim_max = RLIM_INFINITY;
  78.       break;
  79.     case RLIMIT_STACK:
  80.       rlp->rlim_cur = rlp->rlim_max = proc->pr_StackSize;
  81.       break;
  82.     }
  83.     }    
  84.   else
  85.     {
  86.       /* so this is a task, and it has the stack-data somewhere else.. */
  87.       switch (resource)
  88.         {
  89.         case RLIMIT_CPU:
  90.     case RLIMIT_FSIZE:
  91.     case RLIMIT_CORE:
  92.     case RLIMIT_RSS:
  93.         case RLIMIT_DATA:
  94.       rlp->rlim_cur = rlp->rlim_max = RLIM_INFINITY;
  95.       break;
  96.     case RLIMIT_STACK:
  97.       rlp->rlim_cur = rlp->rlim_max = task->tc_SPUpper-task->tc_SPLower;
  98.       break;
  99.     }
  100.     }
  101.  
  102.   return 0;
  103. }
  104. @
  105.