chiark / gitweb /
Provide for a network initialization step
[disorder] / lib / common.h
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2004, 2005, 2007, 2008, 2013 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 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28
29 # define SOCKET int
30 # define INVALID_SOCKET (-1)
31 # define declspec(x)
32 # define socket_error() (errno)
33 # define system_error() (errno)
34 # define network_init()
35
36 #if HAVE_INTTYPES_H
37 # include <inttypes.h>
38 #endif
39 #include <limits.h>
40 #include <sys/types.h>
41
42 /* had better be before atol/atoll redefinition */
43 #include <stdlib.h>
44 #include <string.h>
45 #include <stdio.h>
46 #include <assert.h>
47
48 #if HAVE_LONG_LONG
49 typedef long long long_long;
50 typedef unsigned long long u_long_long;
51 # if ! DECLARES_STRTOLL
52 long long strtoll(const char *, char **, int);
53 # endif
54 # if ! DECLARES_ATOLL
55 long long atoll(const char *);
56 # endif
57 #else
58 typedef long long_long;
59 typedef unsigned long u_long_long;
60 # define atoll atol
61 # define strtoll strtol
62 #endif
63
64 #if __APPLE__
65 /* apple define these to j[dxu], which gcc -std=c99 -pedantic then rejects */
66 # undef PRIdMAX
67 # undef PRIxMAX
68 # undef PRIuMAX
69 #endif
70
71 #if HAVE_INTMAX_T
72 # ifndef PRIdMAX
73 #  define PRIdMAX "jd"
74 # endif
75 #elif HAVE_LONG_LONG
76 typedef long long intmax_t;
77 # define PRIdMAX "lld"
78 #else
79 typedef long intmax_t;
80 # define PRIdMAX "ld"
81 #endif
82
83 #if HAVE_UINTMAX_T
84 # ifndef PRIuMAX
85 #  define PRIuMAX "ju"
86 # endif
87 # ifndef PRIxMAX
88 #  define PRIxMAX "jx"
89 # endif
90 #elif HAVE_LONG_LONG
91 typedef unsigned long long uintmax_t;
92 # define PRIuMAX "llu"
93 # define PRIxMAX "llx"
94 #else
95 typedef unsigned long uintmax_t;
96 # define PRIuMAX "lu"
97 # define PRIxMAX "lx"
98 #endif
99
100 #if ! HAVE_UINT8_T
101 # if CHAR_BIT == 8
102 typedef unsigned char uint8_t;
103 # else
104 #  error cannot determine uint8_t
105 # endif
106 #endif
107
108 #if ! HAVE_UINT32_T
109 # if UINT_MAX == 4294967295
110 typedef unsigned int uint32_t;
111 # elif ULONG_MAX == 4294967295
112 typedef unsigned long uint32_t;
113 # elif USHRT_MAX == 4294967295
114 typedef unsigned short uint32_t;
115 # elif UCHAR_MAX == 4294967295
116 typedef unsigned char uint32_t;
117 # else
118 #  error cannot determine uint32_t
119 # endif
120 #endif
121
122 #if ! HAVE_UINT16_T
123 # if USHRT_MAX == 65535
124 typedef unsigned short uint16_t;
125 # else
126 #  error cannot determine uint16_t
127 # endif
128 #endif
129
130 #if !HAVE_CLOSESOCKET
131 # define closesocket close
132 #endif
133
134 #endif /* COMMENT_H */
135
136 /*
137 Local Variables:
138 c-basic-offset:2
139 comment-column:40
140 End:
141 */