#ifndef EMACS_SYSTIME_H
#define EMACS_SYSTIME_H
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
#ifdef HAVE_TZNAME
#ifndef tzname
extern char *tzname[];
#endif
#endif
#ifdef USG5_4
extern time_t timezone;
#endif
#ifdef VMS
#ifdef VAXC
#include "vmstime.h"
#endif
#endif
#ifdef HPUX
#ifdef _STRUCT_TIMEVAL
#ifndef __TIMEVAL__
#define __TIMEVAL__
#endif
#endif
#endif
#ifdef HAVE_TIMEVAL
#define EMACS_HAS_USECS
#define EMACS_TIME struct timeval
#define EMACS_SECS(time) ((time).tv_sec + 0)
#define EMACS_USECS(time) ((time).tv_usec + 0)
#define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds))
#define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds))
#ifdef GETTIMEOFDAY_ONE_ARGUMENT
#define EMACS_GET_TIME(time) gettimeofday (&(time))
#else
#ifdef HAVE_STRUCT_TIMEZONE
#define EMACS_GET_TIME(time) \
do { \
struct timezone dummy; \
gettimeofday (&(time), &dummy); \
} while (0)
#else
#define EMACS_GET_TIME(time) gettimeofday (&(time), NULL)
#endif
#endif
#define EMACS_ADD_TIME(dest, src1, src2) \
do { \
(dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
(dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \
if ((dest).tv_usec > 1000000) \
(dest).tv_usec -= 1000000, (dest).tv_sec++; \
} while (0)
#define EMACS_SUB_TIME(dest, src1, src2) \
do { \
(dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \
(dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \
if ((dest).tv_usec < 0) \
(dest).tv_usec += 1000000, (dest).tv_sec--; \
} while (0)
#define EMACS_TIME_NEG_P(time) \
((long)(time).tv_sec < 0 \
|| ((time).tv_sec == 0 \
&& (long)(time).tv_usec < 0))
#else
#define EMACS_TIME int
#define EMACS_SECS(time) (time)
#define EMACS_USECS(time) 0
#define EMACS_SET_SECS(time, seconds) ((time) = (seconds))
#define EMACS_SET_USECS(time, usecs) 0
#define EMACS_GET_TIME(t) ((t) = time ((long *) 0))
#define EMACS_ADD_TIME(dest, src1, src2) ((dest) = (src1) + (src2))
#define EMACS_SUB_TIME(dest, src1, src2) ((dest) = (src1) - (src2))
#define EMACS_TIME_NEG_P(t) ((t) < 0)
#endif
#define EMACS_SET_SECS_USECS(time, secs, usecs) \
(EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs))
extern int set_file_times __P ((char *, EMACS_TIME, EMACS_TIME));
#define EMACS_TIME_CMP(T1, T2) \
(EMACS_SECS (T1) - EMACS_SECS (T2) \
+ (EMACS_SECS (T1) == EMACS_SECS (T2) \
? EMACS_USECS (T1) - EMACS_USECS (T2) \
: 0))
#define EMACS_TIME_EQ(T1, T2) (EMACS_TIME_CMP (T1, T2) == 0)
#define EMACS_TIME_NE(T1, T2) (EMACS_TIME_CMP (T1, T2) != 0)
#define EMACS_TIME_GT(T1, T2) (EMACS_TIME_CMP (T1, T2) > 0)
#define EMACS_TIME_GE(T1, T2) (EMACS_TIME_CMP (T1, T2) >= 0)
#define EMACS_TIME_LT(T1, T2) (EMACS_TIME_CMP (T1, T2) < 0)
#define EMACS_TIME_LE(T1, T2) (EMACS_TIME_CMP (T1, T2) <= 0)
#endif