diff --git a/reactos/base/shell/explorer/utility/xmlstorage.h b/reactos/base/shell/explorer/utility/xmlstorage.h index 7e8eb69101c..ea70d8fdd09 100644 --- a/reactos/base/shell/explorer/utility/xmlstorage.h +++ b/reactos/base/shell/explorer/utility/xmlstorage.h @@ -516,25 +516,41 @@ extern XS_String DecodeXMLString(const std::string& str); /// base class for XMLStorage::tifstream and XMLStorage::tofstream struct FileHolder { - FileHolder(LPCTSTR path, LPCTSTR mode) +protected: + FileHolder() { -//@@ _MS_VER: temporarily needed for the ReactOS build environment -#if defined(__STDC_WANT_SECURE_LIB__) && defined(_MS_VER) // secure CRT functions using VS 2005 - if (_tfopen_s(&_pfile, path, mode) != 0) - _pfile = NULL; -#else - _pfile = _tfopen(path, mode); -#endif } ~FileHolder() { if (_pfile) fclose(_pfile); + delete _buf; } -protected: - FILE* _pfile; + FILE_FILEBUF* init_buf(LPCTSTR path, std::ios_base::openmode mode) + { + PCTSTR modestr = mode == std::ios::in ? TEXT("rb") : TEXT("wb"); +//@@ _MS_VER: temporarily needed for the ReactOS build environment +#if defined(__STDC_WANT_SECURE_LIB__) && defined(_MS_VER) // secure CRT functions using VS 2005 + if (_tfopen_s(&_pfile, path, modestr) != 0) + _pfile = NULL; +#else + _pfile = _tfopen(path, modestr); +#endif + +#ifdef __GNUC__ + _buf = new FILE_FILEBUF(_pfile, mode); +#else + _buf = new FILE_FILEBUF; + if (_pfile) + _buf->open(_pfile, mode); +#endif + return _buf; + } + + FILE* _pfile; + FILE_FILEBUF* _buf; }; /// input file stream with ANSI/UNICODE file names @@ -543,24 +559,11 @@ struct tifstream : public std::istream, FileHolder typedef std::istream super; tifstream(LPCTSTR path) - : super(&_buf), - FileHolder(path, TEXT("rb")), // binary mode is important for XMLReader::read_buffer() with MinGW libraries -#ifdef __GNUC__ - _buf(_pfile, std::ios::in) -#else - _buf() -#endif + : super(init_buf(path, std::ios::in)) { if (!_pfile) setstate(badbit); -#ifdef _MSC_VER - else - _buf.open(fileno(_pfile)); -#endif } - -protected: - FILE_FILEBUF _buf; }; /// output file stream with ANSI/UNICODE file names @@ -569,29 +572,16 @@ struct tofstream : public std::ostream, FileHolder typedef std::ostream super; tofstream(LPCTSTR path) - : super(&_buf), - FileHolder(path, TEXT("wb")), -#ifdef __GNUC__ - _buf(_pfile, std::ios::out) -#else - _buf() -#endif + : super(init_buf(path, std::ios::out)) { if (!_pfile) setstate(badbit); -#ifdef _MSC_VER - else - _buf.open(fileno(_pfile)); -#endif } ~tofstream() { flush(); } - -protected: - FILE_FILEBUF _buf; }; #else // FILE_FILEBUF diff --git a/reactos/include/c++/stlport/stl/_fstream.h b/reactos/include/c++/stlport/stl/_fstream.h index 1945e411884..1249e956e26 100644 --- a/reactos/include/c++/stlport/stl/_fstream.h +++ b/reactos/include/c++/stlport/stl/_fstream.h @@ -59,6 +59,9 @@ public: // Opening and closing files. bool _M_open(const char*, ios_base::openmode, long __protection); bool _M_open(const char*, ios_base::openmode); bool _M_open(int __id, ios_base::openmode = ios_base::__default_mode); +#if defined (_STLP_USE_STDIO_IO) + bool _M_open(FILE *file, ios_base::openmode = ios_base::__default_mode); +#endif /* _STLP_USE_STDIO_IO */ #if defined (_STLP_USE_WIN32_IO) bool _M_open(_STLP_fd __id, ios_base::openmode = ios_base::__default_mode); #endif /* _STLP_USE_WIN32_IO */ @@ -182,6 +185,12 @@ public: // Opening and closing files. return this->_M_open(__id, _Init_mode); } +# if defined (_STLP_USE_STDIO_IO) + _Self* open(FILE *file, ios_base::openmode _Init_mode = ios_base::__default_mode) { + return _M_base._M_open(file, _Init_mode) ? this : 0; + } +# endif /* _STLP_USE_STDIO_IO */ + # if defined (_STLP_USE_WIN32_IO) _Self* open(_STLP_fd __id, ios_base::openmode _Init_mode = ios_base::__default_mode) { return _M_base._M_open(__id, _Init_mode) ? this : 0; diff --git a/reactos/lib/3rdparty/stlport/src/details/fstream_stdio.cpp b/reactos/lib/3rdparty/stlport/src/details/fstream_stdio.cpp index 8392ffdebc9..ea37a2e5d93 100644 --- a/reactos/lib/3rdparty/stlport/src/details/fstream_stdio.cpp +++ b/reactos/lib/3rdparty/stlport/src/details/fstream_stdio.cpp @@ -300,6 +300,41 @@ bool _Filebuf_base::_M_open( int file_no, ios_base::openmode ) return true; } +bool _Filebuf_base::_M_open(FILE *file, ios_base::openmode openmode) +{ + _STLP_fd file_no; + + if (_M_is_open) + return false; + + _M_file = file; + + if (_M_file) { + file_no = fileno(_M_file); + } else { + return false; + } + + // unset buffering immediately + setbuf(_M_file, 0); + + _M_is_open = true; + + if (openmode & ios_base::ate) { + if (FSEEK(_M_file, 0, SEEK_END) != 0) + _M_is_open = false; + } + + _M_file_id = file_no; + _M_should_close = _M_is_open; + _M_openmode = openmode; + + if (_M_is_open) + _M_regular_file = _STLP_PRIV __is_regular_file(_M_file_id); + + return (_M_is_open != 0); +} + bool _Filebuf_base::_M_close() { if (!_M_is_open)