1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Copyright Sociomantic Labs GmbH.
5  * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6  * Authors:   Leandro Lucarella
7  */
8 
9 /*          Copyright Sociomantic Labs GmbH.
10  * Distributed under the Boost Software License, Version 1.0.
11  *    (See accompanying file LICENSE or copy at
12  *          http://www.boost.org/LICENSE_1_0.txt)
13  */
14 module core.sys.linux.sys.time;
15 
16 import core.sys.linux.config;
17 public import core.sys.posix.sys.time;  // timeval
18 
19 version (linux):
20 
21 /* macros provided to operate on timeval structures
22  * they are extern(D) because they are not really C symbols, just macros
23  */
24 extern (D) pure @safe @nogc nothrow {
25 
26     void timeradd(const timeval* a, const timeval* b,
27             timeval* result)
28     {
29         result.tv_sec = a.tv_sec + b.tv_sec;
30         result.tv_usec = a.tv_usec + b.tv_usec;
31         if (result.tv_usec >= 1_000_000)
32         {
33             ++result.tv_sec;
34             result.tv_usec -= 1_000_000;
35         }
36     }
37 
38     void timersub(const timeval* a, const timeval* b,
39             timeval *result)
40     {
41         result.tv_sec = a.tv_sec - b.tv_sec;
42         result.tv_usec = a.tv_usec - b.tv_usec;
43         if (result.tv_usec < 0) {
44             --result.tv_sec;
45             result.tv_usec += 1_000_000;
46         }
47     }
48 
49     void timerclear(timeval* tvp)
50     {
51         (tvp.tv_sec = tvp.tv_usec = 0);
52     }
53 
54     int timerisset(timeval* tvp)
55     {
56         return cast(int) (tvp.tv_sec || tvp.tv_usec);
57     }
58 
59     int timercmp(string CMP)(const timeval* a, const timeval* b)
60     {
61         return cast(int)
62                mixin("((a.tv_sec == b.tv_sec) ?" ~
63                      "(a.tv_usec" ~ CMP ~ "b.tv_usec) :" ~
64                      "(a.tv_sec"  ~ CMP ~ "b.tv_sec))");
65     }
66 
67 }