]> git.proxmox.com Git - libgit2.git/blob - src/cc-compat.h
install as examples
[libgit2.git] / src / cc-compat.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
6 */
7 #ifndef INCLUDE_cc_compat_h__
8 #define INCLUDE_cc_compat_h__
9
10 #include <stdarg.h>
11
12 /*
13 * See if our compiler is known to support flexible array members.
14 */
15 #ifndef GIT_FLEX_ARRAY
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
24 # endif
25
26 /* Default to safer but a bit wasteful traditional style */
27 # ifndef GIT_FLEX_ARRAY
28 # define GIT_FLEX_ARRAY 1
29 # endif
30 #endif
31
32 #ifdef __GNUC__
33 # define GIT_TYPEOF(x) (__typeof__(x))
34 #else
35 # define GIT_TYPEOF(x)
36 #endif
37
38 #if defined(__GNUC__)
39 # define GIT_ALIGN(x,size) x __attribute__ ((aligned(size)))
40 #elif defined(_MSC_VER)
41 # define GIT_ALIGN(x,size) __declspec(align(size)) x
42 #else
43 # define GIT_ALIGN(x,size) x
44 #endif
45
46 #define GIT_UNUSED(x) ((void)(x))
47
48 /* Define the printf format specifer to use for size_t output */
49 #if defined(_MSC_VER) || defined(__MINGW32__)
50
51 /* Visual Studio 2012 and prior lack PRId64 entirely */
52 # ifndef PRId64
53 # define PRId64 "I64d"
54 # endif
55
56 /* The first block is needed to avoid warnings on MingW amd64 */
57 # if (SIZE_MAX == ULLONG_MAX)
58 # define PRIuZ "I64u"
59 # define PRIxZ "I64x"
60 # define PRIXZ "I64X"
61 # define PRIdZ "I64d"
62 # else
63 # define PRIuZ "Iu"
64 # define PRIxZ "Ix"
65 # define PRIXZ "IX"
66 # define PRIdZ "Id"
67 # endif
68
69 #else
70 # define PRIuZ "zu"
71 # define PRIxZ "zx"
72 # define PRIXZ "zX"
73 # define PRIdZ "zd"
74 #endif
75
76 /* Micosoft Visual C/C++ */
77 #if defined(_MSC_VER)
78 /* disable "deprecated function" warnings */
79 # pragma warning ( disable : 4996 )
80 /* disable "conditional expression is constant" level 4 warnings */
81 # pragma warning ( disable : 4127 )
82 #endif
83
84 #if defined (_MSC_VER)
85 typedef unsigned char bool;
86 # ifndef true
87 # define true 1
88 # endif
89 # ifndef false
90 # define false 0
91 # endif
92 #else
93 # include <stdbool.h>
94 #endif
95
96 #ifndef va_copy
97 # ifdef __va_copy
98 # define va_copy(dst, src) __va_copy(dst, src)
99 # else
100 # define va_copy(dst, src) ((dst) = (src))
101 # endif
102 #endif
103
104 #endif