From 266399d8e5d1fcfa1bd4cc8d6b2997c90c850dfe Mon Sep 17 00:00:00 2001
From: Niels <niels.lohmann@gmail.com>
Date: Thu, 4 Jun 2015 08:31:13 +0200
Subject: [PATCH] fixed MinGW compilation (#81 and #80)

---
 src/json.hpp      | 15 +++++++++++----
 src/json.hpp.re2c | 15 +++++++++++----
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/json.hpp b/src/json.hpp
index 030d955e..c0a630e1 100644
--- a/src/json.hpp
+++ b/src/json.hpp
@@ -29,6 +29,13 @@
 #include <utility>
 #include <vector>
 
+// enable ssize_t on MinGW
+#ifdef __GNUC__
+    #ifdef __MINGW32__
+        #include <sys/types.h>
+    #endif
+#endif
+
 /*!
 @brief namespace for Niels Lohmann
 @see https://github.com/nlohmann
@@ -2159,8 +2166,7 @@ class basic_json
     recursively. Note that
 
     - strings and object keys are escaped using escape_string()
-    - integer numbers are converted to a string before output using
-      std::to_string()
+    - integer numbers are converted implictly via operator<<
     - floating-point numbers are converted to a string using "%g" format
 
     @param o              stream to write to
@@ -2278,9 +2284,10 @@ class basic_json
             {
                 // 15 digits of precision allows round-trip IEEE 754
                 // string->double->string
-                const auto sz = static_cast<unsigned int>(std::snprintf(nullptr, 0, "%.15g", m_value.number_float));
+                using std::snprintf;
+                const auto sz = static_cast<unsigned int>(snprintf(nullptr, 0, "%.15g", m_value.number_float));
                 std::vector<typename string_t::value_type> buf(sz + 1);
-                std::snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float);
+                snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float);
                 o << buf.data();
                 return;
             }
diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c
index 84f5aaa0..572690bc 100644
--- a/src/json.hpp.re2c
+++ b/src/json.hpp.re2c
@@ -29,6 +29,13 @@
 #include <utility>
 #include <vector>
 
+// enable ssize_t on MinGW
+#ifdef __GNUC__
+    #ifdef __MINGW32__
+        #include <sys/types.h>
+    #endif
+#endif
+
 /*!
 @brief namespace for Niels Lohmann
 @see https://github.com/nlohmann
@@ -2159,8 +2166,7 @@ class basic_json
     recursively. Note that
 
     - strings and object keys are escaped using escape_string()
-    - integer numbers are converted to a string before output using
-      std::to_string()
+    - integer numbers are converted implictly via operator<<
     - floating-point numbers are converted to a string using "%g" format
 
     @param o              stream to write to
@@ -2278,9 +2284,10 @@ class basic_json
             {
                 // 15 digits of precision allows round-trip IEEE 754
                 // string->double->string
-                const auto sz = static_cast<unsigned int>(std::snprintf(nullptr, 0, "%.15g", m_value.number_float));
+                using std::snprintf;
+                const auto sz = static_cast<unsigned int>(snprintf(nullptr, 0, "%.15g", m_value.number_float));
                 std::vector<typename string_t::value_type> buf(sz + 1);
-                std::snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float);
+                snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float);
                 o << buf.data();
                 return;
             }