]> git.saurik.com Git - apple/libc.git/blob - gen/ulimit.c
af68b84392a9495c85b952d58a35b2e791794c5a
[apple/libc.git] / gen / ulimit.c
1 #include <sys/types.h>
2 #include <sys/time.h>
3 #include <sys/resource.h>
4 #include <unistd.h>
5 #include <ulimit.h>
6 #include <stdarg.h>
7 #include <errno.h>
8
9 long int ulimit( int cmd, ... )
10 {
11 va_list ap;
12 struct rlimit rlim;
13
14 switch (cmd ) {
15 case UL_GETFSIZE:
16 if( getrlimit( RLIMIT_FSIZE, &rlim ) < 0 )
17 return -1;
18 return rlim.rlim_cur/512;
19 case UL_SETFSIZE:
20 va_start(ap, cmd);
21 rlim.rlim_cur = 512 * va_arg(ap, long int);
22 rlim.rlim_max = rlim.rlim_cur;
23 va_end(ap);
24 return setrlimit( RLIMIT_FSIZE, &rlim );
25 default:
26 errno = EINVAL;
27 return -1;
28 }
29 /* NOT REACHED */
30 errno = EINVAL;
31 return -1;
32 }