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
diff --git a/src/system_wrappers/interface/file_wrapper.h b/src/system_wrappers/interface/file_wrapper.h
index 8f0cd8c..123ab65 100644
--- a/src/system_wrappers/interface/file_wrapper.h
+++ b/src/system_wrappers/interface/file_wrapper.h
@@ -22,7 +22,6 @@
{
public:
enum { kMaxFileNameSize = 1024};
- enum { kFileMaxTextMessageSize = 1024};
// Factory method. Constructor disabled.
static FileWrapper* Create();
@@ -52,15 +51,14 @@
// 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
diff --git a/src/system_wrappers/source/file_impl.cc b/src/system_wrappers/source/file_impl.cc
index 6046c2c..f252fe2 100644
--- a/src/system_wrappers/source/file_impl.cc
+++ b/src/system_wrappers/source/file_impl.cc
@@ -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 @@
}
_readOnly = readOnly;
+ _text = text;
FILE *tmpId = NULL;
#if defined _WIN32
@@ -174,7 +175,7 @@
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 @@
}
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 @@
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.
diff --git a/src/system_wrappers/source/file_impl.h b/src/system_wrappers/source/file_impl.h
index cf6b734..457b110 100644
--- a/src/system_wrappers/source/file_impl.h
+++ b/src/system_wrappers/source/file_impl.h
@@ -40,7 +40,7 @@
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;