xref: /original-bsd/lib/libcompat/4.1/vlimit.c (revision e59fb703)
1 /*-
2  * Copyright (c) 1980 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)vlimit.c	5.3 (Berkeley) 04/19/91";
10 #endif /* LIBC_SCCS and not lint */
11 
12 /*
13  * (Almost) backwards compatible vlimit.
14  */
15 #include <sys/time.h>
16 #include <sys/resource.h>
17 #include <errno.h>
18 
19 /* LIM_NORAISE is not emulated */
20 #define	LIM_NORAISE	0	/* if <> 0, can't raise limits */
21 #define	LIM_CPU		1	/* max secs cpu time */
22 #define	LIM_FSIZE	2	/* max size of file created */
23 #define	LIM_DATA	3	/* max growth of data space */
24 #define	LIM_STACK	4	/* max growth of stack */
25 #define	LIM_CORE	5	/* max size of ``core'' file */
26 #define	LIM_MAXRSS	6	/* max desired data+stack core usage */
27 
28 #define	NLIMITS		6
29 
30 vlimit(limit, value)
31 	int limit, value;
32 {
33 	struct rlimit rlim;
34 
35 	if (limit <= 0 || limit > NLIMITS)
36 		return (EINVAL);
37 	if (value == -1) {
38 		if (getrlimit(limit - 1, &rlim) < 0)
39 			return (-1);
40 		return (rlim.rlim_cur);
41 	}
42 	rlim.rlim_cur = value;
43 	rlim.rlim_max = RLIM_INFINITY;
44 	return (setrlimit(limit - 1, &rlim));
45 }
46