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