[Scummvm-cvs-logs] SF.net SVN: scummvm:[53576] scummvm/trunk/common
sev at users.sourceforge.net
sev at users.sourceforge.net
Mon Oct 18 21:04:41 CEST 2010
Revision: 53576
http://scummvm.svn.sourceforge.net/scummvm/?rev=53576&view=rev
Author: sev
Date: 2010-10-18 19:04:41 +0000 (Mon, 18 Oct 2010)
Log Message:
-----------
COMMON: Implement Common::vprintf(). Patch by littleboy
Modified Paths:
--------------
scummvm/trunk/common/str.cpp
scummvm/trunk/common/str.h
Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp 2010-10-18 19:03:24 UTC (rev 53575)
+++ scummvm/trunk/common/str.cpp 2010-10-18 19:04:41 UTC (rev 53576)
@@ -30,6 +30,18 @@
#include <stdarg.h>
+#ifndef VA_COPY
+#if defined(HAVE_VA_COPY) || defined(va_copy)
+#define VA_COPY(dest, src) va_copy(dest, src)
+#else
+#ifdef HAVE___VA_COPY
+#define VA_COPY(dest, src) __va_copy(dest, src)
+#else
+#define VA_COPY(dest, src) (dest) = (src)
+#endif
+#endif
+#endif
+
namespace Common {
MemoryPool *g_refCountPool = 0; // FIXME: This is never freed right now
@@ -431,13 +443,22 @@
// static
String String::printf(const char *fmt, ...) {
+ va_list argptr;
+
+ va_start(argptr, fmt);
+ Common::String output = vprintf(fmt, argptr);
+ va_end (argptr);
+
+ return output;
+}
+
+String String::vprintf(const char *fmt, va_list argptr) {
String output;
assert(output.isStorageIntern());
va_list va;
- va_start(va, fmt);
+ VA_COPY(va, argptr);
int len = vsnprintf(output._str, _builtinCapacity, fmt, va);
- va_end(va);
if (len == -1 || len == _builtinCapacity - 1) {
// MSVC and IRIX don't return the size the full string would take up.
@@ -460,9 +481,7 @@
assert(!output.isStorageIntern());
size = output._extern._capacity;
- va_start(va, fmt);
len = vsnprintf(output._str, size, fmt, va);
- va_end(va);
} while (len == -1 || len >= size - 1);
output._size = len;
} else if (len < (int)_builtinCapacity) {
@@ -471,9 +490,7 @@
} else {
// vsnprintf didn't have enough space, so grow buffer
output.ensureCapacity(len, false);
- va_start(va, fmt);
int len2 = vsnprintf(output._str, len+1, fmt, va);
- va_end(va);
assert(len == len2);
output._size = len2;
}
Modified: scummvm/trunk/common/str.h
===================================================================
--- scummvm/trunk/common/str.h 2010-10-18 19:03:24 UTC (rev 53575)
+++ scummvm/trunk/common/str.h 2010-10-18 19:04:41 UTC (rev 53576)
@@ -220,6 +220,8 @@
*/
static Common::String printf(const char *fmt, ...) GCC_PRINTF(1,2);
+ static Common::String vprintf(const char *fmt, va_list argptr);
+
public:
typedef char * iterator;
typedef const char * const_iterator;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list