setrlimit.c 1.2 KB

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