From 7e5ddf5aa396d3e6f221449e280925f16b036a51 Mon Sep 17 00:00:00 2001 From: "andrew@webrtc.org" Date: Wed, 14 Dec 2011 18:02:02 +0000 Subject: [PATCH] Restore behavior to FileWrapper::Read. - Returning the number of bytes read was mistakenly removed in r1175 in an overzealous attempt to unify the interface. - Now both Read and WriteText return the number of bytes/characters processed. Write unfortunately cannot be easily changed due to the inheritance from OutStream. - Improve the interface comments. TBR=henrika@webrtc.org BUG=issue196, issue198 TEST=voe_auto_test passes at last... Review URL: http://webrtc-codereview.appspot.com/326001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1188 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/system_wrappers/interface/file_wrapper.h | 8 +++++--- src/system_wrappers/source/file_impl.cc | 10 +++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) 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 {