LibC: Add timer{add,sub,clear,isset,cmp}

These are not POSIX but used by used by some ports
This commit is contained in:
Bananymous 2025-05-27 07:10:30 +03:00
parent 89c9bfd052
commit c7be3dcd5b
1 changed files with 30 additions and 0 deletions

View File

@ -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