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
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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<int>(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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user