• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <unistd.h>
2 #include <errno.h>
3 #include <sys/resource.h>
4 #include <limits.h>
5 #include "syscall.h"
6 
nice(int inc)7 int nice(int inc)
8 {
9 	int prio = inc;
10 	// Only query old priority if it can affect the result.
11 	// This also avoids issues with integer overflow.
12 	if (inc > -2*NZERO && inc < 2*NZERO)
13 		prio += getpriority(PRIO_PROCESS, 0);
14 	if (prio > NZERO-1) prio = NZERO-1;
15 	if (prio < -NZERO) prio = -NZERO;
16 	if (setpriority(PRIO_PROCESS, 0, prio)) {
17 		if (errno == EACCES)
18 			errno = EPERM;
19 		return -1;
20 	} else {
21 		return prio;
22 	}
23 }
24