dbertoni 01/11/26 15:03:18
Modified: c/src/PlatformSupport XalanFileOutputStream.cpp
XalanFileOutputStream.hpp
Log:
On Windows, use CreateFile() if CreateFileW() fails. Fix for Windows 9x.
Revision Changes Path
1.6 +73 -18 xml-xalan/c/src/PlatformSupport/XalanFileOutputStream.cpp
Index: XalanFileOutputStream.cpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/PlatformSupport/XalanFileOutputStream.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XalanFileOutputStream.cpp 2001/09/26 14:10:31 1.5
+++ XalanFileOutputStream.cpp 2001/11/26 23:03:18 1.6
@@ -78,40 +78,95 @@
-XalanFileOutputStream::XalanFileOutputStream(
- const XalanDOMString& theFileName,
- unsigned int theBufferSize) :
- XalanOutputStream(theBufferSize),
- m_fileName(theFileName),
+static XalanFileOutputStream::HandleType
+openFile(const XalanDOMString& theFileName)
+{
+ typedef XalanFileOutputStream::HandleType HandleType;
+
#if defined(WIN32)
- m_handle(CreateFileW(
+ HandleType theFileHandle = CreateFileW(
c_wstr(theFileName),
GENERIC_WRITE,
0,
0,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
- 0))
-#else
- m_handle(0)
-#endif
-{
-#if defined(WIN32)
- if (m_handle == INVALID_HANDLE_VALUE)
+ 0);
+
+ if (theFileHandle != INVALID_HANDLE_VALUE)
+ {
+ return theFileHandle;
+ }
+ else
+ {
+ const CharVectorType
theResult(TranscodeToLocalCodePage(theFileName));
+
+ if (theResult.size() == 0)
+ {
+ return INVALID_HANDLE_VALUE;
+ }
+ else
+ {
+ const char* const tmpName = &theResult[0];
+
+ if (tmpName == 0)
+ {
+ return INVALID_HANDLE_VALUE;
+ }
+ else
+ {
+ return CreateFile(
+ tmpName,
+ GENERIC_WRITE,
+ 0,
+ 0,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ 0);
+ }
+ }
+ }
#else
const CharVectorType
theResult(TranscodeToLocalCodePage(theFileName));
+
+ if (theResult.size() == 0)
+ {
+ return false;
+ }
+ else
+ {
+ const char* const tmpName = &theResult[0];
- assert(theResult.size() > 0);
+ if (tmpName == 0)
+ {
+ return 0;
+ }
+ else
+ {
+ return fopen(tmpName, "wb");
+ }
+ }
+#endif
+}
- const char* const tmpName = &theResult[0];
- m_handle = fopen(tmpName, "wb");
+XalanFileOutputStream::XalanFileOutputStream(
+ const XalanDOMString& theFileName,
+ unsigned int theBufferSize) :
+ XalanOutputStream(theBufferSize),
+ m_fileName(theFileName),
+ m_handle(openFile(theFileName))
+{
+#if defined(WIN32)
+ if (m_handle == INVALID_HANDLE_VALUE)
+#else
if (m_handle == 0)
#endif
{
- throw XalanFileOutputStreamOpenException(theFileName,
-
errno);
+ throw XalanFileOutputStreamOpenException(
+ theFileName,
+ errno);
}
}
1.5 +7 -5 xml-xalan/c/src/PlatformSupport/XalanFileOutputStream.hpp
Index: XalanFileOutputStream.hpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/PlatformSupport/XalanFileOutputStream.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XalanFileOutputStream.hpp 2001/09/26 14:10:31 1.4
+++ XalanFileOutputStream.hpp 2001/11/26 23:03:18 1.5
@@ -85,6 +85,12 @@
enum { eDefaultBufferSize = 8192 };
+#if defined(WIN32)
+ typedef HANDLE HandleType;
+#else
+ typedef FILE* HandleType;
+#endif
+
/**
* Construct an XalanFileOutputStream object.
*
@@ -162,11 +168,7 @@
// Data members...
const XalanDOMString m_fileName;
-#if defined(WIN32)
- const HANDLE m_handle;
-#else
- FILE* m_handle;
-#endif
+ const HandleType m_handle;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]