dbertoni 01/06/06 14:58:25
Modified: c/src/PlatformSupport XalanFileOutputStream.cpp
XalanFileOutputStream.hpp
Log:
New native Win32 file handling.
Revision Changes Path
1.4 +50 -7 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XalanFileOutputStream.cpp 2000/11/30 14:41:32 1.3
+++ XalanFileOutputStream.cpp 2001/06/06 21:58:22 1.4
@@ -78,12 +78,27 @@
-
-XalanFileOutputStream::XalanFileOutputStream(const XalanDOMString&
theFileName) :
- XalanOutputStream(),
+XalanFileOutputStream::XalanFileOutputStream(
+ const XalanDOMString& theFileName,
+ unsigned int theBufferSize) :
+ XalanOutputStream(theBufferSize),
m_fileName(theFileName),
+#if defined(WIN32)
+ m_handle(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)
+#else
const CharVectorType
theResult(TranscodeToLocalCodePage(theFileName));
assert(theResult.size() > 0);
@@ -93,6 +108,7 @@
m_handle = fopen(tmpName, "wb");
if (m_handle == 0)
+#endif
{
throw XalanFileOutputStreamOpenException(theFileName,
errno);
@@ -103,10 +119,17 @@
XalanFileOutputStream::~XalanFileOutputStream()
{
+#if defined(WIN32)
+ if (m_handle != INVALID_HANDLE_VALUE)
+ {
+ CloseHandle(m_handle);
+ }
+#else
if (m_handle != 0)
{
fclose(m_handle);
}
+#endif
}
@@ -114,7 +137,14 @@
void
XalanFileOutputStream::doFlush()
{
- fflush(m_handle);
+#if !defined(WIN32)
+ if (fflush(m_handle) != 0)
+ {
+ throw XalanFileOutputStreamWriteException(
+ m_fileName,
+ errno);
+ }
+#endif
}
@@ -124,17 +154,30 @@
const char* theBuffer,
unsigned long theBufferLength)
{
+#if defined(WIN32)
+ DWORD theBytesWritten;
+
+ if (WriteFile(m_handle, theBuffer, theBufferLength, &theBytesWritten,
0) == false ||
+ theBytesWritten != theBufferLength)
+ {
+ throw XalanFileOutputStreamWriteException(
+ m_fileName,
+ GetLastError());
+ }
+#else
const size_t theBytesWritten =
fwrite(theBuffer,
1,
theBufferLength,
m_handle);
- if(theBytesWritten != theBufferLength)
+ if (theBytesWritten != theBufferLength)
{
- throw XalanFileOutputStreamWriteException(m_fileName,
-
errno);
+ throw XalanFileOutputStreamWriteException(
+ m_fileName,
+ errno);
}
+#endif
}
1.2 +17 -3 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XalanFileOutputStream.hpp 2000/09/27 16:24:12 1.1
+++ XalanFileOutputStream.hpp 2001/06/06 21:58:23 1.2
@@ -64,7 +64,12 @@
+#if defined(WIN32)
+#include <windows.h>
+#else
#include <cstdio>
+#endif
+
#include <vector>
@@ -78,12 +83,17 @@
{
public :
+ enum { eDefaultBufferSize = 8192 };
+
/**
- * Construct an XalanFileOutputStream exception object.
+ * Construct an XalanFileOutputStream object.
*
- * @param theFileName name of file causing the exception
+ * @param theFileName name of file
+ * @param theBufferSize The size of the buffer
*/
- XalanFileOutputStream(const XalanDOMString& theFileName);
+ XalanFileOutputStream(
+ const XalanDOMString& theFileName,
+ unsigned int theBufferSize =
eDefaultBufferSize);
virtual
~XalanFileOutputStream();
@@ -162,7 +172,11 @@
// Data members...
const XalanDOMString m_fileName;
+#if defined(WIN32)
+ const HANDLE m_handle;
+#else
FILE* m_handle;
+#endif
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]