]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/getrlimit64.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / getrlimit64.c
CommitLineData
045c13d1 1/* Linux getrlimit64 implementation (64 bits rlim_t).
04277e02 2 Copyright (C) 2010-2019 Free Software Foundation, Inc.
5bd6dc5c
UD
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
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
5bd6dc5c
UD
18
19#include <errno.h>
5bd6dc5c 20#include <sys/types.h>
045c13d1
AZ
21#include <shlib-compat.h>
22
23/* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
d35989be 24 linking getrlimit64 to {__}getrlimit does not throw a type error. */
045c13d1
AZ
25#undef getrlimit
26#undef __getrlimit
27#define getrlimit getrlimit_redirect
28#define __getrlimit __getrlimit_redirect
29#include <sys/resource.h>
30#undef getrlimit
31#undef __getrlimit
5bd6dc5c
UD
32
33/* Put the soft and hard limits for RESOURCE in *RLIMITS.
34 Returns 0 if successful, -1 if not (and sets errno). */
35int
1a2325c0 36__getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
5bd6dc5c 37{
695d7d13 38 return INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits);
5bd6dc5c 39}
1a2325c0 40libc_hidden_def (__getrlimit64)
045c13d1
AZ
41
42#if __RLIM_T_MATCHES_RLIM64_T
43/* If both rlim_t and rlimt64_t are essentially the same type we can use
44 alias both interfaces. */
45strong_alias (__getrlimit64, __GI_getrlimit)
46strong_alias (__getrlimit64, __GI___getrlimit)
47strong_alias (__getrlimit64, __getrlimit)
8e900969
AJ
48/* Alpha defines a versioned getrlimit{64}. */
49# ifndef USE_VERSIONED_RLIMIT
045c13d1 50weak_alias (__getrlimit64, getrlimit)
8e900969
AJ
51weak_alias (__getrlimit64, getrlimit64)
52libc_hidden_weak (getrlimit64)
53# else
54weak_alias (__getrlimit64, __GI_getrlimit64)
55# endif
045c13d1 56
8e900969 57#elif SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
045c13d1 58/* Back compatible 2GiB limited rlimit. */
0e7d5b6e
L
59extern int __new_getrlimit (enum __rlimit_resource, struct rlimit *)
60 attribute_hidden;
045c13d1
AZ
61
62int
63attribute_compat_text_section
64__old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
65{
045c13d1 66 struct rlimit rlimits32;
045c13d1
AZ
67
68 if (__new_getrlimit (resource, &rlimits32) < 0)
69 return -1;
70
71 if (rlimits32.rlim_cur == RLIM_INFINITY)
72 rlimits->rlim_cur = RLIM64_INFINITY >> 1;
73 else
74 rlimits->rlim_cur = rlimits32.rlim_cur;
75 if (rlimits32.rlim_max == RLIM_INFINITY)
76 rlimits->rlim_max = RLIM64_INFINITY >> 1;
77 else
78 rlimits->rlim_max = rlimits32.rlim_max;
79
80 return 0;
81}
82versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_2);
83compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
c2e014cc
AJ
84#else
85weak_alias (__getrlimit64, getrlimit64)
86libc_hidden_weak (getrlimit64)
8e900969 87#endif /* __RLIM_T_MATCHES_RLIM64_T */