]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/common/ulimit.c
Inital import
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / common / ulimit.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
4  *
5  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6  */
7
8 #include <sys/syscall.h>
9
10 #ifdef __NR_ulimit
11
12 extern long int ulimit(int cmd, long arg);
13 _syscall2(long, ulimit, int, cmd, long, arg)
14
15 #else
16
17 #include <stdarg.h>
18 #include <unistd.h>
19 #include <ulimit.h>
20 #include <sys/resource.h>
21
22
23 long int ulimit(int cmd, ...)
24 {
25         va_list va;
26         struct rlimit limit;
27         long int result = -1;
28         va_start (va, cmd);
29         switch (cmd) {
30                 /* Get limit on file size.  */
31                 case UL_GETFSIZE:
32                         if (getrlimit(RLIMIT_FSIZE, &limit) == 0)
33                                 result =  limit.rlim_cur / 512; /* bytes to 512 byte blocksize */
34                         break;
35                 /* Set limit on file size.  */
36                 case UL_SETFSIZE:
37                         result = va_arg (va, long int);
38                         if ((rlim_t) result > RLIM_INFINITY / 512) {
39                                 limit.rlim_cur = RLIM_INFINITY;
40                                 limit.rlim_max = RLIM_INFINITY;
41                         } else {
42                                 limit.rlim_cur = result * 512;
43                                 limit.rlim_max = result * 512;
44                         }
45                         result = setrlimit(RLIMIT_FSIZE, &limit);
46                         break;
47                 case __UL_GETOPENMAX:
48                         result = sysconf(_SC_OPEN_MAX);
49                         break;
50                 default:
51                         __set_errno(EINVAL);
52         }
53         va_end (va);
54         return result;
55 }
56 #endif