chiark / gitweb /
Work around buggy FreeBSD strptime()
[disorder] / lib / common.h
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
5aff007d 3 * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
460b9539 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 2 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, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
05b75f8d
RK
20/** @file lib/common.h
21 * @brief Common includes and definitions
22 */
23
24#ifndef COMMON_H
25#define COMMON_H
460b9539 26
05b75f8d 27#include <config.h>
460b9539 28
29#if HAVE_INTTYPES_H
30# include <inttypes.h>
31#endif
32#include <limits.h>
33#include <sys/types.h>
34
35/* had better be before atol/atoll redefinition */
36#include <stdlib.h>
05b75f8d
RK
37#include <string.h>
38#include <stdio.h>
39#include <assert.h>
460b9539 40
41#if HAVE_LONG_LONG
42typedef long long long_long;
43typedef unsigned long long u_long_long;
44# if ! DECLARES_STRTOLL
45long long strtoll(const char *, char **, int);
46# endif
47# if ! DECLARES_ATOLL
48long long atoll(const char *);
49# endif
50#else
51typedef long long_long;
52typedef unsigned long u_long_long;
53# define atoll atol
54# define strtoll strtol
55#endif
56
57#if __APPLE__
58/* apple define these to j[dxu], which gcc -std=c99 -pedantic then rejects */
59# undef PRIdMAX
60# undef PRIxMAX
61# undef PRIuMAX
62#endif
63
64#if HAVE_INTMAX_T
65# ifndef PRIdMAX
66# define PRIdMAX "jd"
67# endif
68#elif HAVE_LONG_LONG
69typedef long long intmax_t;
70# define PRIdMAX "lld"
71#else
72typedef long intmax_t;
73# define PRIdMAX "ld"
74#endif
75
76#if HAVE_UINTMAX_T
77# ifndef PRIuMAX
78# define PRIuMAX "ju"
79# endif
80# ifndef PRIxMAX
81# define PRIxMAX "jx"
82# endif
83#elif HAVE_LONG_LONG
84typedef unsigned long long uintmax_t;
85# define PRIuMAX "llu"
86# define PRIxMAX "llx"
87#else
88typedef unsigned long uintmax_t;
89# define PRIuMAX "lu"
90# define PRIxMAX "lx"
91#endif
92
93#if ! HAVE_UINT8_T
94# if CHAR_BIT == 8
95typedef unsigned char uint8_t;
96# else
97# error cannot determine uint8_t
98# endif
99#endif
100
101#if ! HAVE_UINT32_T
102# if UINT_MAX == 4294967295
103typedef unsigned int uint32_t;
104# elif ULONG_MAX == 4294967295
105typedef unsigned long uint32_t;
106# elif USHRT_MAX == 4294967295
107typedef unsigned short uint32_t;
108# elif UCHAR_MAX == 4294967295
109typedef unsigned char uint32_t;
110# else
111# error cannot determine uint32_t
112# endif
113#endif
114
05b75f8d 115#endif /* COMMENT_H */
460b9539 116
117/*
118Local Variables:
119c-basic-offset:2
120comment-column:40
121End:
122*/