
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <errno.h>



/* It seems that Debian Woody (and possibly others) do not define RTLD_NEXT. */
#include <dlfcn.h>
#ifndef RTLD_NEXT
	#define RTLD_NEXT  ((void *) -1l)
#endif
#define REAL_LIBC RTLD_NEXT


int nice(int inc)
{
  static int (*func_nice)(int) = NULL;
  int errno_save = errno;
  int ret_val;
  
  if (!func_nice)
    {
      func_nice = (int (*)(int)) dlsym(REAL_LIBC, "nice");
    }
  
  errno = 0;
  
  ret_val = func_nice(inc);
  
  if (getenv("VMNICE_DEBUG"))
    {
      fprintf(stderr,"vmnice: inc=%d, ret=%d, errno=%d\n",
              inc, ret_val, errno);
    }
  
  if ((ret_val == -1) && errno)
    {
      return -1;
    }
  else
    {
      errno = errno_save;
      return 0;
    }
}
