getrlimit.c 1.7 KB

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