From c3b3c0fafe4835014d609a93025bae157b39cc15 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 14 May 2014 07:45:21 -0700 Subject: [PATCH] Fix warning. --- test/gtest-extra-test.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/gtest-extra-test.cc b/test/gtest-extra-test.cc index 3a8c42f3..89767901 100644 --- a/test/gtest-extra-test.cc +++ b/test/gtest-extra-test.cc @@ -27,7 +27,6 @@ #include "gtest-extra.h" -#include #include #include #include @@ -63,8 +62,18 @@ class SuppressAssert { }; # define SUPPRESS_ASSERT(statement) { SuppressAssert sa; statement; } + +// Fix "secure" warning about using fopen without defining +// _CRT_SECURE_NO_WARNINGS. +std::FILE *OpenFile(const char *filename, const char *mode) { + std::FILE *f = 0; + errno = fopen_s(&f, filename, mode); + return f; +} +#define fopen OpenFile #else # define SUPPRESS_ASSERT(statement) statement +using std::fopen; #endif // _WIN32 #define EXPECT_SYSTEM_ERROR_NOASSERT(statement, error_code, message) \ @@ -419,7 +428,7 @@ TEST(FileTest, DefaultCtor) { } TEST(FileTest, OpenBufferedFileInCtor) { - FILE *fp = std::fopen("test-file", "w"); + FILE *fp = fopen("test-file", "w"); std::fputs(FILE_CONTENT, fp); std::fclose(fp); File f("test-file", File::RDONLY);