Initial import
[olsrd.git] / src / win32 / sys / time.h
1 /*
2  * Functions for the Windows port
3  * Copyright (C) 2004 Thomas Lopatic (thomas@lopatic.de)
4  *
5  * This file is part of olsrd-unik.
6  *
7  * olsrd-unik is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * olsrd-unik is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with olsrd-unik; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #if !defined TL_SYS_TIME_H_INCLUDED
24
25 #define TL_SYS_TIME_H_INCLUDED
26
27 #define WIN32_LEAN_AND_MEAN
28 #include <winsock2.h>
29 #include <ws2tcpip.h>
30 #undef interface
31
32 #define timeradd(x, y, z)                       \
33   do                                            \
34   {                                             \
35     (z)->tv_sec = (x)->tv_sec + (y)->tv_sec;    \
36                                                 \
37     (z)->tv_usec = (x)->tv_usec + (y)->tv_usec; \
38                                                 \
39     if ((z)->tv_usec >= 1000000)                \
40     {                                           \
41       (z)->tv_sec++;                            \
42       (z)->tv_usec -= 1000000;                  \
43     }                                           \
44   }                                             \
45   while (0)
46
47 #define timersub(x, y, z)                       \
48   do                                            \
49   {                                             \
50     (z)->tv_sec = (x)->tv_sec - (y)->tv_sec;    \
51                                                 \
52     (z)->tv_usec = (x)->tv_usec - (y)->tv_usec; \
53                                                 \
54     if ((z)->tv_usec < 0)                       \
55     {                                           \
56       (z)->tv_sec--;                            \
57       (z)->tv_usec += 1000000;                  \
58     }                                           \
59   }                                             \
60   while (0)
61
62 struct timespec
63 {
64   unsigned int tv_sec;
65   unsigned int tv_nsec;
66 };
67
68 int nanosleep(struct timespec *Req, struct timespec *Rem);
69 void gettimeofday(struct timeval *TVal, void *TZone);
70
71 #endif