]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/common/getrlimit.c
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / common / getrlimit.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * getrlimit() for uClibc
4  *
5  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
6  *
7  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8  */
9
10 #include <sys/syscall.h>
11 #include <sys/resource.h>
12 #include <bits/wordsize.h>
13
14 /* Only wrap getrlimit if the new ugetrlimit is not present and getrlimit sucks */
15
16 #if defined __NR_ugetrlimit
17
18 /* just call ugetrlimit() */
19 # define __NR___syscall_ugetrlimit __NR_ugetrlimit
20 static __always_inline
21 _syscall2(int, __syscall_ugetrlimit, enum __rlimit_resource, resource,
22           struct rlimit *, rlim)
23 int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
24 {
25         return __syscall_ugetrlimit(resource, rlimits);
26 }
27
28 #elif !defined(__UCLIBC_HANDLE_OLDER_RLIMIT__)
29
30 /* We don't need to wrap getrlimit() */
31 _syscall2(int, getrlimit, __rlimit_resource_t, resource,
32           struct rlimit *, rlim)
33
34 #else
35
36 /* we have to handle old style getrlimit() */
37 # define __NR___syscall_getrlimit __NR_getrlimit
38 static __always_inline
39 _syscall2(int, __syscall_getrlimit, int, resource, struct rlimit *, rlim)
40
41 int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
42 {
43         int result;
44
45         result = __syscall_getrlimit(resource, rlimits);
46
47         if (result == -1)
48                 return result;
49
50         /* We might have to correct the limits values.  Since the old values
51          * were signed the infinity value is too small.  */
52         if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
53                 rlimits->rlim_cur = RLIM_INFINITY;
54         if (rlimits->rlim_max == RLIM_INFINITY >> 1)
55                 rlimits->rlim_max = RLIM_INFINITY;
56         return result;
57 }
58 #endif
59 libc_hidden_def(getrlimit)
60
61 #if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64
62 strong_alias_untyped(getrlimit, getrlimit64)
63 #endif