1 /* 2 * Public domain 3 * sys/time.h compatibility shim 4 */ 5 module libressl_d.compat.time; 6 7 8 public import core.stdc.time; 9 public import core.sys.posix.time; 10 public import libressl_d.compat.sys.time; 11 12 extern (C): 13 nothrow @nogc: 14 15 version (Windows) { 16 core.stdc.time.tm* __gmtime_r(const (core.stdc.time.time_t)* t, core.stdc.time.tm* tm); 17 alias gmtime_r = .__gmtime_r; 18 } 19 20 static if (!__traits(compiles, timegm)) { 21 core.stdc.time.time_t timegm(core.stdc.time.tm* tm); 22 } 23 24 static if (!__traits(compiles, CLOCK_REALTIME)) { 25 enum CLOCK_REALTIME = 0; 26 } 27 28 static if (!__traits(compiles, CLOCK_MONOTONIC)) { 29 alias CLOCK_MONOTONIC = .CLOCK_REALTIME; 30 } 31 32 version (Posix) { 33 static if (!__traits(compiles, clock_gettime)) { 34 alias clockid_t = int; 35 int clock_gettime(.clockid_t clock_id, libressl_d.compat.sys.time.timespec* tp); 36 } 37 38 //#if defined(timespecsub) 39 //version = HAVE_TIMESPECSUB; 40 //#endif 41 42 //#if !defined(HAVE_TIMESPECSUB) 43 static if (!__traits(compiles, timespecsub)) { 44 pragma(inline, true) 45 pure nothrow @trusted @nogc @live 46 void timespecsub(scope const libressl_d.compat.sys.time.timespec* tsp, scope const libressl_d.compat.sys.time.timespec* usp, scope libressl_d.compat.sys.time.timespec* vsp) 47 48 in 49 { 50 assert(tsp != null); 51 assert(usp != null); 52 assert(vsp != null); 53 } 54 55 do 56 { 57 vsp.tv_sec = tsp.tv_sec - usp.tv_sec; 58 vsp.tv_nsec = tsp.tv_nsec - usp.tv_nsec; 59 60 if (vsp.tv_nsec < 0) { 61 vsp.tv_sec--; 62 vsp.tv_nsec += 1000000000L; 63 } 64 } 65 } 66 }