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 #if defined(__GNUC__) 47 # define GIT_UNUSED(x) \ 48 do { \ 49 typeof(x) _unused __attribute__((unused)); \ 50 _unused = (x); \ 51 } while (0) 52 #else 53 # define GIT_UNUSED(x) ((void)(x)) 54 #endif 55 56 /* Define the printf format specifier to use for size_t output */ 57 #if defined(_MSC_VER) || defined(__MINGW32__) 58 59 /* Visual Studio 2012 and prior lack PRId64 entirely */ 60 # ifndef PRId64 61 # define PRId64 "I64d" 62 # endif 63 64 /* The first block is needed to avoid warnings on MingW amd64 */ 65 # if (SIZE_MAX == ULLONG_MAX) 66 # define PRIuZ "I64u" 67 # define PRIxZ "I64x" 68 # define PRIXZ "I64X" 69 # define PRIdZ "I64d" 70 # else 71 # define PRIuZ "Iu" 72 # define PRIxZ "Ix" 73 # define PRIXZ "IX" 74 # define PRIdZ "Id" 75 # endif 76 77 #else 78 # define PRIuZ "zu" 79 # define PRIxZ "zx" 80 # define PRIXZ "zX" 81 # define PRIdZ "zd" 82 #endif 83 84 /* Micosoft Visual C/C++ */ 85 #if defined(_MSC_VER) 86 /* disable "deprecated function" warnings */ 87 # pragma warning ( disable : 4996 ) 88 /* disable "conditional expression is constant" level 4 warnings */ 89 # pragma warning ( disable : 4127 ) 90 #endif 91 92 #if defined (_MSC_VER) 93 typedef unsigned char bool; 94 # ifndef true 95 # define true 1 96 # endif 97 # ifndef false 98 # define false 0 99 # endif 100 #else 101 # include <stdbool.h> 102 #endif 103 104 #ifndef va_copy 105 # ifdef __va_copy 106 # define va_copy(dst, src) __va_copy(dst, src) 107 # else 108 # define va_copy(dst, src) ((dst) = (src)) 109 # endif 110 #endif 111 112 #endif 113