Author: tfaber
Date: Sat Jan 26 18:21:39 2013
New Revision: 58227
URL:
http://svn.reactos.org/svn/reactos?rev=58227&view=rev
Log:
[STLPORT] - Add basic_fstream(FILE *) constructor to make up for the completely broken
basic_fstream(int) one
[EXPLORER] - Fix accordingly. Also fix totally broken initialization order in
t[io]fstream
Modified:
trunk/reactos/base/shell/explorer/utility/xmlstorage.h
trunk/reactos/include/c++/stlport/stl/_fstream.h
trunk/reactos/lib/3rdparty/stlport/src/details/fstream_stdio.cpp
Modified: trunk/reactos/base/shell/explorer/utility/xmlstorage.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/utilit…
==============================================================================
--- trunk/reactos/base/shell/explorer/utility/xmlstorage.h [iso-8859-1] (original)
+++ trunk/reactos/base/shell/explorer/utility/xmlstorage.h [iso-8859-1] Sat Jan 26
18:21:39 2013
@@ -516,25 +516,41 @@
/// 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);
-#endif
- }
-
- ~FileHolder()
- {
+ _pfile = _tfopen(path, modestr);
+#endif
+
+#ifdef __GNUC__
+ _buf = new FILE_FILEBUF(_pfile, mode);
+#else
+ _buf = new FILE_FILEBUF;
if (_pfile)
- fclose(_pfile);
- }
-
-protected:
- FILE* _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 @@
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 @@
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
Modified: trunk/reactos/include/c++/stlport/stl/_fstream.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/c%2B%2B/stlport/st…
==============================================================================
--- trunk/reactos/include/c++/stlport/stl/_fstream.h [iso-8859-1] (original)
+++ trunk/reactos/include/c++/stlport/stl/_fstream.h [iso-8859-1] Sat Jan 26 18:21:39
2013
@@ -59,6 +59,9 @@
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 @@
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;
Modified: trunk/reactos/lib/3rdparty/stlport/src/details/fstream_stdio.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/3rdparty/stlport/src/d…
==============================================================================
--- trunk/reactos/lib/3rdparty/stlport/src/details/fstream_stdio.cpp [iso-8859-1]
(original)
+++ trunk/reactos/lib/3rdparty/stlport/src/details/fstream_stdio.cpp [iso-8859-1] Sat Jan
26 18:21:39 2013
@@ -300,6 +300,41 @@
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)