mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-30 20:59:12 +08:00
5983ba633f
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
52 lines
1.5 KiB
Diff
52 lines
1.5 KiB
Diff
From 8b5b2ea5ba695252abaad4234c951675d5f733ec Mon Sep 17 00:00:00 2001
|
|
From: Hiroshi Miura <miurahr@linux.com>
|
|
Date: Wed, 7 Feb 2018 12:28:54 +0900
|
|
Subject: [PATCH 1/2] VS2015 provides snprintf
|
|
|
|
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
|
|
---
|
|
lib/common.h | 27 +++++++++++++++++++++++----
|
|
1 file changed, 23 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/lib/common.h b/lib/common.h
|
|
index c5db1ed..73c4118 100644
|
|
--- a/lib/common.h
|
|
+++ b/lib/common.h
|
|
@@ -39,10 +39,29 @@ extern "C" {
|
|
/** \addtogroup misc Miscellanea */
|
|
/*@{*/
|
|
|
|
-/* Use _snprintf instead of snprintf under MSVC compiler */
|
|
-#if defined(_WIN32) && !defined(__MINGW32__)
|
|
-#define snprintf _snprintf
|
|
-#endif
|
|
+#ifdef _MSC_VER
|
|
+#if _MSC_VER < 1900 // VS2015/17 provides snprintf
|
|
+#include <stdio.h>
|
|
+#include <stdarg.h>
|
|
+/* Want safe, 'n += snprintf(b + n ...)' like function. If cp_max_len is 1
|
|
+* then assume cp is pointing to a null char and do nothing. Returns number
|
|
+* number of chars placed in cp excluding the trailing null char. So for
|
|
+* cp_max_len > 0 the return value is always < cp_max_len; for cp_max_len
|
|
+* <= 0 the return value is 0 (and no chars are written to cp). */
|
|
+static int snprintf(char * cp, int cp_max_len, const char * fmt, ...)
|
|
+{
|
|
+ va_list args;
|
|
+ int n;
|
|
+
|
|
+ if (cp_max_len < 2)
|
|
+ return 0;
|
|
+ va_start(args, fmt);
|
|
+ n = vsnprintf(cp, cp_max_len, fmt, args);
|
|
+ va_end(args);
|
|
+ return (n < cp_max_len) ? n : (cp_max_len - 1);
|
|
+}
|
|
+#endif // _MSC_VER < 1900
|
|
+#endif // _MSC_VER
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
# include <config.h>
|
|
--
|
|
2.16.1
|
|
|