getrlimit.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * getrlimit() for uClibc
  3. *
  4. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <sys/syscall.h>
  9. #include <sys/resource.h>
  10. #include <bits/wordsize.h>
  11. #include <stddef.h> // needed for NULL to be defined
  12. /* Only wrap getrlimit if the new ugetrlimit is not present and getrlimit sucks */
  13. #if defined(__NR_ugetrlimit)
  14. /* just call ugetrlimit() */
  15. # define __NR___syscall_ugetrlimit __NR_ugetrlimit
  16. static __always_inline
  17. _syscall2(int, __syscall_ugetrlimit, enum __rlimit_resource, resource,
  18. struct rlimit *, rlim)
  19. int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  20. {
  21. return __syscall_ugetrlimit(resource, rlimits);
  22. }
  23. #else
  24. # if !defined(__UCLIBC_HANDLE_OLDER_RLIMIT__)
  25. # if defined(__NR_prlimit64)
  26. int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  27. {
  28. return INLINE_SYSCALL (prlimit64, 4, 0, resource, NULL, rlimits);
  29. }
  30. # else
  31. /* We don't need to wrap getrlimit() */
  32. _syscall2(int, getrlimit, __rlimit_resource_t, resource,
  33. struct rlimit *, rlim)
  34. # endif
  35. # else
  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. int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  41. {
  42. int result;
  43. # if defined(__NR_prlimit64)
  44. result = INLINE_SYSCALL (prlimit64, 4, 0, resource, NULL, rlimits);
  45. # else
  46. result = __syscall_getrlimit(resource, rlimits);
  47. # endif
  48. if (result == -1)
  49. return result;
  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. #endif
  60. libc_hidden_def(getrlimit)
  61. #if __WORDSIZE == 64
  62. strong_alias_untyped(getrlimit, getrlimit64)
  63. #endif