]> git.saurik.com Git - apple/libc.git/blob - gen/FreeBSD/nice.c.patch
Libc-763.13.tar.gz
[apple/libc.git] / gen / FreeBSD / nice.c.patch
1 --- nice.c.orig 2009-11-07 14:51:38.000000000 -0800
2 +++ nice.c 2009-11-07 14:51:40.000000000 -0800
3 @@ -38,7 +38,9 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/nic
4 #include <sys/resource.h>
5 #include <errno.h>
6 #include <unistd.h>
7 -
8 +#if __DARWIN_UNIX03
9 +#include <limits.h>
10 +#endif /* __DARWIN_UNIX03 */
11 /*
12 * Backwards compatible nice.
13 */
14 @@ -46,11 +48,18 @@ int
15 nice(incr)
16 int incr;
17 {
18 - int prio;
19 + int prio, rv;
20
21 errno = 0;
22 prio = getpriority(PRIO_PROCESS, 0);
23 if (prio == -1 && errno)
24 return (-1);
25 - return (setpriority(PRIO_PROCESS, 0, prio + incr));
26 +#if __DARWIN_UNIX03
27 + if (prio + incr > NZERO-1)
28 + incr = NZERO-1-prio;
29 +#endif /* __DARWIN_UNIX03 */
30 + rv = setpriority(PRIO_PROCESS, 0, prio + incr);
31 + if (rv == -1 && errno == EACCES)
32 + errno = EPERM;
33 + return (rv == -1) ? rv : getpriority(PRIO_PROCESS, 0);
34 }