getrlimit.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * getrlimit() for uClibc
  4. *
  5. * Copyright (C) 2000-2004 by Erik Andersen <andersen@codpoet.org>
  6. *
  7. * GNU Library General Public License (LGPL) version 2 or later.
  8. */
  9. #include "syscalls.h"
  10. #include <unistd.h>
  11. #include <sys/resource.h>
  12. #ifdef __NR_ugetrlimit
  13. #define __NR___ugetrlimit __NR_ugetrlimit
  14. _syscall2(int, __ugetrlimit, enum __rlimit_resource, resource,
  15. struct rlimit *, rlim);
  16. int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  17. {
  18. return (__ugetrlimit(resource, rlimits));
  19. }
  20. #else /* __NR_ugetrlimit */
  21. /* Only include the old getrlimit if the new one (ugetrlimit) is not around */
  22. #define __NR___getrlimit __NR_getrlimit
  23. static inline
  24. _syscall2(int, __getrlimit, int, resource, struct rlimit *, rlim);
  25. int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  26. {
  27. int result;
  28. result = __getrlimit(resource, rlimits);
  29. if (result == -1)
  30. return result;
  31. /* We might have to correct the limits values. Since the old values
  32. * were signed the infinity value is too small. */
  33. if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
  34. rlimits->rlim_cur = RLIM_INFINITY;
  35. if (rlimits->rlim_max == RLIM_INFINITY >> 1)
  36. rlimits->rlim_max = RLIM_INFINITY;
  37. return result;
  38. }
  39. #endif