1 /* 2 * Copyright 2022 Yonggang Luo 3 * SPDX-License-Identifier: MIT 4 * 5 * C11 <time.h> emulation library 6 */ 7 8 #ifndef C11_TIME_H_INCLUDED_ 9 #define C11_TIME_H_INCLUDED_ 10 11 #include <time.h> 12 13 /*---------------------------- macros ---------------------------*/ 14 15 #ifndef TIME_UTC 16 #define TIME_UTC 1 17 #endif 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /*---------------------------- types ----------------------------*/ 24 25 /* 26 * On MINGW `struct timespec` present but `timespec_get` may not present; 27 * On MSVC `struct timespec` and `timespec_get` present at the same time; 28 * So detecting `HAVE_STRUCT_TIMESPEC` in meson script dynamically. 29 */ 30 #ifndef HAVE_STRUCT_TIMESPEC 31 struct timespec 32 { 33 time_t tv_sec; // Seconds - >= 0 34 long tv_nsec; // Nanoseconds - [0, 999999999] 35 }; 36 #endif 37 38 /*-------------------------- functions --------------------------*/ 39 40 #ifndef HAVE_TIMESPEC_GET 41 /*-------------------- 7.25.7 Time functions --------------------*/ 42 // 7.25.6.1 43 int 44 timespec_get(struct timespec *ts, int base); 45 #endif 46 47 #ifdef __cplusplus 48 } 49 #endif 50 51 #endif /* C11_TIME_H_INCLUDED_ */ 52