summaryrefslogtreecommitdiff
path: root/lib/libc/unistd
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/unistd')
-rw-r--r--lib/libc/unistd/nice.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/libc/unistd/nice.c b/lib/libc/unistd/nice.c
index 78dccbb0..29ac8487 100644
--- a/lib/libc/unistd/nice.c
+++ b/lib/libc/unistd/nice.c
@@ -1,8 +1,28 @@
-#include <unistd.h> // for nice
+#include <errno.h>
+#include <limits.h>
+#include <sys/resource.h>
+#include <unistd.h>
int nice(int incr)
{
- (void)incr;
- // TODO: needs getpriority and setpriority from sys/resouce.h
- return 0;
+ int priority = incr;
+
+ if (incr > NZERO * -2 && incr < NZERO * 2) {
+ priority += getpriority(PRIO_PROCESS, 0);
+ }
+
+ if (priority > NZERO - 1)
+ priority = NZERO - 1;
+
+ if (priority < -NZERO)
+ priority = -NZERO;
+
+ if (setpriority(PRIO_PROCESS, 0, priority)) {
+ if (errno == EACCES)
+ errno = EPERM;
+
+ return -1;
+ }
+
+ return priority;
}