NetSurf
sys_time.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * BSD style timeval macros
22 *
23 * BSD added macros for manipulating timeval which have become standard on
24 * modern c libraries but for compatability where they are missing it is
25 * necessary to provide fallbacks.
26 */
27
28#ifndef NETSURF_UTILS_SYS_TIME_H_
29#define NETSURF_UTILS_SYS_TIME_H_
30
31#include <sys/time.h>
32
33#ifndef timerclear
34#define timerclear(a) ((a)->tv_sec = (a)->tv_usec = 0)
35#endif
36
37#ifndef timerisset
38#define timerisset(a) ((a)->tv_sec || (a)->tv_usec)
39#endif
40
41#ifndef timeradd
42#define timeradd(a, aa, result) \
43 do { \
44 (result)->tv_sec = (a)->tv_sec + (aa)->tv_sec; \
45 (result)->tv_usec = (a)->tv_usec + (aa)->tv_usec; \
46 if ((result)->tv_usec >= 1000000) { \
47 ++(result)->tv_sec; \
48 (result)->tv_usec -= 1000000; \
49 } \
50 } while (0)
51#endif
52
53#ifndef timersub
54#define timersub(a, aa, result) \
55 do { \
56 (result)->tv_sec = (a)->tv_sec - (aa)->tv_sec; \
57 (result)->tv_usec = (a)->tv_usec - (aa)->tv_usec; \
58 if ((result)->tv_usec < 0) { \
59 --(result)->tv_sec; \
60 (result)->tv_usec += 1000000; \
61 } \
62 } while (0)
63#endif
64
65#ifndef timercmp
66#define timercmp(a, aa, cmp) \
67 (((a)->tv_sec cmp (aa)->tv_sec) || \
68 ((a)->tv_sec == (aa)->tv_sec && (a)->tv_usec cmp (aa)->tv_usec))
69#endif
70
71#endif