setrlimit.c 1.3 KB

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