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
/
sett.c
< prev
next >
Wrap
C/C++ Source or Header
|
2003-12-09
|
1KB
|
47 lines
#include "sizint.h"
#include <sys/time.h>
int sett(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. Unlike adjt
which changes the clock slowly, this subroutine changes
the time in one step. It is intended to remove large
errors only and is used during startup and following
a large glitch.
Both calls to get the time and set it return a value
of 0 so that the return from this subroutine should
also be 0 if both calls were ok and -2 if both
failed. If this subroutine is called with inadequate
root permissions, the first call will succeed and the
second will fail, so that the return status will be
-1.
*/
struct timeval tp;
struct timezone tzp;
int j;
LONG ix,jx; /*integer and fractional parts of adjustment*/
ix= (LONG) xx;
xx -= (double) ix; /*remove integral seconds*/
jx= 1000000*xx; /*convert remainder to microseconds*/
j=gettimeofday(&tp,&tzp);
tp.tv_sec += ix;
tp.tv_usec += jx;
/*
borrow or carry as needed
*/
if(tp.tv_usec > 1000000)
{
tp.tv_usec -= 1000000;
tp.tv_sec++;
}
if(tp.tv_usec < 0)
{
tp.tv_usec += 1000000;
tp.tv_sec--;
}
j += settimeofday(&tp,&tzp);
return(j);
}