Remove character limit in WriteText().
- vfprintf can be used directly here, removing the need for the interim buffer. This change allows us to remove the artificial character limit. - Fix bugs with _text. It wasn't actually getting set earlier, and the check was wrong. - Remove asserts that should use real error checks. TEST=DataLog and VoECallReport (through voe_auto_test), the only users of WriteText(). Review URL: http://webrtc-codereview.appspot.com/323001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1156 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
2f47b5a70f
commit
114c790be7
@ -22,7 +22,6 @@ class FileWrapper : public InStream, public OutStream
|
||||
{
|
||||
public:
|
||||
enum { kMaxFileNameSize = 1024};
|
||||
enum { kFileMaxTextMessageSize = 1024};
|
||||
|
||||
// Factory method. Constructor disabled.
|
||||
static FileWrapper* Create();
|
||||
@ -52,15 +51,14 @@ public:
|
||||
|
||||
// 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.
|
||||
virtual WebRtc_Word32 WriteText(const WebRtc_Word8* text, ...) = 0;
|
||||
virtual WebRtc_Word32 WriteText(const char* format, ...) = 0;
|
||||
|
||||
// Reads len number of bytes from buf to file.
|
||||
virtual int Read(void* buf, int len) = 0;
|
||||
|
||||
// Writes len number of bytes to buf from file. Please note that the actual
|
||||
// writing to file may happen some time later. Call flush to force a write
|
||||
// to take affect
|
||||
virtual bool Write(const void *buf,int len) = 0;
|
||||
// Writes len number of bytes to buf from file. The actual writing to file
|
||||
// may happen some time later. Call flush to force a write to take effect.
|
||||
virtual bool Write(const void *buf, int len) = 0;
|
||||
|
||||
// Rewinds the file to the start. Only available when OpenFile() has been
|
||||
// called with loop argument set to true. Or readOnly argument has been set
|
||||
|
@ -10,13 +10,13 @@
|
||||
|
||||
#include "file_impl.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
namespace webrtc {
|
||||
@ -125,6 +125,7 @@ WebRtc_Word32 FileWrapperImpl::OpenFile(const WebRtc_Word8 *fileNameUTF8,
|
||||
}
|
||||
|
||||
_readOnly = readOnly;
|
||||
_text = text;
|
||||
|
||||
FILE *tmpId = NULL;
|
||||
#if defined _WIN32
|
||||
@ -174,7 +175,7 @@ WebRtc_Word32 FileWrapperImpl::OpenFile(const WebRtc_Word8 *fileNameUTF8,
|
||||
|
||||
if (tmpId != NULL)
|
||||
{
|
||||
// + 1 comes fro copying the NULL termination charachter too
|
||||
// +1 comes from copying the NULL termination character.
|
||||
memcpy(_fileNameUTF8, fileNameUTF8, length + 1);
|
||||
if (_id != NULL)
|
||||
{
|
||||
@ -196,7 +197,7 @@ int FileWrapperImpl::Read(void *buf, int len)
|
||||
}
|
||||
if (_id != NULL)
|
||||
{
|
||||
WebRtc_Word32 res = static_cast<WebRtc_Word32>(fread(buf, 1, len, _id));
|
||||
int res = static_cast<int>(fread(buf, 1, len, _id));
|
||||
if (res != len)
|
||||
{
|
||||
if(!_looping)
|
||||
@ -209,41 +210,43 @@ int FileWrapperImpl::Read(void *buf, int len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
WebRtc_Word32 FileWrapperImpl::WriteText(const WebRtc_Word8* text, ...)
|
||||
WebRtc_Word32 FileWrapperImpl::WriteText(const char* format, ...)
|
||||
{
|
||||
assert(!_readOnly);
|
||||
assert(!_text);
|
||||
if (_readOnly)
|
||||
return -1;
|
||||
|
||||
if (!_text)
|
||||
return -1;
|
||||
|
||||
if (_id == NULL)
|
||||
return -1;
|
||||
|
||||
if (format == NULL)
|
||||
return -1;
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int num_bytes = vfprintf(_id, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (num_bytes > 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
CloseFile();
|
||||
return -1;
|
||||
}
|
||||
|
||||
char tempBuff[kFileMaxTextMessageSize];
|
||||
if (text)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
#ifdef _WIN32
|
||||
_vsnprintf(tempBuff, kFileMaxTextMessageSize-1, text, args);
|
||||
#else
|
||||
vsnprintf(tempBuff, kFileMaxTextMessageSize-1, text, args);
|
||||
#endif
|
||||
va_end(args);
|
||||
WebRtc_Word32 nBytes;
|
||||
nBytes = fprintf(_id, "%s", tempBuff);
|
||||
if (nBytes > 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
CloseFile();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool FileWrapperImpl::Write(const void* buf, int len)
|
||||
{
|
||||
assert(!_readOnly);
|
||||
if (!_readOnly)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_id != NULL)
|
||||
{
|
||||
// Check if it's time to stop writing.
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
virtual bool Write(const void *buf, int len);
|
||||
virtual int Rewind();
|
||||
|
||||
virtual WebRtc_Word32 WriteText(const WebRtc_Word8* text, ...);
|
||||
virtual WebRtc_Word32 WriteText(const char* format, ...);
|
||||
|
||||
private:
|
||||
FILE* _id;
|
||||
|
Loading…
x
Reference in New Issue
Block a user