win32: Add support for the MS Visual C/C++ compiler Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
diff --git a/src/cc-compat.h b/src/cc-compat.h
index 32e4139..4141dd8 100644
--- a/src/cc-compat.h
+++ b/src/cc-compat.h
@@ -30,4 +30,28 @@
# define GIT_TYPEOF(x)
#endif
+/*
+ * Does our compiler/platform support the C99 <inttypes.h> and
+ * <stdint.h> header files. (C99 requires that <inttypes.h>
+ * includes <stdint.h>).
+ */
+#if !defined(_MSC_VER)
+# define GIT_HAVE_INTTYPES_H 1
+#endif
+
+/* Define the printf format specifer to use for size_t output */
+#if !defined(_MSC_VER)
+# define PRIuZ "zu"
+#else
+# define PRIuZ "Iu"
+#endif
+
+/* Micosoft Visual C/C++ */
+#if defined(_MSC_VER)
+/* no direct support for C99 inline function specifier */
+# define inline __inline
+/* disable "deprecated function" warnings */
+# pragma warning ( disable : 4996 )
+#endif
+
#endif /* INCLUDE_compat_h__ */
diff --git a/src/common.h b/src/common.h
index 32679a9..d4b9769 100644
--- a/src/common.h
+++ b/src/common.h
@@ -6,11 +6,14 @@
#endif
#include "git/thread-utils.h"
+#include "cc-compat.h"
#ifdef GIT_HAS_PTHREAD
# include <pthread.h>
#endif
-#include <inttypes.h>
+#ifdef GIT_HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
#include <assert.h>
#include <errno.h>
#include <limits.h>
@@ -26,9 +29,21 @@
# include <direct.h>
# include <windows.h>
-#define snprintf _snprintf
+# define snprintf _snprintf
-typedef int ssize_t;
+# if (defined(_MSC_VER) && defined(_WIN64)) || \
+ (defined(__DMC__) && defined(_M_AMD64))
+ typedef long long ssize_t;
+# else
+ typedef int ssize_t;
+# endif
+
+# if defined(_MSC_VER)
+/* access() mode parameter #defines */
+# define F_OK 0 /* existence check */
+# define W_OK 2 /* write mode check */
+# define R_OK 4 /* read mode check */
+# endif
#else
@@ -37,7 +52,6 @@ typedef int ssize_t;
#endif
-#include "cc-compat.h"
#include "git/common.h"
#include "util.h"
#include "thread-utils.h"
@@ -45,4 +59,13 @@ typedef int ssize_t;
#define GIT_PATH_MAX 4096
+#ifndef GIT_HAVE_INTTYPES_H
+/* add some missing <stdint.h> typedef's */
+typedef long int32_t;
+typedef unsigned long uint32_t;
+
+typedef long long int64_t;
+typedef unsigned long long uint64_t;
+#endif
+
#endif /* INCLUDE_common_h__ */
diff --git a/src/git/common.h b/src/git/common.h
index 75e1e84..c470e0e 100644
--- a/src/git/common.h
+++ b/src/git/common.h
@@ -21,7 +21,11 @@
#endif
/** Declare a function as always inlined. */
+#if defined(_MSC_VER)
+# define GIT_INLINE(type) static __inline type
+#else
# define GIT_INLINE(type) static inline type
+#endif
/** Declare a function's takes printf style arguments. */
#ifdef __GNUC__
diff --git a/src/odb.c b/src/odb.c
index ea28d01..6d646a4 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -153,7 +153,7 @@ int git_obj__loose_object_type(git_otype type)
static int format_object_header(char *hdr, size_t n, git_obj *obj)
{
const char *type_str = git_obj_type_to_string(obj->type);
- int len = snprintf(hdr, n, "%s %zu", type_str, obj->len);
+ int len = snprintf(hdr, n, "%s %"PRIuZ, type_str, obj->len);
assert(len > 0); /* otherwise snprintf() is broken */
assert(len < n); /* otherwise the caller is broken! */