1 /*
2  * Copyright (c) 2019 Linaro Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #undef _POSIX_C_SOURCE
8 #define _POSIX_C_SOURCE 200809L
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <errno.h>
12 #include <sys/time.h>
13 #include <time.h>
14 #include <unistd.h>
15 
main(void)16 int main(void)
17 {
18 	struct timeval tv;
19 
20 	while (1) {
21 		int res = gettimeofday(&tv, NULL);
22 		time_t now = time(NULL);
23 		struct tm tm;
24 		localtime_r(&now, &tm);
25 
26 		if (res < 0) {
27 			printf("Error in gettimeofday(): %d\n", errno);
28 			return 1;
29 		}
30 
31 		printf("gettimeofday(): HI(tv_sec)=%d, LO(tv_sec)=%d, "
32 		       "tv_usec=%d\n\t%s\n", (unsigned int)(tv.tv_sec >> 32),
33 		       (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec,
34 		       asctime(&tm));
35 		sleep(1);
36 	}
37 }
38