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 >
Wrap
C/C++ Source or Header
|
2003-12-09
|
1KB
|
43 lines
int adjt(double xx)
{
/*
this subroutine adjusts the time of the local clock
by xx seconds, where a positive value advances the
time and a negative value retards it.
note that the parameter LONG is defined in sizint.h,
which is included through autolock.h
if LINUX is defined, the the adjustment is made using
adjtimex.
*/
#include <sys/time.h>
#include "autolock.h"
struct timeval delta;
struct timeval olddelta;
int j;
#ifdef LINUX
#include <sys/timex.h>
struct timex tmx; /*used in adjtimex call*/
#endif /*LINUX*/
#ifdef LINUX
tmx.modes=ADJ_OFFSET_SINGLESHOT; /*one-time adjustment*/
if(xx > 10) xx = 10;
if(xx < -10) xx = -10; /*limit adjustments to +/- 10s*/
tmx.offset= 1e+6*xx; /*convert to usec*/
j=adjtimex(&tmx);
/*
the return status will be -1 if the adjustment failed,
otherwise it will be the status of the clock, which
we don't know here.
*/
if(j == -1) return(-1); /*adjtimex had an error*/
else return(0);
#else
delta.tv_sec=(LONG) xx;
delta.tv_usec=(LONG)(1000000l*(xx-delta.tv_sec));
j=adjtime(&delta,&olddelta);
return(j);
#endif
}