]> git.proxmox.com Git - libgit2.git/blame - src/cc-compat.h
New upstream version 1.3.0+dfsg.1
[libgit2.git] / src / cc-compat.h
CommitLineData
f501265f 1/*
359fc2d2 2 * Copyright (C) the libgit2 contributors. All rights reserved.
bb742ede
VM
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
f501265f 6 */
eae0bfdc
PP
7#ifndef INCLUDE_cc_compat_h__
8#define INCLUDE_cc_compat_h__
f501265f 9
ab0af298
ET
10#include <stdarg.h>
11
f501265f
AE
12/*
13 * See if our compiler is known to support flexible array members.
14 */
2bf93fa1 15#ifndef GIT_FLEX_ARRAY
c060854e
VM
16# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
17# define GIT_FLEX_ARRAY /* empty */
18# elif defined(__GNUC__)
19# if (__GNUC__ >= 3)
20# define GIT_FLEX_ARRAY /* empty */
21# else
22# define GIT_FLEX_ARRAY 0 /* older GNU extension */
23# endif
87d9869f 24# endif
f501265f
AE
25
26/* Default to safer but a bit wasteful traditional style */
c060854e
VM
27# ifndef GIT_FLEX_ARRAY
28# define GIT_FLEX_ARRAY 1
29# endif
f501265f
AE
30#endif
31
3aaa5c7b
JG
32#if defined(__GNUC__)
33# define GIT_ALIGN(x,size) x __attribute__ ((aligned(size)))
34#elif defined(_MSC_VER)
35# define GIT_ALIGN(x,size) __declspec(align(size)) x
36#else
37# define GIT_ALIGN(x,size) x
38#endif
39
c25aa7cd
PP
40#if defined(__GNUC__)
41# define GIT_UNUSED(x) \
42 do { \
43 __typeof__(x) _unused __attribute__((unused)); \
44 _unused = (x); \
45 } while (0)
46#else
47# define GIT_UNUSED(x) ((void)(x))
48#endif
73dcf287 49
c25aa7cd 50/* Define the printf format specifier to use for size_t output */
a1c0728d 51#if defined(_MSC_VER) || defined(__MINGW32__)
ac3d33df 52
22a2d3d5
UG
53/* Visual Studio 2012 and prior lack PRId64 entirely */
54# ifndef PRId64
55# define PRId64 "I64d"
56# endif
57
ac3d33df
JK
58/* The first block is needed to avoid warnings on MingW amd64 */
59# if (SIZE_MAX == ULLONG_MAX)
60# define PRIuZ "I64u"
61# define PRIxZ "I64x"
62# define PRIXZ "I64X"
63# define PRIdZ "I64d"
64# else
65# define PRIuZ "Iu"
66# define PRIxZ "Ix"
67# define PRIXZ "IX"
68# define PRIdZ "Id"
69# endif
70
a1c0728d 71#else
c060854e 72# define PRIuZ "zu"
47fc2642 73# define PRIxZ "zx"
ac3d33df 74# define PRIXZ "zX"
cf1013a8 75# define PRIdZ "zd"
8a086f87
RJ
76#endif
77
5cae6c25
RJ
78/* Micosoft Visual C/C++ */
79#if defined(_MSC_VER)
80/* disable "deprecated function" warnings */
c060854e 81# pragma warning ( disable : 4996 )
ca3939e6 82/* disable "conditional expression is constant" level 4 warnings */
c060854e 83# pragma warning ( disable : 4127 )
5cae6c25
RJ
84#endif
85
1a481123
VM
86#if defined (_MSC_VER)
87 typedef unsigned char bool;
b6ac07b5
RB
88# ifndef true
89# define true 1
90# endif
91# ifndef false
92# define false 0
93# endif
1a481123
VM
94#else
95# include <stdbool.h>
96#endif
97
1adf8c6a
VM
98#ifndef va_copy
99# ifdef __va_copy
100# define va_copy(dst, src) __va_copy(dst, src)
101# else
102# define va_copy(dst, src) ((dst) = (src))
103# endif
104#endif
105
eae0bfdc 106#endif