From c6129f81e9a001e7648a0a3f06a273e5876fc8cc Mon Sep 17 00:00:00 2001 From: cutealien Date: Sun, 27 Aug 2017 15:09:34 +0000 Subject: [PATCH] Revert ftell checks from r5532. Add documentation. I suppose not checking gives a chance for ftell to go wrong in which case we can get an error (size -1). Arguably which solution is better - I reverted it simply because not changing old behavior is probably better than changing it. Also added documentation about getSize to IReadFile, IWriteFile and IFileReadCallBack that those functions can return -1L on error (thanks @dixx for mentioning that in http://irrlicht.sourceforge.net/forum/viewtopic.php?f=4&t=52086). git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5538 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IReadFile.h | 2 +- include/IWriteFile.h | 2 +- include/irrXML.h | 8 ++++---- source/Irrlicht/CReadFile.cpp | 8 +++----- source/Irrlicht/CWriteFile.cpp | 9 +++------ source/Irrlicht/irrXML.cpp | 8 +++----- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/include/IReadFile.h b/include/IReadFile.h index 790a1ae5..47deb7e4 100644 --- a/include/IReadFile.h +++ b/include/IReadFile.h @@ -36,7 +36,7 @@ namespace io virtual long getSize() const = 0; //! Get the current position in the file. - /** \return Current position in the file in bytes. */ + /** \return Current position in the file in bytes on success or -1L on failure. */ virtual long getPos() const = 0; //! Get name of file. diff --git a/include/IWriteFile.h b/include/IWriteFile.h index 68eac14a..5cc48352 100644 --- a/include/IWriteFile.h +++ b/include/IWriteFile.h @@ -32,7 +32,7 @@ namespace io virtual bool seek(long finalPos, bool relativeMovement = false) = 0; //! Get the current position in the file. - /** \return Current position in the file in bytes. */ + /** \return Current position in the file in bytes on success or -1L on failure */ virtual long getPos() const = 0; //! Get name of file. diff --git a/include/irrXML.h b/include/irrXML.h index cc65bd15..5957e086 100644 --- a/include/irrXML.h +++ b/include/irrXML.h @@ -224,7 +224,7 @@ namespace io \return Returns how much bytes were read. */ virtual int read(void* buffer, int sizeToRead) = 0; - //! Returns size of file in bytes + //! Returns size of file in bytes on success or -1L on failure. virtual long getSize() const = 0; }; @@ -317,7 +317,7 @@ namespace io //! Returns the value of an attribute as integer. /** \param name Name of the attribute. \param defaultNotFound Value returned when name does not exist - \return Value of the attribute as integer or value of defaultNotFound + \return Value of the attribute as integer or value of defaultNotFound when name was not found or 0 when value could not be interpreted as integer */ virtual int getAttributeValueAsInt(const char_type* name, int defaultNotFound=0) const = 0; @@ -331,14 +331,14 @@ namespace io //! Returns the value of an attribute as float. /** \param name: Name of the attribute. \param defaultNotFound Value returned when name does not exist. - \return Value of the attribute as float or value of defaultNotFound parameter on failure + \return Value of the attribute as float or value of defaultNotFound parameter on failure or 0 when value could not be interpreted as float. */ virtual float getAttributeValueAsFloat(const char_type* name, float defaultNotFound=0.f) const = 0; //! Returns the value of an attribute as float. /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1. \param defaultNotFound Value returned when index does not exist. - \return Value of the attribute as float or value of defaultNotFound parameter on failure + \return Value of the attribute as float or value of defaultNotFound parameter on failure or 0 when value could not be interpreted as float. */ virtual float getAttributeValueAsFloat(int idx, float defaultNotFound=0.f) const = 0; diff --git a/source/Irrlicht/CReadFile.cpp b/source/Irrlicht/CReadFile.cpp index 424b0267..cf90f54b 100644 --- a/source/Irrlicht/CReadFile.cpp +++ b/source/Irrlicht/CReadFile.cpp @@ -83,11 +83,9 @@ void CReadFile::openFile() { // get FileSize - if ( fseek(File, 0, SEEK_END) == 0 ) - { - FileSize = getPos(); - fseek(File, 0, SEEK_SET); - } + fseek(File, 0, SEEK_END); + FileSize = getPos(); + fseek(File, 0, SEEK_SET); } } diff --git a/source/Irrlicht/CWriteFile.cpp b/source/Irrlicht/CWriteFile.cpp index 7d6f0812..ef816b6b 100644 --- a/source/Irrlicht/CWriteFile.cpp +++ b/source/Irrlicht/CWriteFile.cpp @@ -91,12 +91,9 @@ void CWriteFile::openFile(bool append) { // get FileSize - if ( fseek(File, 0, SEEK_END) == 0 ) - { - FileSize = ftell(File); - fseek(File, 0, SEEK_SET); - - } + fseek(File, 0, SEEK_END); + FileSize = ftell(File); + fseek(File, 0, SEEK_SET); } } diff --git a/source/Irrlicht/irrXML.cpp b/source/Irrlicht/irrXML.cpp index d0f43a96..a5553ade 100644 --- a/source/Irrlicht/irrXML.cpp +++ b/source/Irrlicht/irrXML.cpp @@ -67,11 +67,9 @@ private: //! retrieves the file size of the open file void getFileSize() { - if ( fseek(File, 0, SEEK_END) == 0 ) - { - Size = ftell(File); - fseek(File, 0, SEEK_SET); - } + fseek(File, 0, SEEK_END); + Size = ftell(File); + fseek(File, 0, SEEK_SET); } FILE* File;