- Sync with trunk r58248 to bring the latest changes from Amine (headers) and others...
[reactos.git] / base / shell / explorer / utility / xmlstorage.h
index 1913bdc..ea70d8f 100644 (file)
@@ -157,8 +157,8 @@ typedef XMLCh XML_Char;
 
 #ifdef _WIN32
 
-#include <windows.h>   // for LPCTSTR
-#include <tchar.h>
+//#include <windows.h> // for LPCTSTR
+//#include <tchar.h>
 #include <malloc.h>
 
 #ifndef _MSC_VER
@@ -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()
+       {
+       }
+
+       ~FileHolder()
+       {
+               if (_pfile)
+                       fclose(_pfile);
+               delete _buf;
+       }
+
+       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, mode) != 0)
+               if (_tfopen_s(&_pfile, path, modestr) != 0)
                        _pfile = NULL;
 #else
-               _pfile = _tfopen(path, mode);
+               _pfile = _tfopen(path, modestr);
 #endif
-       }
 
-       ~FileHolder()
-       {
+#ifdef __GNUC__
+               _buf = new FILE_FILEBUF(_pfile, mode);
+#else
+               _buf = new FILE_FILEBUF;
                if (_pfile)
-                       fclose(_pfile);
+                       _buf->open(_pfile, mode);
+#endif
+               return _buf;
        }
 
-protected:
-       FILE*   _pfile;
+       FILE*                   _pfile;
+       FILE_FILEBUF*   _buf;
 };
 
  /// input file stream with ANSI/UNICODE file names
@@ -543,20 +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(_pfile)
-#endif
+        :      super(init_buf(path, std::ios::in))
        {
                if (!_pfile)
                        setstate(badbit);
        }
-
-protected:
-       FILE_FILEBUF _buf;
 };
 
  /// output file stream with ANSI/UNICODE file names
@@ -565,13 +572,7 @@ 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(_pfile)
-#endif
+        :      super(init_buf(path, std::ios::out))
        {
                if (!_pfile)
                        setstate(badbit);
@@ -581,9 +582,6 @@ struct tofstream : public std::ostream, FileHolder
        {
                flush();
        }
-
-protected:
-       FILE_FILEBUF _buf;
 };
 
 #else // FILE_FILEBUF