getrlimit.c 1.7 KB

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