getrlimit.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. /* Only wrap getrlimit if the new ugetrlimit is not present and getrlimit sucks */
  12. #if defined __NR_ugetrlimit
  13. /* just call ugetrlimit() */
  14. # define __NR___syscall_ugetrlimit __NR_ugetrlimit
  15. static __always_inline
  16. _syscall2(int, __syscall_ugetrlimit, enum __rlimit_resource, resource,
  17. struct rlimit *, rlim)
  18. int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  19. {
  20. return __syscall_ugetrlimit(resource, rlimits);
  21. }
  22. #elif !defined(__UCLIBC_HANDLE_OLDER_RLIMIT__)
  23. /* We don't need to wrap getrlimit() */
  24. _syscall2(int, getrlimit, __rlimit_resource_t, resource,
  25. struct rlimit *, rlim)
  26. #else
  27. /* we have to handle old style getrlimit() */
  28. # define __NR___syscall_getrlimit __NR_getrlimit
  29. static __always_inline
  30. _syscall2(int, __syscall_getrlimit, int, resource, struct rlimit *, rlim)
  31. int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  32. {
  33. int result;
  34. result = __syscall_getrlimit(resource, rlimits);
  35. if (result == -1)
  36. return result;
  37. /* We might have to correct the limits values. Since the old values
  38. * were signed the infinity value is too small. */
  39. if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
  40. rlimits->rlim_cur = RLIM_INFINITY;
  41. if (rlimits->rlim_max == RLIM_INFINITY >> 1)
  42. rlimits->rlim_max = RLIM_INFINITY;
  43. return result;
  44. }
  45. #endif
  46. libc_hidden_def(getrlimit)
  47. #if __WORDSIZE == 64
  48. strong_alias_untyped(getrlimit, getrlimit64)
  49. #endif