]>
Commit | Line | Data |
---|---|---|
4aebaa6b | 1 | /* Copyright (C) 1991, 1996, 1997, 1998, 2000 Free Software Foundation, Inc. |
478b92f0 UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
478b92f0 UD |
8 | |
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
478b92f0 | 13 | |
41bdb6e2 AJ |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, write to the Free | |
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
17 | 02111-1307 USA. */ | |
28f540f4 RM |
18 | |
19 | /* This is generic in the sense that it will work with the BSD, SYSV, | |
20 | or stub versions of getrlimit. Separate versions could be written | |
21 | for efficiency, but it's probably not worth it. */ | |
22 | ||
28f540f4 RM |
23 | #include <sys/vlimit.h> |
24 | #include <sys/resource.h> | |
25 | #include <errno.h> | |
26 | ||
27 | /* Set the soft limit for RESOURCE to be VALUE. | |
28 | Returns 0 for success, -1 for failure. */ | |
29 | int | |
c4029823 UD |
30 | vlimit (resource, value) |
31 | enum __vlimit_resource resource; | |
32 | int value; | |
28f540f4 RM |
33 | { |
34 | if (resource >= LIM_CPU && resource <= LIM_MAXRSS) | |
35 | { | |
36 | /* The rlimit codes happen to each be one less | |
37 | than the corresponding vlimit codes. */ | |
38 | enum __rlimit_resource rlimit_res = | |
39 | (enum __rlimit_resource) ((int) resource - 1); | |
40 | struct rlimit lims; | |
41 | ||
50304ef0 | 42 | if (__getrlimit (rlimit_res, &lims) < 0) |
28f540f4 RM |
43 | return -1; |
44 | ||
45 | lims.rlim_cur = value; | |
4aebaa6b | 46 | return __setrlimit (rlimit_res, &lims); |
28f540f4 RM |
47 | } |
48 | ||
c4029823 | 49 | __set_errno (EINVAL); |
28f540f4 RM |
50 | return -1; |
51 | } |