]> git.proxmox.com Git - libgit2.git/blame - src/cc-compat.h
DFSG changes
[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
AE
6 */
7#ifndef INCLUDE_compat_h__
8#define INCLUDE_compat_h__
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
32#ifdef __GNUC__
c060854e 33# define GIT_TYPEOF(x) (__typeof__(x))
f501265f 34#else
c060854e 35# define GIT_TYPEOF(x)
f501265f
AE
36#endif
37
3aaa5c7b
JG
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
854eccbb 46#define GIT_UNUSED(x) ((void)(x))
73dcf287 47
8a086f87 48/* Define the printf format specifer to use for size_t output */
a1c0728d 49#if defined(_MSC_VER) || defined(__MINGW32__)
c060854e 50# define PRIuZ "Iu"
47fc2642 51# define PRIxZ "Ix"
cf1013a8 52# define PRIdZ "Id"
a1c0728d 53#else
c060854e 54# define PRIuZ "zu"
47fc2642 55# define PRIxZ "zx"
cf1013a8 56# define PRIdZ "zd"
8a086f87
RJ
57#endif
58
5cae6c25
RJ
59/* Micosoft Visual C/C++ */
60#if defined(_MSC_VER)
61/* disable "deprecated function" warnings */
c060854e 62# pragma warning ( disable : 4996 )
ca3939e6 63/* disable "conditional expression is constant" level 4 warnings */
c060854e 64# pragma warning ( disable : 4127 )
5cae6c25
RJ
65#endif
66
1a481123
VM
67#if defined (_MSC_VER)
68 typedef unsigned char bool;
b6ac07b5
RB
69# ifndef true
70# define true 1
71# endif
72# ifndef false
73# define false 0
74# endif
1a481123
VM
75#else
76# include <stdbool.h>
77#endif
78
1adf8c6a
VM
79#ifndef va_copy
80# ifdef __va_copy
81# define va_copy(dst, src) __va_copy(dst, src)
82# else
83# define va_copy(dst, src) ((dst) = (src))
84# endif
85#endif
86
f501265f 87#endif /* INCLUDE_compat_h__ */