OSDN Git Service

0684edca2800c32bb30493d138d0c9923e0e353a
[uclinux-h8/uClibc.git] / 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 #define getrlimit64 __hide_getrlimit64
11 #include <sys/syscall.h>
12 #include <unistd.h>
13 #include <sys/resource.h>
14 #undef getrlimit64
15
16 libc_hidden_proto(getrlimit)
17
18 /* Only wrap getrlimit if the new ugetrlimit is not present and getrlimit sucks */
19
20 #if defined(__NR_ugetrlimit)
21
22 /* just call ugetrlimit() */
23 # define __NR___syscall_ugetrlimit __NR_ugetrlimit
24 static inline
25 _syscall2(int, __syscall_ugetrlimit, enum __rlimit_resource, resource,
26           struct rlimit *, rlim);
27 int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
28 {
29         return (__syscall_ugetrlimit(resource, rlimits));
30 }
31
32 #elif !defined(__UCLIBC_HANDLE_OLDER_RLIMIT__)
33
34 /* We don't need to wrap getrlimit() */
35 _syscall2(int, getrlimit, __rlimit_resource_t, resource,
36                 struct rlimit *, rlim);
37
38 #else
39
40 /* we have to handle old style getrlimit() */
41 # define __NR___syscall_getrlimit __NR_getrlimit
42 static inline
43 _syscall2(int, __syscall_getrlimit, int, resource, struct rlimit *, rlim);
44
45 int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
46 {
47         int result;
48
49         result = __syscall_getrlimit(resource, rlimits);
50
51         if (result == -1)
52                 return result;
53
54         /* We might have to correct the limits values.  Since the old values
55          * were signed the infinity value is too small.  */
56         if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
57                 rlimits->rlim_cur = RLIM_INFINITY;
58         if (rlimits->rlim_max == RLIM_INFINITY >> 1)
59                 rlimits->rlim_max = RLIM_INFINITY;
60         return result;
61 }
62 #endif
63
64 libc_hidden_def(getrlimit)
65
66 #if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64
67 strong_alias(getrlimit, getrlimit64)
68 #endif