xref: /csrg-svn/lib/libcompat/4.1/vlimit.c (revision 61240)
148368Sbostic /*-
2*61240Sbostic  * Copyright (c) 1980, 1993
3*61240Sbostic  *	The Regents of the University of California.  All rights reserved.
448368Sbostic  *
548368Sbostic  * %sccs.include.proprietary.c%
621336Sdist  */
713218Ssam 
826523Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*61240Sbostic static char sccsid[] = "@(#)vlimit.c	8.1 (Berkeley) 06/04/93";
1048368Sbostic #endif /* LIBC_SCCS and not lint */
1121336Sdist 
1213218Ssam /*
1313218Ssam  * (Almost) backwards compatible vlimit.
1413218Ssam  */
1553719Smckusick #include <sys/types.h>
1613219Ssam #include <sys/time.h>
1713218Ssam #include <sys/resource.h>
1813219Ssam #include <errno.h>
1913218Ssam 
2013218Ssam /* LIM_NORAISE is not emulated */
2113218Ssam #define	LIM_NORAISE	0	/* if <> 0, can't raise limits */
2213218Ssam #define	LIM_CPU		1	/* max secs cpu time */
2313218Ssam #define	LIM_FSIZE	2	/* max size of file created */
2413218Ssam #define	LIM_DATA	3	/* max growth of data space */
2513218Ssam #define	LIM_STACK	4	/* max growth of stack */
2613218Ssam #define	LIM_CORE	5	/* max size of ``core'' file */
2713218Ssam #define	LIM_MAXRSS	6	/* max desired data+stack core usage */
2813218Ssam 
2913218Ssam #define	NLIMITS		6
3013218Ssam 
vlimit(limit,value)3113218Ssam vlimit(limit, value)
3213218Ssam 	int limit, value;
3313218Ssam {
3413218Ssam 	struct rlimit rlim;
3513218Ssam 
3613218Ssam 	if (limit <= 0 || limit > NLIMITS)
3713218Ssam 		return (EINVAL);
3813218Ssam 	if (value == -1) {
3913218Ssam 		if (getrlimit(limit - 1, &rlim) < 0)
4013218Ssam 			return (-1);
4113218Ssam 		return (rlim.rlim_cur);
4213218Ssam 	}
4313218Ssam 	rlim.rlim_cur = value;
4413218Ssam 	rlim.rlim_max = RLIM_INFINITY;
4513218Ssam 	return (setrlimit(limit - 1, &rlim));
4613218Ssam }
47