ntp_unixtime.h revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 1996 by Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ntp_unixtime.h - contains constants and macros for converting between
* NTP time stamps (l_fp) and Unix times (struct timeval)
*/
#include "ntp_types.h"
/* gettimeofday() takes two args in BSD and only one in SYSV */
# if defined(HAVE_SYS_TIMERS_H) && defined(HAVE_GETCLOCK)
/* Don't #define GETTIMEOFDAY because we shouldn't be using it in this case. */
# define SETTIMEOFDAY(a, b) (settimeofday(a, b))
# else /* not (HAVE_SYS_TIMERS_H && HAVE_GETCLOCK) */
# ifdef SYSV_TIMEOFDAY
# define GETTIMEOFDAY(a, b) (gettimeofday(a))
# define SETTIMEOFDAY(a, b) (settimeofday(a))
# else /* ! SYSV_TIMEOFDAY */
# define GETTIMEOFDAY(a, b) (gettimeofday(a, b))
# define SETTIMEOFDAY(a, b) (settimeofday(a, b))
# endif /* SYSV_TIMEOFDAY */
# endif /* not (HAVE_SYS_TIMERS_H && HAVE_GETCLOCK) */
/*
* Time of day conversion constant. Ntp's time scale starts in 1900,
* Unix in 1970.
*/
/*
* These constants are used to round the time stamps computed from
* a struct timeval to the microsecond (more or less). This keeps
* things neat.
*/
/*
* Convert usec to a time stamp fraction. If you use this the program
* must include the following declarations:
*/
/*
* Convert a struct timeval to a time stamp.
*/
do { \
} while(0)
do { \
int isneg = 0; \
long usec; \
isneg = 1; \
} \
if (isneg) { \
} \
} while(0)
/*
* TV_SHIFT is used to turn the table result into a usec value. To round,
* add in TV_ROUNDBIT before shifting
*/
#define TV_SHIFT 3
#define TV_ROUNDBIT 0x4
/*
* Convert a time stamp fraction to microseconds. The time stamp
* fraction is assumed to be unsigned. To use this in a program, declare:
*/
extern long tstouslo[];
extern long tstousmid[];
extern long tstoushi[];
+ TV_ROUNDBIT) >> TV_SHIFT
/*
* Convert a time stamp to a struct timeval. The time stamp
* has to be positive.
*/
do { \
} \
} while (0)
/*
* Convert milliseconds to a time stamp fraction. This shouldn't be
* here, but it is convenient since the guys who use the definition will
* often be including this file anyway.
*/
extern u_long msutotsflo[];
extern u_long msutotsfhi[];