setrlimit.c 2.0 KB

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