From 81da1fb26bf909f3aefd1984baf0a6c7b2784670 Mon Sep 17 00:00:00 2001 From: Ken Miller Date: Mon, 9 Apr 2012 23:32:26 -0500 Subject: [PATCH] Made SaveFile symmetrical with LoadFile Added overload taking a FILE pointer Return error code (if any) instead of void --- tinyxml2.cpp | 21 ++++++++++++++------- tinyxml2.h | 12 +++++++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index f6998ea..4ce9b32 100644 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1407,7 +1407,7 @@ int XMLDocument::LoadFile( FILE* fp ) } -void XMLDocument::SaveFile( const char* filename ) +int XMLDocument::SaveFile( const char* filename ) { #if defined(_MSC_VER) #pragma warning ( push ) @@ -1417,14 +1417,21 @@ void XMLDocument::SaveFile( const char* filename ) #if defined(_MSC_VER) #pragma warning ( pop ) #endif - if ( fp ) { - XMLPrinter stream( fp ); - Print( &stream ); - fclose( fp ); - } - else { + if ( !fp ) { SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, 0 ); + return errorID; } + SaveFile(fp); + fclose( fp ); + return errorID; +} + + +int XMLDocument::SaveFile( FILE* fp ) +{ + XMLPrinter stream( fp ); + Print( &stream ); + return errorID; } diff --git a/tinyxml2.h b/tinyxml2.h index feffd36..769882b 100644 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -1024,8 +1024,18 @@ public: int LoadFile( FILE* ); /** Save the XML file to disk. + Returns XML_NO_ERROR (0) on success, or + an errorID. */ - void SaveFile( const char* filename ); + int SaveFile( const char* filename ); + /** + Save the XML file to disk. You are responsible + for providing and closing the FILE*. + + Returns XML_NO_ERROR (0) on success, or + an errorID. + */ + int SaveFile( FILE* ); bool ProcessEntities() const { return processEntities; }