From 87ced1364e9a2a2c1ee21b833c831903f7d92e7e Mon Sep 17 00:00:00 2001 From: PeiYong Zhang <peiyongz@apache.org> Date: Tue, 16 Jul 2002 15:42:47 +0000 Subject: [PATCH] openFileToWrite(), writeBufferToFile() git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@174016 13f79535-47bb-0310-9956-ffa450edef68 --- .../Platforms/OS400/OS400PlatformUtils.cpp | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/xercesc/util/Platforms/OS400/OS400PlatformUtils.cpp b/src/xercesc/util/Platforms/OS400/OS400PlatformUtils.cpp index 83db3304e..6319b8db6 100644 --- a/src/xercesc/util/Platforms/OS400/OS400PlatformUtils.cpp +++ b/src/xercesc/util/Platforms/OS400/OS400PlatformUtils.cpp @@ -262,6 +262,30 @@ FileHandle XMLPlatformUtils::openFile(const char* const fileName) return retVal; } +FileHandle XMLPlatformUtils::openFileToWrite(const XMLCh* const fileName) +{ + const char* tmpFileName = XMLString::transcode(fileName); + ArrayJanitor<char> janText((char*)tmpFileName); + + return openFileToWrite(tmpFileName); +} + +FileHandle XMLPlatformUtils::openFileToWrite(const char* const fileName) +{ + char errno_id[7]; + errno = 0; + FileHandle retVal = (FILE*)fopen( fileName , "wb" ); + + if (retVal == NULL) + { + send_message((char*)fileName,FILE_OPEN_PROBLEMS,'d'); + convert_errno(errno_id,errno); + send_message(NULL,errno_id,'d'); + return 0; + } + + return retVal; +} unsigned int XMLPlatformUtils::readFileBuffer( FileHandle theFile @@ -277,6 +301,40 @@ XMLPlatformUtils::readFileBuffer( FileHandle theFile return (unsigned int)noOfItemsRead; } +void +XMLPlatformUtils::writeBufferToFile( FileHandle const theFile + , long toWrite + , const XMLByte* const toFlush) +{ + if (!theFile || + (toWrite <= 0 ) || + !toFlush ) + return; + + const XMLByte* tmpFlush = (const XMLByte*) toFlush; + size_t bytesWritten = 0; + + while (true) + { + bytesWritten=fwrite(tmpFlush, sizeof(XMLByte), toWrite, (FILE*)theFile); + + if(ferror((FILE*)theFile)) + { + ThrowXML(XMLPlatformUtilsException, XMLExcepts::File_CouldNotWriteToFile); + } + + if (bytesWritten < toWrite) //incomplete write + { + tmpFlush+=bytesWritten; + toWrite-=bytesWritten; + bytesWritten=0; + } + else + return; + } + + return; +} void XMLPlatformUtils::resetFile(FileHandle theFile) { -- GitLab