#include <stdio.h>
#include <sys/time.h>
#include "time_util.h"

void tval_minus(struct timeval *result,
    struct timeval *tv1, struct timeval *tv2)
{
  long usec;
  result->tv_sec = tv2->tv_sec - tv1->tv_sec;
  usec = tv2->tv_usec - tv1->tv_usec;
  if (usec < 0) {
    (result->tv_sec)--;
    result->tv_usec = usec + 1000000;
  } else
    result->tv_usec = usec;
}

void tval_print(struct timeval *tv)
{
  printf("%ld sec, %ld usec", tv->tv_sec, tv->tv_usec);
}


#ifdef WINDOWS

int gettimeofday(struct timeval *tp, void *tzp)
{
  time_t curTime = time(NULL);
  tp->tv_sec = (double) curTime;
  tp->tv_usec = 0;
  if (!tzp)
    return 0;
  return -1;
}

#endif
