diff --git a/src/system_wrappers/interface/file_wrapper.h b/src/system_wrappers/interface/file_wrapper.h index 71f945aee..fe5de4df3 100644 --- a/src/system_wrappers/interface/file_wrapper.h +++ b/src/system_wrappers/interface/file_wrapper.h @@ -53,12 +53,14 @@ public: virtual int FileName(char* fileNameUTF8, size_t size) const = 0; - // Write text to the opened file. The written text can contain plain text - // and text with type specifiers in the same way as sprintf works. + // Write |format| to the opened file. Supply arguments to this function as + // you would printf. Returns the number of characters written or -1 on + // error. virtual int WriteText(const char* format, ...) = 0; // Inherited from Instream. - // Reads |len| bytes from file to |buf|. + // Reads |len| bytes from file to |buf|. Returns the number of bytes read + // or -1 on error. virtual int Read(void* buf, int len) = 0; // Inherited from OutStream. diff --git a/src/system_wrappers/source/file_impl.cc b/src/system_wrappers/source/file_impl.cc index c58d41916..67a45677e 100644 --- a/src/system_wrappers/source/file_impl.cc +++ b/src/system_wrappers/source/file_impl.cc @@ -188,6 +188,10 @@ int FileWrapperImpl::OpenFile(const char *fileNameUTF8, bool readOnly, int FileWrapperImpl::Read(void *buf, int len) { + if (len < 0) + { + return -1; + } if (_id != NULL) { int res = static_cast(fread(buf, 1, len, _id)); @@ -198,7 +202,7 @@ int FileWrapperImpl::Read(void *buf, int len) CloseFile(); } } - return 0; + return res; } return -1; } @@ -219,9 +223,9 @@ int FileWrapperImpl::WriteText(const char* format, ...) int num_chars = vfprintf(_id, format, args); va_end(args); - if (num_chars > 0) + if (num_chars >= 0) { - return 0; + return num_chars; } else {