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