
#include "/home/nevil/ntm-44/ntm_conf.h"
#include <sys/time.h>

int tv_minus(struct timeval x, struct timeval y)
{  /* Returns x-y microseconds */
  int s,u;

   s = x.tv_sec - y.tv_sec;
   if ((u = x.tv_usec - y.tv_usec) < 0) {
      --s;  u += 1000000;
      }
   return s*1000000 + u;
   }


int main(int argc, char *argv[])
{
   struct timeval a, b;

   a.tv_sec = 5;  a.tv_usec = 1000;
   b.tv_sec = 4;  b.tv_usec = 1000;
   printf(" a(%u.%06u) - n(%u.%06u) => %d\n", a,b, tv_minus(a,b));

   b.tv_sec = 5;  b.tv_usec = 1000;
   printf(" a(%u.%06u) - n(%u.%06u) => %d\n", a,b, tv_minus(a,b));

   b.tv_sec = 6;  b.tv_usec = 1000;
   printf(" a(%u.%06u) - n(%u.%06u) => %d\n", a,b, tv_minus(a,b));


   b.tv_sec = 5;  b.tv_usec =  900;
   printf(" a(%u.%06u) - n(%u.%06u) => %d\n", a,b, tv_minus(a,b));

   b.tv_sec = 5;  b.tv_usec = 1100;
   printf(" a(%u.%06u) - n(%u.%06u) => %d\n", a,b, tv_minus(a,b));


   b.tv_sec = 6;  b.tv_usec = 10;
   printf(" a(%u.%06u) - n(%u.%06u) => %d\n", a,b, tv_minus(a,b));

   a.tv_sec = 5;  a.tv_usec = 999900;
   b.tv_sec = 6;  b.tv_usec = 50;
   printf(" a(%u.%06u) - n(%u.%06u) => %d\n", a,b, tv_minus(a,b));

   a.tv_sec = 5;  b.tv_usec = 1000;
   b.tv_sec = 3;  b.tv_usec = 999900;
   printf(" a(%u.%06u) - n(%u.%06u) => %d\n", a,b, tv_minus(a,b));
   }
