Commit c58d4b47 authored by Sean McBride's avatar Sean McBride Committed by Brad King
Browse files

SystemTools: On Windows, strip 'e' from Fopen mode

The MSVC runtime does not support the 'e' mode specifier.
parent 44086372
......@@ -24,6 +24,7 @@
#include KWSYS_HEADER(Encoding.h)
#include KWSYS_HEADER(Encoding.hxx)
#include <algorithm>
#include <fstream>
#include <iostream>
#include <set>
......@@ -892,8 +893,12 @@ const char* SystemTools::GetExecutableExtension()
FILE* SystemTools::Fopen(const std::string& file, const char* mode)
{
#ifdef _WIN32
// Remove any 'e', which is supported on UNIX, but not Windows.
std::wstring trimmedMode = Encoding::ToWide(mode);
trimmedMode.erase(std::remove(trimmedMode.begin(), trimmedMode.end(), L'e'),
trimmedMode.end());
return _wfopen(Encoding::ToWindowsExtendedPath(file).c_str(),
Encoding::ToWide(mode).c_str());
trimmedMode.c_str());
#else
return fopen(file.c_str(), mode);
#endif
......
......@@ -549,7 +549,8 @@ public:
*/
/**
* Open a file considering unicode.
* Open a file considering unicode. On Windows, if 'e' is present in
* mode it is first discarded.
*/
static FILE* Fopen(const std::string& file, const char* mode);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment