1 #include <unistd.h> 2 #include <sys/resource.h> 3 #include <limits.h> 4 #include "syscall.h" 5 nice(int inc)6int nice(int inc) 7 { 8 int prio = inc; 9 // Only query old priority if it can affect the result. 10 // This also avoids issues with integer overflow. 11 if (inc > -2*NZERO && inc < 2*NZERO) 12 prio += getpriority(PRIO_PROCESS, 0); 13 if (prio > NZERO-1) prio = NZERO-1; 14 if (prio < -NZERO) prio = -NZERO; 15 return setpriority(PRIO_PROCESS, 0, prio) ? -1 : prio; 16 } 17