1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
6 * Copyright (C) 2005 by Manuel Novoa III <mjn3@codepoet.org>
8 * GNU Library General Public License (LGPL) version 2 or later.
13 #include <sys/resource.h>
15 libc_hidden_proto(getpriority)
19 #define __NR___syscall_nice __NR_nice
20 static inline _syscall1(int, __syscall_nice, int, incr);
26 libc_hidden_proto(setpriority)
28 static inline int int_add_no_wrap(int a, int b)
33 if (s > a) s = INT_MIN;
35 if (s < a) s = INT_MAX;
41 static inline int __syscall_nice(int incr)
45 /* This should never fail. */
46 old_priority = getpriority(PRIO_PROCESS, 0);
48 /* But if you want to be paranoid... */
53 old_priority = getpriority(PRIO_PROCESS, 0);
54 if ((old_priority == -1) && errno) {
57 __set_errno(old_errno);
60 if (setpriority(PRIO_PROCESS, 0, int_add_no_wrap(old_priority, incr))) {
61 __set_errno(EPERM); /* SUSv3 mandates EPERM for nice failure. */
72 if (__syscall_nice(incr)) {
76 return getpriority(PRIO_PROCESS, 0);