nice.c 656 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * nice() 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. #include <unistd.h>
  11. #ifdef __NR_nice
  12. _syscall1(int, nice, int, inc);
  13. #else
  14. #include <sys/resource.h>
  15. int nice(int incr)
  16. {
  17. int save, prio, result;
  18. save = errno;
  19. __set_errno(0);
  20. prio = getpriority(PRIO_PROCESS, 0);
  21. if (prio == -1) {
  22. if (errno != 0) {
  23. return -1;
  24. } else {
  25. __set_errno(save);
  26. }
  27. }
  28. result = setpriority(PRIO_PROCESS, 0, prio + incr);
  29. if (result != -1) {
  30. return prio + incr;
  31. } else {
  32. return -1;
  33. }
  34. }
  35. #endif