mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
Introduce GNU/BSD timeval macros
This commit is contained in:
parent
2af7c802b6
commit
a1e1e821cb
1 changed files with 23 additions and 0 deletions
|
@ -47,6 +47,29 @@ static inline bool timeval_isvalid(struct timeval __tv) {
|
|||
}
|
||||
#endif /* _COSMO_SOURCE */
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
#define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
|
||||
#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
|
||||
#define timercmp(s, t, op) \
|
||||
((s)->tv_sec == (t)->tv_sec ? (s)->tv_usec op(t)->tv_usec \
|
||||
: (s)->tv_sec op(t)->tv_sec)
|
||||
#define timeradd(s, t, a) \
|
||||
(void)((a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \
|
||||
((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
|
||||
((a)->tv_usec -= 1000000, (a)->tv_sec++))
|
||||
#define timersub(s, t, a) \
|
||||
(void)((a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \
|
||||
((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
|
||||
((a)->tv_usec += 1000000, (a)->tv_sec--))
|
||||
#endif
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
#define TIMEVAL_TO_TIMESPEC(tv, ts) \
|
||||
((ts)->tv_sec = (tv)->tv_sec, (ts)->tv_nsec = (tv)->tv_usec * 1000, (void)0)
|
||||
#define TIMESPEC_TO_TIMEVAL(tv, ts) \
|
||||
((tv)->tv_sec = (ts)->tv_sec, (tv)->tv_usec = (ts)->tv_nsec / 1000, (void)0)
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_ */
|
||||
|
|
Loading…
Add table
Reference in a new issue