getrlimit.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "syscalls.h"
  10. #include <unistd.h>
  11. #include <sys/resource.h>
  12. libc_hidden_proto(getrlimit)
  13. #ifdef __NR_ugetrlimit
  14. # define __NR___ugetrlimit __NR_ugetrlimit
  15. static inline
  16. _syscall2(int, __ugetrlimit, enum __rlimit_resource, resource,
  17. struct rlimit *, rlim);
  18. int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  19. {
  20. return (__ugetrlimit(resource, rlimits));
  21. }
  22. #else /* __NR_ugetrlimit */
  23. /* Only include the old getrlimit if the new one (ugetrlimit) is not around */
  24. # define __NR___syscall_getrlimit __NR_getrlimit
  25. static inline
  26. _syscall2(int, __syscall_getrlimit, int, resource, struct rlimit *, rlim);
  27. int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
  28. {
  29. int result;
  30. result = __syscall_getrlimit(resource, rlimits);
  31. if (result == -1)
  32. return result;
  33. /* We might have to correct the limits values. Since the old values
  34. * were signed the infinity value is too small. */
  35. if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
  36. rlimits->rlim_cur = RLIM_INFINITY;
  37. if (rlimits->rlim_max == RLIM_INFINITY >> 1)
  38. rlimits->rlim_max = RLIM_INFINITY;
  39. return result;
  40. }
  41. #endif
  42. libc_hidden_def(getrlimit)