home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / LIBC / LIBC-4.6 / LIBC-4 / libc-linux / sysdeps / linux / __adjtime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-30  |  1.1 KB  |  56 lines

  1. #include <syscall.h>
  2. #include <sys/time.h>
  3. #include <errno.h>
  4. #include <limits.h>
  5. #include <linux/timex.h>
  6.  
  7. inline static
  8. _syscall1(int, adjtimex, struct timex *, ntx);
  9.  
  10. #define MAX_SEC    (LONG_MAX / 1000000L - 2)
  11. #define MIN_SEC    (LONG_MIN / 1000000L + 2)
  12.  
  13. int
  14. __adjtime(struct timeval * itv, struct timeval * otv)
  15. {
  16.   struct timex tntx;
  17.  
  18.   if (itv)
  19.   {
  20.     struct timeval tmp;
  21.  
  22.     /* We will do some check here. */
  23.     tmp.tv_sec = itv->tv_sec + itv->tv_usec / 1000000L;
  24.     tmp.tv_usec = itv->tv_usec % 1000000L;
  25.     if (tmp.tv_sec > MAX_SEC || tmp.tv_sec < MIN_SEC)
  26.     {
  27.     errno = EINVAL;
  28.     return -1;
  29.     }
  30.     tntx.offset = tmp.tv_usec + tmp.tv_sec * 1000000L;
  31.     tntx.mode = ADJ_OFFSET_SINGLESHOT;
  32.   }
  33.   else
  34.   {
  35.     tntx.mode = 0;
  36.   }
  37.   if (adjtimex(&tntx) < 0) return -1;
  38.   if (otv)
  39.     if (tntx.offset < 0)
  40.       {
  41.     otv->tv_usec = -(-tntx.offset % 1000000);
  42.     otv->tv_sec  = -(-tntx.offset / 1000000);
  43.       }
  44.     else
  45.       {
  46.     otv->tv_usec = tntx.offset % 1000000;
  47.     otv->tv_sec  = tntx.offset / 1000000;
  48.       }
  49.   return 0;
  50. }
  51.  
  52. #include <gnu-stabs.h>
  53. #ifdef weak_alias
  54. weak_alias (__adjtime, adjtime);
  55. #endif
  56.