xref: /csrg-svn/lib/libcompat/4.1/vlimit.c (revision 26523)
121336Sdist /*
221336Sdist  * Copyright (c) 1980 Regents of the University of California.
321336Sdist  * All rights reserved.  The Berkeley software License Agreement
421336Sdist  * specifies the terms and conditions for redistribution.
521336Sdist  */
613218Ssam 
7*26523Sdonn #if defined(LIBC_SCCS) && !defined(lint)
8*26523Sdonn static char sccsid[] = "@(#)vlimit.c	5.2 (Berkeley) 03/09/86";
9*26523Sdonn #endif LIBC_SCCS and not lint
1021336Sdist 
1113218Ssam /*
1213218Ssam  * (Almost) backwards compatible vlimit.
1313218Ssam  */
1413219Ssam #include <sys/time.h>
1513218Ssam #include <sys/resource.h>
1613219Ssam #include <errno.h>
1713218Ssam 
1813218Ssam /* LIM_NORAISE is not emulated */
1913218Ssam #define	LIM_NORAISE	0	/* if <> 0, can't raise limits */
2013218Ssam #define	LIM_CPU		1	/* max secs cpu time */
2113218Ssam #define	LIM_FSIZE	2	/* max size of file created */
2213218Ssam #define	LIM_DATA	3	/* max growth of data space */
2313218Ssam #define	LIM_STACK	4	/* max growth of stack */
2413218Ssam #define	LIM_CORE	5	/* max size of ``core'' file */
2513218Ssam #define	LIM_MAXRSS	6	/* max desired data+stack core usage */
2613218Ssam 
2713218Ssam #define	NLIMITS		6
2813218Ssam 
2913218Ssam vlimit(limit, value)
3013218Ssam 	int limit, value;
3113218Ssam {
3213218Ssam 	struct rlimit rlim;
3313218Ssam 
3413218Ssam 	if (limit <= 0 || limit > NLIMITS)
3513218Ssam 		return (EINVAL);
3613218Ssam 	if (value == -1) {
3713218Ssam 		if (getrlimit(limit - 1, &rlim) < 0)
3813218Ssam 			return (-1);
3913218Ssam 		return (rlim.rlim_cur);
4013218Ssam 	}
4113218Ssam 	rlim.rlim_cur = value;
4213218Ssam 	rlim.rlim_max = RLIM_INFINITY;
4313218Ssam 	return (setrlimit(limit - 1, &rlim));
4413218Ssam }
45