getrlimit.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * getrlimit() for uClibc
  4. *
  5. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <sys/syscall.h>
  10. #include <sys/resource.h>
  11. #include <bits/wordsize.h>
  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. #elif !defined(__UCLIBC_HANDLE_OLDER_RLIMIT__)
  24. /* We don't need to wrap getrlimit() */
  25. _syscall2(int, getrlimit, __rlimit_resource_t, resource,
  26. struct rlimit *, rlim)
  27. #else
  28. /* we have to handle old style getrlimit() */
  29. # define __NR___syscall_getrlimit __NR_getrlimit
  30. static __always_inline
  31. _syscall2(int, __syscall_getrlimit, int, resource, struct rlimit *, rlim)
  32. int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  33. {
  34. int result;
  35. result = __syscall_getrlimit(resource, rlimits);
  36. if (result == -1)
  37. return result;
  38. /* We might have to correct the limits values. Since the old values
  39. * were signed the infinity value is too small. */
  40. if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
  41. rlimits->rlim_cur = RLIM_INFINITY;
  42. if (rlimits->rlim_max == RLIM_INFINITY >> 1)
  43. rlimits->rlim_max = RLIM_INFINITY;
  44. return result;
  45. }
  46. #endif
  47. libc_hidden_def(getrlimit)
  48. #if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64
  49. strong_alias_untyped(getrlimit, getrlimit64)
  50. #endif