Provide for a network initialization step
[disorder] / lib / common.h
CommitLineData
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
aa846a75
RK
29# define SOCKET int
30# define INVALID_SOCKET (-1)
31# define declspec(x)
32# define socket_error() (errno)
33# define system_error() (errno)
3544c8e7
RK
34# define network_init()
35
460b9539 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>
05b75f8d
RK
44#include <string.h>
45#include <stdio.h>
46#include <assert.h>
460b9539 47
48#if HAVE_LONG_LONG
49typedef long long long_long;
50typedef unsigned long long u_long_long;
51# if ! DECLARES_STRTOLL
52long long strtoll(const char *, char **, int);
53# endif
54# if ! DECLARES_ATOLL
55long long atoll(const char *);
56# endif
57#else
58typedef long long_long;
59typedef 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
76typedef long long intmax_t;
77# define PRIdMAX "lld"
78#else
79typedef 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
91typedef unsigned long long uintmax_t;
92# define PRIuMAX "llu"
93# define PRIxMAX "llx"
94#else
95typedef 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
102typedef 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
110typedef unsigned int uint32_t;
111# elif ULONG_MAX == 4294967295
112typedef unsigned long uint32_t;
113# elif USHRT_MAX == 4294967295
114typedef unsigned short uint32_t;
115# elif UCHAR_MAX == 4294967295
116typedef unsigned char uint32_t;
117# else
118# error cannot determine uint32_t
119# endif
120#endif
121
0b29fd3d
RK
122#if ! HAVE_UINT16_T
123# if USHRT_MAX == 65535
124typedef unsigned short uint16_t;
125# else
126# error cannot determine uint16_t
127# endif
128#endif
129
aa846a75
RK
130#if !HAVE_CLOSESOCKET
131# define closesocket close
132#endif
133
05b75f8d 134#endif /* COMMENT_H */
460b9539 135
136/*
137Local Variables:
138c-basic-offset:2
139comment-column:40
140End:
141*/