spelling check
[unix-history] / usr / src / lib / libcompat / 4.1 / vlimit.c
CommitLineData
bb0cfa24
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
2ce81398
DS
7#if defined(LIBC_SCCS) && !defined(lint)
8static char sccsid[] = "@(#)vlimit.c 5.2 (Berkeley) %G%";
9#endif LIBC_SCCS and not lint
611c3c29
SL
10
11/*
12 * (Almost) backwards compatible vlimit.
13 */
ed4a8563 14#include <sys/time.h>
611c3c29 15#include <sys/resource.h>
ed4a8563 16#include <errno.h>
611c3c29
SL
17
18/* LIM_NORAISE is not emulated */
19#define LIM_NORAISE 0 /* if <> 0, can't raise limits */
20#define LIM_CPU 1 /* max secs cpu time */
21#define LIM_FSIZE 2 /* max size of file created */
22#define LIM_DATA 3 /* max growth of data space */
23#define LIM_STACK 4 /* max growth of stack */
24#define LIM_CORE 5 /* max size of ``core'' file */
25#define LIM_MAXRSS 6 /* max desired data+stack core usage */
26
27#define NLIMITS 6
28
29vlimit(limit, value)
30 int limit, value;
31{
32 struct rlimit rlim;
33
34 if (limit <= 0 || limit > NLIMITS)
35 return (EINVAL);
36 if (value == -1) {
37 if (getrlimit(limit - 1, &rlim) < 0)
38 return (-1);
39 return (rlim.rlim_cur);
40 }
41 rlim.rlim_cur = value;
42 rlim.rlim_max = RLIM_INFINITY;
43 return (setrlimit(limit - 1, &rlim));
44}