xref: /minix3/minix/lib/libc/sys/getrlimit.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /*	getrlimit                             Author: Erik van der Kouwe
2*433d6423SLionel Sambuc  *      query resource consumtion limits      4 December 2009
3*433d6423SLionel Sambuc  *
4*433d6423SLionel Sambuc  * Based on these specifications:
5*433d6423SLionel Sambuc  * http://www.opengroup.org/onlinepubs/007908775/xsh/getdtablesize.html
6*433d6423SLionel Sambuc  * http://www.opengroup.org/onlinepubs/007908775/xsh/getrlimit.html
7*433d6423SLionel Sambuc  */
8*433d6423SLionel Sambuc 
9*433d6423SLionel Sambuc #include <sys/cdefs.h>
10*433d6423SLionel Sambuc #include "namespace.h"
11*433d6423SLionel Sambuc 
12*433d6423SLionel Sambuc #include <errno.h>
13*433d6423SLionel Sambuc #include <limits.h>
14*433d6423SLionel Sambuc #include <sys/resource.h>
15*433d6423SLionel Sambuc #include <unistd.h>
16*433d6423SLionel Sambuc 
17*433d6423SLionel Sambuc int getrlimit(int resource, struct rlimit *rlp)
18*433d6423SLionel Sambuc {
19*433d6423SLionel Sambuc 	rlim_t limit;
20*433d6423SLionel Sambuc 
21*433d6423SLionel Sambuc 	switch (resource)
22*433d6423SLionel Sambuc 	{
23*433d6423SLionel Sambuc 		case RLIMIT_CPU:
24*433d6423SLionel Sambuc 		case RLIMIT_FSIZE:
25*433d6423SLionel Sambuc 		case RLIMIT_DATA:
26*433d6423SLionel Sambuc 		case RLIMIT_STACK:
27*433d6423SLionel Sambuc 		case RLIMIT_CORE:
28*433d6423SLionel Sambuc 		case RLIMIT_RSS:
29*433d6423SLionel Sambuc 		case RLIMIT_MEMLOCK:
30*433d6423SLionel Sambuc 		case RLIMIT_NPROC:
31*433d6423SLionel Sambuc 		case RLIMIT_SBSIZE:
32*433d6423SLionel Sambuc 		case RLIMIT_AS:
33*433d6423SLionel Sambuc 		/* case RLIMIT_VMEM: Same as RLIMIT_AS */
34*433d6423SLionel Sambuc 		case RLIMIT_NTHR:
35*433d6423SLionel Sambuc 			/* no limit enforced (however architectural limits
36*433d6423SLionel Sambuc 			 * may apply)
37*433d6423SLionel Sambuc 			 */
38*433d6423SLionel Sambuc 			limit = RLIM_INFINITY;
39*433d6423SLionel Sambuc 			break;
40*433d6423SLionel Sambuc 
41*433d6423SLionel Sambuc 		case RLIMIT_NOFILE:
42*433d6423SLionel Sambuc 			limit = OPEN_MAX;
43*433d6423SLionel Sambuc 			break;
44*433d6423SLionel Sambuc 
45*433d6423SLionel Sambuc 		default:
46*433d6423SLionel Sambuc 			errno = EINVAL;
47*433d6423SLionel Sambuc 			return -1;
48*433d6423SLionel Sambuc 	}
49*433d6423SLionel Sambuc 
50*433d6423SLionel Sambuc 	/* return limit */
51*433d6423SLionel Sambuc 	rlp->rlim_cur = limit;
52*433d6423SLionel Sambuc 	rlp->rlim_max = limit;
53*433d6423SLionel Sambuc 	return 0;
54*433d6423SLionel Sambuc }
55*433d6423SLionel Sambuc 
56