From 8f30ce64390e9b66f612c8344ba9185bd97cd9b6 Mon Sep 17 00:00:00 2001 From: Etienne Brateau <etienne.brateau@ensiie.fr> Date: Wed, 11 Jul 2018 22:56:37 +0200 Subject: [PATCH] sysdev: revert changes to can retrieve microseconds, but fix compilation The change was made in 20233596e5be21143732b0dbe995f49daf41dfb6 It was just a missing header, and i changed all the code. --- psys/src/sysdevs.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/psys/src/sysdevs.c b/psys/src/sysdevs.c index c34b18e..a2b7fc6 100644 --- a/psys/src/sysdevs.c +++ b/psys/src/sysdevs.c @@ -1,6 +1,7 @@ #define SYSDEVS_G #include <time.h> +#include <sys/time.h> #include <p2c/p2c.h> #include <p2c/sysglobals.h> @@ -8,11 +9,11 @@ long sysclock() { - time_t t = time(NULL); - struct tm *tz; - tz = localtime(&t); + struct timeval tv; + struct timezone tz; - return(tz->tm_sec % 86400 * 100 /*+ tz->tv_usec / 10000*/); + gettimeofday(&tv, &tz); + return tv.tv_sec % 86400 * 100 + tv.tv_usec / 10000; } @@ -29,14 +30,18 @@ void sysdate(daterec *thedate) void systime(timerec *thetime) { + struct timeval tv; + struct timezone tz; struct tm *t; time_t temp; - temp = time(NULL); + gettimeofday(&tv, &tz); + temp = tv.tv_sec; t = localtime(&temp); + thetime->hour = t->tm_hour; thetime->minute = t->tm_min; - thetime->centisecond = t->tm_sec*100 /*+ time.tv_usec/10000*/; + thetime->centisecond = t->tm_sec * 100 + tv.tv_usec / 10000; } void SETRUNLIGHT(int c) -- GitLab