1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
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
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
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. */
24 #include <sys/vlimit.h>
25 #include <sys/resource.h>
28 /* Set the soft limit for RESOURCE to be VALUE.
29 Returns 0 for success, -1 for failure. */
31 DEFUN(vlimit
, (resource
, value
),
32 enum __vlimit_resource resource AND
int value
)
34 if (resource
>= LIM_CPU
&& resource
<= LIM_MAXRSS
)
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);
42 if (getrlimit(rlimit_res
, &lims
) < 0)
45 lims
.rlim_cur
= value
;
46 return setrlimit(rlimit_res
, &lims
);