#include #include #include #include #include #include #include "ytiming.h" void GetCurrentTime(YTime *t); time_t MilliTime(void); time_t UTime(void); #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define CLIP(a,l,h) (MIN(MAX((a),(l)),(h))) #define ABSOLUTE(x) (((x) < 0) ? ((x) * -1) : (x)) void GetCurrentTime(YTime *t) { struct timeval tv[1]; if((gettimeofday(tv, NULL) < 0) || (t == NULL)) return; t->ms = (tv->tv_sec % 86400l) * 1000l + tv->tv_usec / 1000l; t->us = MAX(tv->tv_usec % 1000l, 0l); } time_t MilliTime(void) { struct timeval tv[1]; if(gettimeofday(tv, NULL) < 0) { perror("gettimeofday"); return(-1); } return((tv->tv_sec % 86400) * 1000 + tv->tv_usec / 1000); } time_t UTime(void) { struct timeval tv[1]; if(gettimeofday(tv, NULL) < 0) { perror("gettimeofday"); return(-1); } return(tv->tv_usec); }