diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-22 23:49:08 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-22 23:49:08 +0100 |
| commit | 46fadf4bf14360be046b9b770ddf205fad96a0a7 (patch) | |
| tree | 6e88bf6050e4f0cab877760e80f64bd708dd7400 /lib/libc/unistd/nice.c | |
| parent | 0f30d227497418c6d3bef7d52244407e30454504 (diff) | |
Add sys/resource.h implementation and nice(3)
Diffstat (limited to 'lib/libc/unistd/nice.c')
| -rw-r--r-- | lib/libc/unistd/nice.c | 28 |
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; } |
