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