-void debug(const char *format, ...) {
- struct timeval now;
- gettimeofday(&now, NULL);
- fprintf(stderr, "%lu.%lu ", now.tv_sec, now.tv_usec / 1000);
+static void debug(const char *format, ...) {
+ struct timespec tv;
+ char buf[1024];
+ int len;
+
+ clock_gettime(CLOCK_REALTIME, &tv);
+ len = snprintf(buf, sizeof(buf), "%ld.%06lu ", (long)tv.tv_sec, tv.tv_nsec / 1000);