From 5343de692d0823ba7949d568a74c571c8b63366b Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 26 Mar 2009 21:11:22 +0000 Subject: Works around a VC bug by avoiding defining a function named strdup(). git-svn-id: http://googletest.googlecode.com/svn/trunk@228 861a406c-534a-0410-8894-cb66d6ee9925 --- include/gtest/internal/gtest-port.h | 11 ++++++++--- src/gtest-death-test.cc | 4 ++-- src/gtest-port.cc | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index cfb214f..d4ffbb4 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -736,13 +736,18 @@ namespace posix { typedef struct _stat stat_struct; inline int chdir(const char* dir) { return ::_chdir(dir); } +// We cannot write ::_fileno() as MSVC defines it as a macro. inline int fileno(FILE* file) { return _fileno(file); } inline int isatty(int fd) { return ::_isatty(fd); } -inline int stat(const char* path, stat_struct* buf) { return ::_stat(path, buf); } +inline int stat(const char* path, stat_struct* buf) { + return ::_stat(path, buf); +} inline int strcasecmp(const char* s1, const char* s2) { return ::_stricmp(s1, s2); } -inline const char* strdup(const char* src) { return ::_strdup(src); } +// We cannot define the function as strdup(const char* src), since +// MSVC defines strdup as a macro. +inline char* StrDup(const char* src) { return ::_strdup(src); } inline int rmdir(const char* dir) { return ::_rmdir(dir); } inline bool IsDir(const stat_struct& st) { return (_S_IFDIR & st.st_mode) != 0; @@ -757,7 +762,7 @@ using ::fileno; using ::isatty; using ::stat; using ::strcasecmp; -using ::strdup; +inline char* StrDup(const char* src) { return ::strdup(src); } using ::rmdir; inline bool IsDir(const stat_struct& st) { return S_ISDIR(st.st_mode); } diff --git a/src/gtest-death-test.cc b/src/gtest-death-test.cc index 1ad2d6d..517495b 100644 --- a/src/gtest-death-test.cc +++ b/src/gtest-death-test.cc @@ -810,7 +810,7 @@ class Arguments { } } void AddArgument(const char* argument) { - args_.insert(args_.end() - 1, strdup(argument)); + args_.insert(args_.end() - 1, posix::StrDup(argument)); } template @@ -818,7 +818,7 @@ class Arguments { for (typename ::std::vector::const_iterator i = arguments.begin(); i != arguments.end(); ++i) { - args_.insert(args_.end() - 1, strdup(i->c_str())); + args_.insert(args_.end() - 1, posix::StrDup(i->c_str())); } } char* const* Argv() { diff --git a/src/gtest-port.cc b/src/gtest-port.cc index 0299842..ef21389 100644 --- a/src/gtest-port.cc +++ b/src/gtest-port.cc @@ -98,7 +98,7 @@ bool RE::PartialMatch(const char* str, const RE& re) { // Initializes an RE from its string representation. void RE::Init(const char* regex) { - pattern_ = strdup(regex); + pattern_ = posix::StrDup(regex); // Reserves enough bytes to hold the regular expression used for a // full match. @@ -346,7 +346,7 @@ bool RE::PartialMatch(const char* str, const RE& re) { void RE::Init(const char* regex) { pattern_ = full_pattern_ = NULL; if (regex != NULL) { - pattern_ = posix::strdup(regex); + pattern_ = posix::StrDup(regex); } is_valid_ = ValidateRegex(regex); -- cgit v1.2.3