getrlimit.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * getrlimit() for uClibc
  4. *
  5. * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.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. static inline
  15. _syscall2(int, __ugetrlimit, enum __rlimit_resource, resource,
  16. struct rlimit *, rlim);
  17. int attribute_hidden __getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  18. {
  19. return (__ugetrlimit(resource, rlimits));
  20. }
  21. #else /* __NR_ugetrlimit */
  22. /* Only include the old getrlimit if the new one (ugetrlimit) is not around */
  23. #define __NR___syscall_getrlimit __NR_getrlimit
  24. static inline
  25. _syscall2(int, __syscall_getrlimit, int, resource, struct rlimit *, rlim);
  26. int attribute_hidden __getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  27. {
  28. int result;
  29. result = __syscall_getrlimit(resource, rlimits);
  30. if (result == -1)
  31. return result;
  32. /* We might have to correct the limits values. Since the old values
  33. * were signed the infinity value is too small. */
  34. if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
  35. rlimits->rlim_cur = RLIM_INFINITY;
  36. if (rlimits->rlim_max == RLIM_INFINITY >> 1)
  37. rlimits->rlim_max = RLIM_INFINITY;
  38. return result;
  39. }
  40. #endif
  41. strong_alias(__getrlimit,getrlimit)