1 /* Linux setrlimit implementation (32 bits off_t).
2    Copyright (C) 2016-2021 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library.  If not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #include <sys/resource.h>
20 #include <sysdep.h>
21 #include <shlib-compat.h>
22 
23 #if !__RLIM_T_MATCHES_RLIM64_T
24 
25 /* The compatibility symbol is meant to match the old __NR_getrlimit syscall
26    (with broken RLIM_INFINITY definition).  It should be provided iff
27    __NR_getrlimit and __NR_ugetrlimit are both defined.  */
28 # ifndef __NR_ugetrlimit
29 #  undef SHLIB_COMPAT
30 #  define SHLIB_COMPAT(a, b, c) 0
31 # endif
32 
33 int
__setrlimit(enum __rlimit_resource resource,const struct rlimit * rlim)34 __setrlimit (enum __rlimit_resource resource, const struct rlimit *rlim)
35 {
36   struct rlimit64 rlim64;
37 
38   if (rlim->rlim_cur == RLIM_INFINITY)
39     rlim64.rlim_cur = RLIM64_INFINITY;
40   else
41     rlim64.rlim_cur = rlim->rlim_cur;
42   if (rlim->rlim_max == RLIM_INFINITY)
43     rlim64.rlim_max = RLIM64_INFINITY;
44   else
45     rlim64.rlim_max = rlim->rlim_max;
46 
47   return INLINE_SYSCALL_CALL (prlimit64, 0, resource, &rlim64, NULL);
48 }
49 
50 libc_hidden_def (__setrlimit)
51 # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
52 strong_alias (__setrlimit, __setrlimit_1)
53 compat_symbol (libc, __setrlimit, setrlimit, GLIBC_2_0);
54 versioned_symbol (libc, __setrlimit_1, setrlimit, GLIBC_2_2);
55 # else
56 weak_alias (__setrlimit, setrlimit)
57 # endif
58 
59 #endif /* __RLIM_T_MATCHES_RLIM64_T  */
60