GRU time reading example
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
static bool test_read_ex(
const char *str, const long expected_sec, const long expected_usec) {
if (t.tv_sec != expected_sec) {
fprintf(stderr,
"The sec value %ld does not match the expected %ld\n",
t.tv_sec,
expected_sec);
return false;
}
if (t.tv_usec != expected_usec) {
fprintf(stderr,
"The usec value %li does not match the expected %li\n",
t.tv_usec,
expected_usec);
return false;
}
return true;
}
static bool test_read() {
return test_read_ex("1483228862.529000", 1483228862, 529000);
}
static bool test_write() {
struct timeval t;
t.tv_sec = 1562377512;
t.tv_usec = 671;
if (strcmp(tmp, "1562377512.671") == 0) {
free(tmp);
return true;
}
fprintf(stderr,
"Formatted time %s does not match the expected value 1562377512.671\n",
tmp);
free(tmp);
return false;
}
int main(
int argc,
char **argv) {
if (test_read()) {
if (test_write()) {
return EXIT_SUCCESS;
}
}
return EXIT_FAILURE;
}