setrlimit.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * setrlimit() 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(setrlimit)
  13. #ifndef __NR_ugetrlimit
  14. /* Only wrap setrlimit if the new ugetrlimit is not present */
  15. #define __NR___syscall_setrlimit __NR_setrlimit
  16. #define RMIN(x, y) ((x) < (y) ? (x) : (y))
  17. static inline
  18. _syscall2(int, __syscall_setrlimit, int, resource, const struct rlimit *, rlim);
  19. int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlimits)
  20. {
  21. struct rlimit rlimits_small;
  22. /* We might have to correct the limits values. Since the old values
  23. * were signed the new values might be too large. */
  24. rlimits_small.rlim_cur = RMIN((unsigned long int) rlimits->rlim_cur,
  25. RLIM_INFINITY >> 1);
  26. rlimits_small.rlim_max = RMIN((unsigned long int) rlimits->rlim_max,
  27. RLIM_INFINITY >> 1);
  28. return (__syscall_setrlimit(resource, &rlimits_small));
  29. }
  30. #undef RMIN
  31. #else /* We don't need to wrap setrlimit */
  32. _syscall2(int, setrlimit, __rlimit_resource_t, resource,
  33. const struct rlimit *, rlim);
  34. #endif
  35. libc_hidden_def(setrlimit)