From 0e49c842de67018d0c79e112669b1a52dc59efea Mon Sep 17 00:00:00 2001 From: Mauri de Souza Nunes Date: Fri, 27 Dec 2019 00:29:31 -0300 Subject: [PATCH] LibC: Add timeval operations This commit add macros for the timeval operations timeradd, timersub, timercmp, timerisset, timerclear. --- Libraries/LibC/sys/time.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Libraries/LibC/sys/time.h b/Libraries/LibC/sys/time.h index a28472f842..28b8a242dd 100644 --- a/Libraries/LibC/sys/time.h +++ b/Libraries/LibC/sys/time.h @@ -5,6 +5,29 @@ __BEGIN_DECLS +#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? ((tvp)->tv_usec cmp(uvp)->tv_usec) : ((tvp)->tv_sec cmp(uvp)->tv_sec)) +#define timeradd(tvp, uvp) \ + do { \ + (tvp)->tv_sec += (uvp)->tv_sec; \ + (tvp)->tv_usec += (uvp)->tv_usec; \ + if ((tvp)->tv_usec >= 1000000) { \ + (tvp)->tv_sec++; \ + (tvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#define timersub(tvp, uvp) \ + do { \ + (tvp)->tv_sec -= (uvp)->tv_sec; \ + (tvp)->tv_usec -= (uvp)->tv_usec; \ + if ((tvp)->tv_usec < 0) { \ + (tvp)->tv_sec--; \ + (tvp)->tv_usec += 1000000; \ + } \ + } while (0) + struct timeval { time_t tv_sec; suseconds_t tv_usec;