cc-compat.h 1.88 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 32
#endif

#ifdef __GNUC__
33
#	define GIT_TYPEOF(x) (__typeof__(x))
34
#else
35
#	define GIT_TYPEOF(x)
36 37
#endif

Jacques Germishuys committed
38 39 40 41 42 43 44 45
#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

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
#	define PRIuZ "Iu"
51
#	define PRIxZ "Ix"
52
#	define PRIdZ "Id"
53
#else
54
#	define PRIuZ "zu"
55
#	define PRIxZ "zx"
56
#	define PRIdZ "zd"
57 58
#endif

59 60 61
/* Micosoft Visual C/C++ */
#if defined(_MSC_VER)
/* disable "deprecated function" warnings */
62
#	pragma warning ( disable : 4996 )
63
/* disable "conditional expression is constant" level 4 warnings */
64
#	pragma warning ( disable : 4127 )
65 66
#endif

67 68
#if defined (_MSC_VER)
	typedef unsigned char bool;
69 70 71 72 73 74
#	ifndef true
#		define true 1
#	endif
#	ifndef false
#		define false 0
#	endif
75 76 77 78
#else
#	include <stdbool.h>
#endif

79 80 81 82 83 84 85 86
#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

87
#endif