Commit | Line | Data |
---|---|---|
460b9539 | 1 | /* |
2 | * This file is part of DisOrder. | |
cca89d7c | 3 | * Copyright (C) 2004, 2005, 2007, 2008, 2013 Richard Kettlewell |
460b9539 | 4 | * |
e7eb3a27 | 5 | * This program is free software: you can redistribute it and/or modify |
460b9539 | 6 | * it under the terms of the GNU General Public License as published by |
e7eb3a27 | 7 | * the Free Software Foundation, either version 3 of the License, or |
460b9539 | 8 | * (at your option) any later version. |
e7eb3a27 RK |
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 | * | |
460b9539 | 15 | * You should have received a copy of the GNU General Public License |
e7eb3a27 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
460b9539 | 17 | */ |
05b75f8d RK |
18 | /** @file lib/common.h |
19 | * @brief Common includes and definitions | |
20 | */ | |
21 | ||
22 | #ifndef COMMON_H | |
23 | #define COMMON_H | |
460b9539 | 24 | |
cca89d7c RK |
25 | #if HAVE_CONFIG_H |
26 | # include <config.h> | |
27 | #endif | |
460b9539 | 28 | |
9e42afcd RK |
29 | #if _WIN32 |
30 | # include "disorder-win32.h" | |
31 | #else | |
aa846a75 RK |
32 | # define SOCKET int |
33 | # define INVALID_SOCKET (-1) | |
34 | # define declspec(x) | |
35 | # define socket_error() (errno) | |
36 | # define system_error() (errno) | |
3544c8e7 | 37 | # define network_init() |
9e42afcd | 38 | #endif |
3544c8e7 | 39 | |
460b9539 | 40 | #if HAVE_INTTYPES_H |
41 | # include <inttypes.h> | |
42 | #endif | |
43 | #include <limits.h> | |
44 | #include <sys/types.h> | |
45 | ||
46 | /* had better be before atol/atoll redefinition */ | |
47 | #include <stdlib.h> | |
05b75f8d RK |
48 | #include <string.h> |
49 | #include <stdio.h> | |
50 | #include <assert.h> | |
460b9539 | 51 | |
52 | #if HAVE_LONG_LONG | |
53 | typedef long long long_long; | |
54 | typedef unsigned long long u_long_long; | |
55 | # if ! DECLARES_STRTOLL | |
56 | long long strtoll(const char *, char **, int); | |
57 | # endif | |
58 | # if ! DECLARES_ATOLL | |
59 | long long atoll(const char *); | |
60 | # endif | |
61 | #else | |
62 | typedef long long_long; | |
63 | typedef unsigned long u_long_long; | |
64 | # define atoll atol | |
65 | # define strtoll strtol | |
66 | #endif | |
67 | ||
68 | #if __APPLE__ | |
69 | /* apple define these to j[dxu], which gcc -std=c99 -pedantic then rejects */ | |
70 | # undef PRIdMAX | |
71 | # undef PRIxMAX | |
72 | # undef PRIuMAX | |
73 | #endif | |
74 | ||
75 | #if HAVE_INTMAX_T | |
76 | # ifndef PRIdMAX | |
77 | # define PRIdMAX "jd" | |
78 | # endif | |
79 | #elif HAVE_LONG_LONG | |
80 | typedef long long intmax_t; | |
81 | # define PRIdMAX "lld" | |
82 | #else | |
83 | typedef long intmax_t; | |
84 | # define PRIdMAX "ld" | |
85 | #endif | |
86 | ||
87 | #if HAVE_UINTMAX_T | |
88 | # ifndef PRIuMAX | |
89 | # define PRIuMAX "ju" | |
90 | # endif | |
91 | # ifndef PRIxMAX | |
92 | # define PRIxMAX "jx" | |
93 | # endif | |
94 | #elif HAVE_LONG_LONG | |
95 | typedef unsigned long long uintmax_t; | |
96 | # define PRIuMAX "llu" | |
97 | # define PRIxMAX "llx" | |
98 | #else | |
99 | typedef unsigned long uintmax_t; | |
100 | # define PRIuMAX "lu" | |
101 | # define PRIxMAX "lx" | |
102 | #endif | |
103 | ||
104 | #if ! HAVE_UINT8_T | |
105 | # if CHAR_BIT == 8 | |
106 | typedef unsigned char uint8_t; | |
107 | # else | |
108 | # error cannot determine uint8_t | |
109 | # endif | |
110 | #endif | |
111 | ||
112 | #if ! HAVE_UINT32_T | |
113 | # if UINT_MAX == 4294967295 | |
114 | typedef unsigned int uint32_t; | |
115 | # elif ULONG_MAX == 4294967295 | |
116 | typedef unsigned long uint32_t; | |
117 | # elif USHRT_MAX == 4294967295 | |
118 | typedef unsigned short uint32_t; | |
119 | # elif UCHAR_MAX == 4294967295 | |
120 | typedef unsigned char uint32_t; | |
121 | # else | |
122 | # error cannot determine uint32_t | |
123 | # endif | |
124 | #endif | |
125 | ||
0b29fd3d RK |
126 | #if ! HAVE_UINT16_T |
127 | # if USHRT_MAX == 65535 | |
128 | typedef unsigned short uint16_t; | |
129 | # else | |
130 | # error cannot determine uint16_t | |
131 | # endif | |
132 | #endif | |
133 | ||
aa846a75 RK |
134 | #if !HAVE_CLOSESOCKET |
135 | # define closesocket close | |
136 | #endif | |
137 | ||
05b75f8d | 138 | #endif /* COMMENT_H */ |
460b9539 | 139 | |
140 | /* | |
141 | Local Variables: | |
142 | c-basic-offset:2 | |
143 | comment-column:40 | |
144 | End: | |
145 | */ |