summaryrefslogtreecommitdiffstats
path: root/include/gtest/internal/gtest-port.h
diff options
context:
space:
mode:
authorvladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925>2011-09-26 17:54:02 (GMT)
committervladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925>2011-09-26 17:54:02 (GMT)
commitf7d58e81c35b37851733a7518c9f7260ba1b8a40 (patch)
treea82abdf4234927dfc5c2e2302a60511a0483d35c /include/gtest/internal/gtest-port.h
parent1b2e50995887d7128f486eeb0544345296215d30 (diff)
downloadgoogletest-f7d58e81c35b37851733a7518c9f7260ba1b8a40.zip
googletest-f7d58e81c35b37851733a7518c9f7260ba1b8a40.tar.gz
googletest-f7d58e81c35b37851733a7518c9f7260ba1b8a40.tar.bz2
Adds a new macro simplifying use of snprinf on MS platforms.
Diffstat (limited to 'include/gtest/internal/gtest-port.h')
-rw-r--r--include/gtest/internal/gtest-port.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h
index 8a76088..16be48d 100644
--- a/include/gtest/internal/gtest-port.h
+++ b/include/gtest/internal/gtest-port.h
@@ -1682,6 +1682,23 @@ inline void Abort() { abort(); }
} // namespace posix
+// MSVC "deprecates" snprintf and issues warnings wherever it is used. In
+// order to avoid these warnings, we need to use _snprintf or _snprintf_s on
+// MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate
+// function in order to achieve that. We use macro definition here because
+// snprintf is a variadic function.
+#if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
+// MSVC 2005 and above support variadic macros.
+# define GTEST_SNPRINTF_(buffer, size, format, ...) \
+ _snprintf_s(buffer, size, size, format, __VA_ARGS__)
+#elif defined(_MSC_VER)
+// Windows CE does not define _snprintf_s and MSVC prior to 2005 doesn't
+// complain about _snprintf.
+# define GTEST_SNPRINTF_ _snprintf
+#else
+# define GTEST_SNPRINTF_ snprintf
+#endif
+
// The maximum number a BiggestInt can represent. This definition
// works no matter BiggestInt is represented in one's complement or
// two's complement.