home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / compat / unistd / nice.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-04  |  935 b   |  35 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <unistd.h>
  3. #include <errno.h>
  4.  
  5. /* The references disagree on the values of these.  Higher value
  6.    means less important process.  */
  7. #define NICE_MIN -20
  8. #define NICE_MAX +20
  9. #define NICE_USER 0
  10.  
  11. /* Currently not used, but __dpmi_int might later be set
  12.    to call __dpmi_yield() also when (nice_val > NICE_USER)
  13.    except, of course, for the __dpmi_yield() call itself.  */
  14. static int nice_val = NICE_USER;
  15.  
  16. int
  17. nice (int incr)
  18. {
  19.   if (incr < 0 && getuid () != 0) {
  20.     errno = EPERM;
  21.     return -1;
  22.   }
  23.  
  24.   nice_val += incr;
  25.   if (nice_val < NICE_MIN) nice_val = NICE_MIN;
  26.   if (nice_val > NICE_MAX) nice_val = NICE_MAX;
  27.  
  28.   /* This is braindead by design!  If -1 returned you don't know
  29.      if you had an error!  Luckily you can ignore errors for a
  30.      function like this.  */
  31.   errno = 0;
  32.   return (nice_val - NICE_USER);
  33. }
  34.  
  35.