mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibC: Add timeval operations
This commit add macros for the timeval operations timeradd, timersub, timercmp, timerisset, timerclear.
This commit is contained in:
parent
4d997308c2
commit
0e49c842de
Notes:
sideshowbarker
2024-07-19 10:36:29 +09:00
Author: https://github.com/mauri870 Commit: https://github.com/SerenityOS/serenity/commit/0e49c842de6 Pull-request: https://github.com/SerenityOS/serenity/pull/926
1 changed files with 23 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue