From 479523d59e7f9a1bb03c691e52f29ecd0ef835be Mon Sep 17 00:00:00 2001 From: Date: Wed, 5 Jan 2011 12:20:09 +0000 Subject: [PATCH] Add the sqlite3_vsnprintf() interface. --- src/printf.c | 25 ++++++++++++++++--------- src/sqlite.h.in | 3 +++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/printf.c b/src/printf.c index da2fdf610..755355de0 100644 --- a/src/printf.c +++ b/src/printf.c @@ -934,21 +934,28 @@ char *sqlite3_mprintf(const char *zFormat, ...){ ** current locale settings. This is important for SQLite because we ** are not able to use a "," as the decimal point in place of "." as ** specified by some locales. +** +** Oops: The first two arguments of sqlite3_snprintf() are backwards +** from the snprintf() standard. Unfortunately, it is too late to change +** this without breaking compatibility, so we just have to live with the +** mistake. +** +** sqlite3_vsnprintf() is the varargs version. */ -char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ - char *z; - va_list ap; +char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){ StrAccum acc; - - if( n<=0 ){ - return zBuf; - } + if( n<=0 ) return zBuf; sqlite3StrAccumInit(&acc, zBuf, n, 0); acc.useMalloc = 0; - va_start(ap,zFormat); sqlite3VXPrintf(&acc, 0, zFormat, ap); + return sqlite3StrAccumFinish(&acc); +} +char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ + char *z; + va_list ap; + va_start(ap,zFormat); + z = sqlite3_vsnprintf(n, zBuf, zFormat, ap); va_end(ap); - z = sqlite3StrAccumFinish(&acc); return z; } diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 77b0aad63..5aaeb4a10 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -1861,6 +1861,8 @@ void sqlite3_free_table(char **result); ** the zero terminator. So the longest string that can be completely ** written will be n-1 characters. ** +** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). +** ** These routines all implement some additional formatting ** options that are useful for constructing SQL statements. ** All of the usual printf() formatting options apply. In addition, there @@ -1924,6 +1926,7 @@ void sqlite3_free_table(char **result); char *sqlite3_mprintf(const char*,...); char *sqlite3_vmprintf(const char*, va_list); char *sqlite3_snprintf(int,char*,const char*, ...); +char *sqlite3_vsnprintf(int,char*,const char*, va_list); /* ** CAPI3REF: Memory Allocation Subsystem