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