chiark / gitweb /
Shun time(), since on Linux it is not monotonic with gettimeofday().
[disorder] / lib / common.h
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program 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 /** @file lib/common.h
19  * @brief Common includes and definitions
20  */
21
22 #ifndef COMMON_H
23 #define COMMON_H
24
25 #include <config.h>
26
27 #if HAVE_INTTYPES_H
28 # include <inttypes.h>
29 #endif
30 #include <limits.h>
31 #include <sys/types.h>
32
33 /* had better be before atol/atoll redefinition */
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdio.h>
37 #include <assert.h>
38
39 #if HAVE_LONG_LONG
40 typedef long long long_long;
41 typedef unsigned long long u_long_long;
42 # if ! DECLARES_STRTOLL
43 long long strtoll(const char *, char **, int);
44 # endif
45 # if ! DECLARES_ATOLL
46 long long atoll(const char *);
47 # endif
48 #else
49 typedef long long_long;
50 typedef unsigned long u_long_long;
51 # define atoll atol
52 # define strtoll strtol
53 #endif
54
55 #if __APPLE__
56 /* apple define these to j[dxu], which gcc -std=c99 -pedantic then rejects */
57 # undef PRIdMAX
58 # undef PRIxMAX
59 # undef PRIuMAX
60 #endif
61
62 #if HAVE_INTMAX_T
63 # ifndef PRIdMAX
64 #  define PRIdMAX "jd"
65 # endif
66 #elif HAVE_LONG_LONG
67 typedef long long intmax_t;
68 # define PRIdMAX "lld"
69 #else
70 typedef long intmax_t;
71 # define PRIdMAX "ld"
72 #endif
73
74 #if HAVE_UINTMAX_T
75 # ifndef PRIuMAX
76 #  define PRIuMAX "ju"
77 # endif
78 # ifndef PRIxMAX
79 #  define PRIxMAX "jx"
80 # endif
81 #elif HAVE_LONG_LONG
82 typedef unsigned long long uintmax_t;
83 # define PRIuMAX "llu"
84 # define PRIxMAX "llx"
85 #else
86 typedef unsigned long uintmax_t;
87 # define PRIuMAX "lu"
88 # define PRIxMAX "lx"
89 #endif
90
91 #if ! HAVE_UINT8_T
92 # if CHAR_BIT == 8
93 typedef unsigned char uint8_t;
94 # else
95 #  error cannot determine uint8_t
96 # endif
97 #endif
98
99 #if ! HAVE_UINT32_T
100 # if UINT_MAX == 4294967295
101 typedef unsigned int uint32_t;
102 # elif ULONG_MAX == 4294967295
103 typedef unsigned long uint32_t;
104 # elif USHRT_MAX == 4294967295
105 typedef unsigned short uint32_t;
106 # elif UCHAR_MAX == 4294967295
107 typedef unsigned char uint32_t;
108 # else
109 #  error cannot determine uint32_t
110 # endif
111 #endif
112
113 #endif /* COMMENT_H */
114
115 /*
116 Local Variables:
117 c-basic-offset:2
118 comment-column:40
119 End:
120 */