From c7be3dcd5bbf1bab69c5be60d28049934e7ea75d Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 27 May 2025 07:10:30 +0300 Subject: [PATCH] LibC: Add timer{add,sub,clear,isset,cmp} These are not POSIX but used by used by some ports --- userspace/libraries/LibC/include/sys/time.h | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/userspace/libraries/LibC/include/sys/time.h b/userspace/libraries/LibC/include/sys/time.h index 8deb916e..458bde62 100644 --- a/userspace/libraries/LibC/include/sys/time.h +++ b/userspace/libraries/LibC/include/sys/time.h @@ -33,6 +33,36 @@ int gettimeofday(struct timeval* __restrict tp, void* __restrict tzp); int setitimer(int which, const struct itimerval* __restrict value, struct itimerval* __restrict ovalue); int utimes(const char* path, const struct timeval times[2]); +#define timeradd(a, b, res) \ + do { \ + (res)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ + (res)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ + (res)->tv_sec += (res)->tv_usec / 1000000; \ + (res)->tv_usec %= 1000000; \ + } while (0) + +#define timersub(a, b, res) \ + do { \ + (res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + (res)->tv_sec += (res)->tv_usec / 1000000; \ + (res)->tv_usec %= 1000000; \ + } while (0) + +#define timerclear(tvp) \ + do { \ + (tvp)->tv_sec = 0; \ + (tvp)->tv_usec = 0; \ + } while (0) + +#define timerisset(tvp) \ + ((tvp)->tv_sec || (tvp)->tv_usec) + +#define timercmp(a, b, CMP) \ + (((a)->tv_sec == (b)->tv_sec) \ + ? ((a)->tv_usec CMP (b)->tv_usec) \ + : ((a)->tv_sec CMP (b)->tv_sec)) + __END_DECLS #endif