No clock_gettime on OS X; must use gettimeofday.

This commit is contained in:
Andrzej Kapolka 2013-07-10 14:21:23 -07:00
parent 0aa1b396db
commit 53eb5ed0bb
2 changed files with 6 additions and 4 deletions

View file

@ -7,6 +7,7 @@
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include "inv_tty.h"
@ -81,8 +82,9 @@ void tty_delay_ms(unsigned long num_ms) {
}
void tty_get_ms(unsigned long *count) {
struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);
const long NANOSECONDS_PER_SECOND = 1000000000;
*count = time.tv_sec * NANOSECONDS_PER_SECOND + time.tv_nsec;
struct timeval time;
gettimeofday(&time, 0);
const long MILLISECONDS_PER_SECOND = 1000;
const long MICROSECONDS_PER_MILLISECOND = 1000;
*count = time.tv_sec * MILLISECONDS_PER_SECOND + time.tv_usec / MICROSECONDS_PER_MILLISECOND;
}