Path: blob/main/contrib/libfido2/openbsd-compat/time.h
39536 views
/*1* Public domain2* sys/time.h compatibility shim3*/45#if defined(_MSC_VER) && (_MSC_VER >= 1900)6#include <../ucrt/time.h>7#elif defined(_MSC_VER) && (_MSC_VER < 1900)8#include <../include/time.h>9#else10#include <time.h>11#endif1213#ifndef _COMPAT_TIME_H14#define _COMPAT_TIME_H1516#ifndef CLOCK_MONOTONIC17#define CLOCK_MONOTONIC CLOCK_REALTIME18#endif1920#ifndef CLOCK_REALTIME21#define CLOCK_REALTIME 022#endif2324#ifndef HAVE_CLOCK_GETTIME25typedef int clockid_t;26int clock_gettime(clockid_t, struct timespec *);27#endif2829#ifdef HAVE_TIMESPECSUB30#include <sys/time.h>31#endif3233#ifndef HAVE_TIMESPECSUB34#define timespecadd(tsp, usp, vsp) \35do { \36(vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \37(vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \38if ((vsp)->tv_nsec >= 1000000000L) { \39(vsp)->tv_sec++; \40(vsp)->tv_nsec -= 1000000000L; \41} \42} while (0)4344#define timespecsub(tsp, usp, vsp) \45do { \46(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \47(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \48if ((vsp)->tv_nsec < 0) { \49(vsp)->tv_sec--; \50(vsp)->tv_nsec += 1000000000L; \51} \52} while (0)5354#define timespeccmp(tsp, usp, cmp) \55(((tsp)->tv_sec == (usp)->tv_sec) ? \56((tsp)->tv_nsec cmp (usp)->tv_nsec) : \57((tsp)->tv_sec cmp (usp)->tv_sec))58#endif5960#endif /* _COMPAT_TIME_H */616263