Skip to content

Instantly share code, notes, and snippets.

@smcc
Created October 28, 2016 03:58
Show Gist options
  • Save smcc/8ff413f7c180072b958c3d6b176b0070 to your computer and use it in GitHub Desktop.
Save smcc/8ff413f7c180072b958c3d6b176b0070 to your computer and use it in GitHub Desktop.
Test program for some Unix time syscalls
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
int main(int argc, char **argv) {
struct timespec ts;
struct timeval tv;
for (;;) {
int res;
ts.tv_sec = (time_t)-1;
ts.tv_nsec = (long)-1;
res = clock_gettime(CLOCK_REALTIME, &ts);
if (res) {
fprintf(stderr, "clock_gettime failed: %s\n", strerror(errno));
exit(1);
}
printf("%08lx.%08lx ", (long)ts.tv_sec, (long)ts.tv_nsec);
tv.tv_sec = (time_t)-1;
tv.tv_usec = (long)-1;
res = gettimeofday(&tv, 0);
if (res) {
fprintf(stderr, "gettimeofday failed: %s\n", strerror(errno));
exit(1);
}
printf("%08lx.%05lx\n", (long)tv.tv_sec, (long)tv.tv_usec);
sleep(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment