Skip to content

Commit

Permalink
Add the sqlite3_vsnprintf() interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown committed Jan 5, 2011
1 parent 4b1a7c7 commit 479523d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/sqlite.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 479523d

Please sign in to comment.