home *** CD-ROM | disk | FTP | other *** search
/ nisttime.carsoncity.k12.mi.us / nisttime.carsoncity.k12.mi.us.tar / nisttime.carsoncity.k12.mi.us / pub / autolock / adjt.c < prev    next >
C/C++ Source or Header  |  2003-12-09  |  1KB  |  43 lines

  1. int adjt(double xx)
  2. {
  3. /*
  4.     this subroutine adjusts the time of the local clock
  5.     by xx seconds, where a positive value advances the
  6.     time and a negative value retards it.
  7.  
  8.     note that the parameter LONG is defined in sizint.h,
  9.     which is included through autolock.h
  10.  
  11.     if LINUX is defined, the the adjustment is made using
  12.     adjtimex.
  13. */
  14. #include <sys/time.h>
  15. #include "autolock.h"
  16. struct timeval delta;
  17. struct timeval olddelta;
  18. int j;
  19. #ifdef LINUX
  20. #include <sys/timex.h>
  21. struct timex tmx;        /*used in adjtimex call*/
  22. #endif    /*LINUX*/
  23. #ifdef LINUX
  24.     tmx.modes=ADJ_OFFSET_SINGLESHOT;    /*one-time adjustment*/
  25.     if(xx > 10) xx = 10;
  26.     if(xx < -10) xx = -10;        /*limit adjustments to +/- 10s*/
  27.     tmx.offset= 1e+6*xx;        /*convert to usec*/
  28.     j=adjtimex(&tmx);
  29. /*
  30.     the return status will be -1 if the adjustment failed,
  31.     otherwise it will be the status of the clock, which
  32.     we don't know here.
  33. */
  34.     if(j == -1)    return(-1);    /*adjtimex had an error*/
  35.     else        return(0);
  36. #else
  37.     delta.tv_sec=(LONG) xx;
  38.     delta.tv_usec=(LONG)(1000000l*(xx-delta.tv_sec));
  39.     j=adjtime(&delta,&olddelta);
  40.     return(j);
  41. #endif
  42. }
  43.