cc-compat.h 2.47 KB
Newer Older
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
Vicent Marti committed
3 4 5
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
6
 */
7 8
#ifndef INCLUDE_cc_compat_h__
#define INCLUDE_cc_compat_h__
9

10 11
#include <stdarg.h>

12 13 14
/*
 * See if our compiler is known to support flexible array members.
 */
15
#ifndef GIT_FLEX_ARRAY
16 17 18 19 20 21 22 23
#	if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#		define GIT_FLEX_ARRAY /* empty */
#	elif defined(__GNUC__)
#		if (__GNUC__ >= 3)
#			define GIT_FLEX_ARRAY /* empty */
#		else
#			define GIT_FLEX_ARRAY 0 /* older GNU extension */
#		endif
Vicent Marti committed
24
#	endif
25 26

/* Default to safer but a bit wasteful traditional style */
27 28 29
#	ifndef GIT_FLEX_ARRAY
#		define GIT_FLEX_ARRAY 1
#	endif
30 31
#endif

Jacques Germishuys committed
32 33 34 35 36 37 38 39
#if defined(__GNUC__)
#	define GIT_ALIGN(x,size) x __attribute__ ((aligned(size)))
#elif defined(_MSC_VER)
#	define GIT_ALIGN(x,size) __declspec(align(size)) x
#else
#	define GIT_ALIGN(x,size) x
#endif

40
#if defined(__GNUC__)
lhchavez committed
41 42
# define GIT_UNUSED(x)                                                         \
	do {                                                                   \
43
		__typeof__(x) _unused __attribute__((unused));                 \
lhchavez committed
44
		_unused = (x);                                                 \
45 46 47 48
	} while (0)
#else
# define GIT_UNUSED(x) ((void)(x))
#endif
49

Aaron Franke committed
50
/* Define the printf format specifier to use for size_t output */
51
#if defined(_MSC_VER) || defined(__MINGW32__)
52

53 54 55 56 57
/* Visual Studio 2012 and prior lack PRId64 entirely */
#	ifndef PRId64
#		define PRId64 "I64d"
#	endif

58
/* The first block is needed to avoid warnings on MingW amd64 */
59 60 61
#	if (SIZE_MAX == ULLONG_MAX)
#		define PRIuZ "I64u"
#		define PRIxZ "I64x"
lhchavez committed
62
#		define PRIXZ "I64X"
63 64 65 66
#		define PRIdZ "I64d"
#	else
#		define PRIuZ "Iu"
#		define PRIxZ "Ix"
lhchavez committed
67
#		define PRIXZ "IX"
68 69 70
#		define PRIdZ "Id"
#	endif

71
#else
72
#	define PRIuZ "zu"
73
#	define PRIxZ "zx"
lhchavez committed
74
#	define PRIXZ "zX"
75
#	define PRIdZ "zd"
76 77
#endif

Dimitris Apostolou committed
78
/* Microsoft Visual C/C++ */
79 80
#if defined(_MSC_VER)
/* disable "deprecated function" warnings */
81
#	pragma warning ( disable : 4996 )
82
/* disable "conditional expression is constant" level 4 warnings */
83
#	pragma warning ( disable : 4127 )
84 85
#endif

86 87
#if defined (_MSC_VER)
	typedef unsigned char bool;
88 89 90 91 92 93
#	ifndef true
#		define true 1
#	endif
#	ifndef false
#		define false 0
#	endif
94 95 96 97
#else
#	include <stdbool.h>
#endif

98 99 100 101 102 103 104 105
#ifndef va_copy
#	ifdef __va_copy
#		define va_copy(dst, src) __va_copy(dst, src)
#	else
#		define va_copy(dst, src) ((dst) = (src))
#	endif
#endif

106
#endif