LibC: Add timeval operations

This commit add macros for the timeval operations timeradd, timersub,
timercmp, timerisset, timerclear.
This commit is contained in:
Mauri de Souza Nunes 2019-12-27 00:29:31 -03:00 committed by Andreas Kling
parent 4d997308c2
commit 0e49c842de
Notes: sideshowbarker 2024-07-19 10:36:29 +09:00

View file

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