Luna/libc/include/bits/timespec.h

40 lines
1.6 KiB
C

/* bits/timespec.h: The timespec and timeval structures. */
#ifndef _BITS_TIMESPEC_H
#define _BITS_TIMESPEC_H
#include <sys/types.h>
struct timespec
{
time_t tv_sec;
long tv_nsec;
};
struct timeval
{
time_t tv_sec;
suseconds_t tv_usec;
};
#endif
#if defined(IN_MOON) || defined(_INCLUDE_TIMESPEC_MACROS)
#ifndef _TIMESPEC_MACROS_INCLUDED
#define _TIMESPEC_MACROS_INCLUDED
#define timespecadd(a, b, res) \
do { \
(res)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(res)->tv_nsec = (a)->tv_nsec + (b)->tv_nsec; \
while ((res)->tv_nsec >= 1'000'000'000) \
{ \
(res)->tv_sec++; \
(res)->tv_nsec -= 1'000'000'000; \
} \
} while (0);
#endif
#define TIMEVAL_TO_TIMESPEC(x) { .tv_sec = (x).tv_sec, .tv_nsec = (x).tv_usec * 1000 }
#define TIMESPEC_TO_TIMEVAL(x) { .tv_sec = (x).tv_sec, .tv_usec = (x).tv_nsec / 1000 }
#endif