2 ** The "printf" code that follows dates from the 1980's. It is in
3 ** the public domain. The original comments are included here for
4 ** completeness. They are very out-of-date but might be useful as
5 ** an historical reference. Most of the "enhancements" have been backed
6 ** out so that the functionality is now the same as standard printf().
8 **************************************************************************
10 ** The following modules is an enhanced replacement for the "printf" subroutines
11 ** found in the standard C library. The following enhancements are
14 ** + Additional functions. The standard set of "printf" functions
15 ** includes printf, fprintf, sprintf, vprintf, vfprintf, and
16 ** vsprintf. This module adds the following:
18 ** * snprintf -- Works like sprintf, but has an extra argument
19 ** which is the size of the buffer written to.
21 ** * mprintf -- Similar to sprintf. Writes output to memory
22 ** obtained from malloc.
24 ** * xprintf -- Calls a function to dispose of output.
26 ** * nprintf -- No output, but returns the number of characters
27 ** that would have been output by printf.
29 ** * A v- version (ex: vsnprintf) of every function is also
32 ** + A few extensions to the formatting notation are supported:
34 ** * The "=" flag (similar to "-") causes the output to be
35 ** be centered in the appropriately sized field.
37 ** * The %b field outputs an integer in binary notation.
39 ** * The %c field now accepts a precision. The character output
40 ** is repeated by the number of times the precision specifies.
42 ** * The %' field works like %c, but takes as its character the
43 ** next character of the format string, instead of the next
44 ** argument. For example, printf("%.78'-") prints 78 minus
45 ** signs, the same as printf("%.78c",'-').
47 ** + When compiled using GCC on a SPARC, this version of printf is
48 ** faster than the library printf for SUN OS 4.1.
50 ** + All functions are fully reentrant.
53 #include "sqliteInt.h"
57 ** Conversion types fall into various categories as defined by the
58 ** following enumeration.
60 #define etRADIX 1 /* Integer types. %d, %x, %o, and so forth */
61 #define etFLOAT 2 /* Floating point. %f */
62 #define etEXP 3 /* Exponentional notation. %e and %E */
63 #define etGENERIC 4 /* Floating or exponential, depending on exponent. %g */
64 #define etSIZE 5 /* Return number of characters processed so far. %n */
65 #define etSTRING 6 /* Strings. %s */
66 #define etDYNSTRING 7 /* Dynamically allocated strings. %z */
67 #define etPERCENT 8 /* Percent symbol. %% */
68 #define etCHARX 9 /* Characters. %c */
69 /* The rest are extensions, not normally found in printf() */
70 #define etCHARLIT 10 /* Literal characters. %' */
71 #define etSQLESCAPE 11 /* Strings with '\'' doubled. %q */
72 #define etSQLESCAPE2 12 /* Strings with '\'' doubled and enclosed in '',
73 NULL pointers replaced by SQL NULL. %Q */
74 #define etTOKEN 13 /* a pointer to a Token structure */
75 #define etSRCLIST 14 /* a pointer to a SrcList */
76 #define etPOINTER 15 /* The %p conversion */
77 #define etSQLESCAPE3 16 /* %w -> Strings with '\"' doubled */
81 ** An "etByte" is an 8-bit unsigned value.
83 typedef unsigned char etByte;
86 ** Each builtin conversion character (ex: the 'd' in "%d") is described
87 ** by an instance of the following structure
89 typedef struct et_info { /* Information about each format field */
90 char fmttype; /* The format field code letter */
91 etByte base; /* The base for radix conversion */
92 etByte flags; /* One or more of FLAG_ constants below */
93 etByte type; /* Conversion paradigm */
94 etByte charset; /* Offset into aDigits[] of the digits string */
95 etByte prefix; /* Offset into aPrefix[] of the prefix string */
99 ** Allowed values for et_info.flags
101 #define FLAG_SIGNED 1 /* True if the value to convert is signed */
102 #define FLAG_INTERN 2 /* True if for internal use only */
103 #define FLAG_STRING 4 /* Allow infinity precision */
107 ** The following table is searched linearly, so it is good to put the
108 ** most frequently used conversion types first.
110 static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
111 static const char aPrefix[] = "-x0\000X0";
112 static const et_info fmtinfo[] = {
113 { 'd', 10, 1, etRADIX, 0, 0 },
114 { 's', 0, 4, etSTRING, 0, 0 },
115 { 'g', 0, 1, etGENERIC, 30, 0 },
116 { 'z', 0, 4, etDYNSTRING, 0, 0 },
117 { 'q', 0, 4, etSQLESCAPE, 0, 0 },
118 { 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
119 { 'w', 0, 4, etSQLESCAPE3, 0, 0 },
120 { 'c', 0, 0, etCHARX, 0, 0 },
121 { 'o', 8, 0, etRADIX, 0, 2 },
122 { 'u', 10, 0, etRADIX, 0, 0 },
123 { 'x', 16, 0, etRADIX, 16, 1 },
124 { 'X', 16, 0, etRADIX, 0, 4 },
125 #ifndef SQLITE_OMIT_FLOATING_POINT
126 { 'f', 0, 1, etFLOAT, 0, 0 },
127 { 'e', 0, 1, etEXP, 30, 0 },
128 { 'E', 0, 1, etEXP, 14, 0 },
129 { 'G', 0, 1, etGENERIC, 14, 0 },
131 { 'i', 10, 1, etRADIX, 0, 0 },
132 { 'n', 0, 0, etSIZE, 0, 0 },
133 { '%', 0, 0, etPERCENT, 0, 0 },
134 { 'p', 16, 0, etPOINTER, 0, 1 },
135 { 'T', 0, 2, etTOKEN, 0, 0 },
136 { 'S', 0, 2, etSRCLIST, 0, 0 },
138 #define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
141 ** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
142 ** conversions will work.
144 #ifndef SQLITE_OMIT_FLOATING_POINT
146 ** "*val" is a double such that 0.1 <= *val < 10.0
147 ** Return the ascii code for the leading digit of *val, then
148 ** multiply "*val" by 10.0 to renormalize.
151 ** input: *val = 3.14159
152 ** output: *val = 1.4159 function return = '3'
154 ** The counter *cnt is incremented each time. After counter exceeds
155 ** 16 (the number of significant digits in a 64-bit float) '0' is
158 static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
161 if( (*cnt)++ >= 16 ) return '0';
165 *val = (*val - d)*10.0;
168 #endif /* SQLITE_OMIT_FLOATING_POINT */
171 ** On machines with a small stack size, you can redefine the
172 ** SQLITE_PRINT_BUF_SIZE to be less than 350. But beware - for
173 ** smaller values some %f conversions may go into an infinite loop.
175 #ifndef SQLITE_PRINT_BUF_SIZE
176 # define SQLITE_PRINT_BUF_SIZE 350
178 #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
181 ** The root program. All variations call this core.
184 ** func This is a pointer to a function taking three arguments
185 ** 1. A pointer to anything. Same as the "arg" parameter.
186 ** 2. A pointer to the list of characters to be output
187 ** (Note, this list is NOT null terminated.)
188 ** 3. An integer number of characters to be output.
189 ** (Note: This number might be zero.)
191 ** arg This is the pointer to anything which will be passed as the
192 ** first argument to "func". Use it for whatever you like.
194 ** fmt This is the format string, as in the usual print.
196 ** ap This is a pointer to a list of arguments. Same as in
200 ** The return value is the total number of characters sent to
201 ** the function "func". Returns -1 on a error.
203 ** Note that the order in which automatic variables are declared below
204 ** seems to make a big difference in determining how fast this beast
208 void (*func)(void*,const char*,int), /* Consumer of text */
209 void *arg, /* First argument to the consumer */
210 int useExtended, /* Allow extended %-conversions */
211 const char *fmt, /* Format string */
212 va_list ap /* arguments */
214 int c; /* Next character in the format string */
215 char *bufpt; /* Pointer to the conversion buffer */
216 int precision; /* Precision of the current field */
217 int length; /* Length of the field */
218 int idx; /* A general purpose loop counter */
219 int count; /* Total number of characters output */
220 int width; /* Width of the current field */
221 etByte flag_leftjustify; /* True if "-" flag is present */
222 etByte flag_plussign; /* True if "+" flag is present */
223 etByte flag_blanksign; /* True if " " flag is present */
224 etByte flag_alternateform; /* True if "#" flag is present */
225 etByte flag_altform2; /* True if "!" flag is present */
226 etByte flag_zeropad; /* True if field width constant starts with zero */
227 etByte flag_long; /* True if "l" flag is present */
228 etByte flag_longlong; /* True if the "ll" flag is present */
229 etByte done; /* Loop termination flag */
230 sqlite_uint64 longvalue; /* Value for integer types */
231 LONGDOUBLE_TYPE realvalue; /* Value for real types */
232 const et_info *infop; /* Pointer to the appropriate info structure */
233 char buf[etBUFSIZE]; /* Conversion buffer */
234 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
235 etByte errorflag = 0; /* True if an error is encountered */
236 etByte xtype; /* Conversion paradigm */
237 char *zExtra; /* Extra memory used for etTCLESCAPE conversions */
238 static const char spaces[] =
240 #define etSPACESIZE (sizeof(spaces)-1)
241 #ifndef SQLITE_OMIT_FLOATING_POINT
242 int exp, e2; /* exponent of real numbers */
243 double rounder; /* Used for rounding floating point values */
244 etByte flag_dp; /* True if decimal point should be shown */
245 etByte flag_rtz; /* True if trailing zeros should be removed */
246 etByte flag_exp; /* True to force display of the exponent */
247 int nsd; /* Number of significant digits returned */
253 for(; (c=(*fmt))!=0; ++fmt){
258 while( (c=(*++fmt))!='%' && c!=0 ) amt++;
259 (*func)(arg,bufpt,amt);
263 if( (c=(*++fmt))==0 ){
269 /* Find out what flags are present */
270 flag_leftjustify = flag_plussign = flag_blanksign =
271 flag_alternateform = flag_altform2 = flag_zeropad = 0;
275 case '-': flag_leftjustify = 1; break;
276 case '+': flag_plussign = 1; break;
277 case ' ': flag_blanksign = 1; break;
278 case '#': flag_alternateform = 1; break;
279 case '!': flag_altform2 = 1; break;
280 case '0': flag_zeropad = 1; break;
281 default: done = 1; break;
283 }while( !done && (c=(*++fmt))!=0 );
284 /* Get the field width */
287 width = va_arg(ap,int);
289 flag_leftjustify = 1;
294 while( c>='0' && c<='9' ){
295 width = width*10 + c - '0';
299 if( width > etBUFSIZE-10 ){
300 width = etBUFSIZE-10;
302 /* Get the precision */
307 precision = va_arg(ap,int);
308 if( precision<0 ) precision = -precision;
311 while( c>='0' && c<='9' ){
312 precision = precision*10 + c - '0';
319 /* Get the conversion type modifier */
330 flag_long = flag_longlong = 0;
332 /* Fetch the info entry for the field */
334 for(idx=0; idx<etNINFO; idx++){
335 if( c==fmtinfo[idx].fmttype ){
336 infop = &fmtinfo[idx];
337 if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
351 /* Limit the precision to prevent overflowing buf[] during conversion */
352 if( precision>etBUFSIZE-40 && (infop->flags & FLAG_STRING)==0 ){
353 precision = etBUFSIZE-40;
357 ** At this point, variables are initialized as follows:
359 ** flag_alternateform TRUE if a '#' is present.
360 ** flag_altform2 TRUE if a '!' is present.
361 ** flag_plussign TRUE if a '+' is present.
362 ** flag_leftjustify TRUE if a '-' is present or if the
363 ** field width was negative.
364 ** flag_zeropad TRUE if the width began with 0.
365 ** flag_long TRUE if the letter 'l' (ell) prefixed
366 ** the conversion character.
367 ** flag_longlong TRUE if the letter 'll' (ell ell) prefixed
368 ** the conversion character.
369 ** flag_blanksign TRUE if a ' ' is present.
370 ** width The specified field width. This is
371 ** always non-negative. Zero is the default.
372 ** precision The specified precision. The default
374 ** xtype The class of the conversion.
375 ** infop Pointer to the appropriate info struct.
379 flag_longlong = sizeof(char*)==sizeof(i64);
380 flag_long = sizeof(char*)==sizeof(long int);
381 /* Fall through into the next case */
383 if( infop->flags & FLAG_SIGNED ){
385 if( flag_longlong ) v = va_arg(ap,i64);
386 else if( flag_long ) v = va_arg(ap,long int);
387 else v = va_arg(ap,int);
393 if( flag_plussign ) prefix = '+';
394 else if( flag_blanksign ) prefix = ' ';
398 if( flag_longlong ) longvalue = va_arg(ap,u64);
399 else if( flag_long ) longvalue = va_arg(ap,unsigned long int);
400 else longvalue = va_arg(ap,unsigned int);
403 if( longvalue==0 ) flag_alternateform = 0;
404 if( flag_zeropad && precision<width-(prefix!=0) ){
405 precision = width-(prefix!=0);
407 bufpt = &buf[etBUFSIZE-1];
409 register const char *cset; /* Use registers for speed */
411 cset = &aDigits[infop->charset];
413 do{ /* Convert to ascii */
414 *(--bufpt) = cset[longvalue%base];
415 longvalue = longvalue/base;
416 }while( longvalue>0 );
418 length = &buf[etBUFSIZE-1]-bufpt;
419 for(idx=precision-length; idx>0; idx--){
420 *(--bufpt) = '0'; /* Zero pad */
422 if( prefix ) *(--bufpt) = prefix; /* Add sign */
423 if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */
426 pre = &aPrefix[infop->prefix];
427 if( *bufpt!=pre[0] ){
428 for(; (x=(*pre))!=0; pre++) *(--bufpt) = x;
431 length = &buf[etBUFSIZE-1]-bufpt;
436 realvalue = va_arg(ap,double);
437 #ifndef SQLITE_OMIT_FLOATING_POINT
438 if( precision<0 ) precision = 6; /* Set default precision */
439 if( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10;
441 realvalue = -realvalue;
444 if( flag_plussign ) prefix = '+';
445 else if( flag_blanksign ) prefix = ' ';
448 if( xtype==etGENERIC && precision>0 ) precision--;
450 /* Rounding works like BSD when the constant 0.4999 is used. Wierd! */
451 for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1);
453 /* It makes more sense to use 0.5 */
454 for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1){}
456 if( xtype==etFLOAT ) realvalue += rounder;
457 /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
459 if( sqlite3_isnan(realvalue) ){
465 while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
466 while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
467 while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
468 while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
469 while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
470 if( exp>350 || exp<-350 ){
473 }else if( prefix=='+' ){
478 length = strlen(bufpt);
484 ** If the field type is etGENERIC, then convert to either etEXP
485 ** or etFLOAT, as appropriate.
487 flag_exp = xtype==etEXP;
488 if( xtype!=etFLOAT ){
489 realvalue += rounder;
490 if( realvalue>=10.0 ){ realvalue *= 0.1; exp++; }
492 if( xtype==etGENERIC ){
493 flag_rtz = !flag_alternateform;
494 if( exp<-4 || exp>precision ){
497 precision = precision - exp;
509 flag_dp = (precision>0) | flag_alternateform | flag_altform2;
510 /* The sign in front of the number */
514 /* Digits prior to the decimal point */
519 *(bufpt++) = et_getdigit(&realvalue,&nsd);
522 /* The decimal point */
526 /* "0" digits after the decimal point but before the first
527 ** significant digit of the number */
528 for(e2++; e2<0 && precision>0; precision--, e2++){
531 /* Significant digits after the decimal point */
532 while( (precision--)>0 ){
533 *(bufpt++) = et_getdigit(&realvalue,&nsd);
535 /* Remove trailing zeros and the "." if no digits follow the "." */
536 if( flag_rtz && flag_dp ){
537 while( bufpt[-1]=='0' ) *(--bufpt) = 0;
539 if( bufpt[-1]=='.' ){
547 /* Add the "eNNN" suffix */
548 if( flag_exp || (xtype==etEXP && exp) ){
549 *(bufpt++) = aDigits[infop->charset];
551 *(bufpt++) = '-'; exp = -exp;
556 *(bufpt++) = (exp/100)+'0'; /* 100's digit */
559 *(bufpt++) = exp/10+'0'; /* 10's digit */
560 *(bufpt++) = exp%10+'0'; /* 1's digit */
564 /* The converted number is in buf[] and zero terminated. Output it.
565 ** Note that the number is in the usual order, not reversed as with
566 ** integer conversions. */
570 /* Special case: Add leading zeros if the flag_zeropad flag is
571 ** set and we are not left justified */
572 if( flag_zeropad && !flag_leftjustify && length < width){
574 int nPad = width - length;
575 for(i=width; i>=nPad; i--){
576 bufpt[i] = bufpt[i-nPad];
579 while( nPad-- ) bufpt[i++] = '0';
585 *(va_arg(ap,int*)) = count;
595 c = buf[0] = (xtype==etCHARX ? va_arg(ap,int) : *++fmt);
597 for(idx=1; idx<precision; idx++) buf[idx] = c;
606 bufpt = va_arg(ap,char*);
609 }else if( xtype==etDYNSTRING ){
612 length = strlen(bufpt);
613 if( precision>=0 && precision<length ) length = precision;
618 int i, j, n, ch, isnull;
620 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
621 char *escarg = va_arg(ap,char*);
623 if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
624 for(i=n=0; (ch=escarg[i])!=0; i++){
627 needQuote = !isnull && xtype==etSQLESCAPE2;
628 n += i + 1 + needQuote*2;
630 bufpt = zExtra = sqlite3_malloc( n );
631 if( bufpt==0 ) return -1;
636 if( needQuote ) bufpt[j++] = q;
637 for(i=0; (ch=escarg[i])!=0; i++){
639 if( ch==q ) bufpt[j++] = ch;
641 if( needQuote ) bufpt[j++] = q;
644 /* The precision is ignored on %q and %Q */
645 /* if( precision>=0 && precision<length ) length = precision; */
649 Token *pToken = va_arg(ap, Token*);
650 if( pToken && pToken->z ){
651 (*func)(arg, (char*)pToken->z, pToken->n);
657 SrcList *pSrc = va_arg(ap, SrcList*);
658 int k = va_arg(ap, int);
659 struct SrcList_item *pItem = &pSrc->a[k];
660 assert( k>=0 && k<pSrc->nSrc );
661 if( pItem->zDatabase && pItem->zDatabase[0] ){
662 (*func)(arg, pItem->zDatabase, strlen(pItem->zDatabase));
663 (*func)(arg, ".", 1);
665 (*func)(arg, pItem->zName, strlen(pItem->zName));
669 }/* End switch over the format type */
671 ** The text of the conversion is pointed to by "bufpt" and is
672 ** "length" characters long. The field width is "width". Do
675 if( !flag_leftjustify ){
677 nspace = width-length;
680 while( nspace>=etSPACESIZE ){
681 (*func)(arg,spaces,etSPACESIZE);
682 nspace -= etSPACESIZE;
684 if( nspace>0 ) (*func)(arg,spaces,nspace);
688 (*func)(arg,bufpt,length);
691 if( flag_leftjustify ){
693 nspace = width-length;
696 while( nspace>=etSPACESIZE ){
697 (*func)(arg,spaces,etSPACESIZE);
698 nspace -= etSPACESIZE;
700 if( nspace>0 ) (*func)(arg,spaces,nspace);
704 sqlite3_free(zExtra);
706 }/* End for loop over the format string */
707 return errorflag ? -1 : count;
708 } /* End of function */
711 /* This structure is used to store state information about the
712 ** write to memory that is currently in progress.
715 char *zBase; /* A base allocation */
716 char *zText; /* The string collected so far */
717 int nChar; /* Length of the string so far */
718 int nTotal; /* Output size if unconstrained */
719 int nAlloc; /* Amount of space allocated in zText */
720 void *(*xRealloc)(void*,int); /* Function used to realloc memory */
721 int iMallocFailed; /* True if xRealloc() has failed */
725 ** This function implements the callback from vxprintf.
727 ** This routine add nNewChar characters of text in zNewText to
728 ** the sgMprintf structure pointed to by "arg".
730 static void mout(void *arg, const char *zNewText, int nNewChar){
731 struct sgMprintf *pM = (struct sgMprintf*)arg;
732 if( pM->iMallocFailed ) return;
733 pM->nTotal += nNewChar;
735 if( pM->nChar + nNewChar + 1 > pM->nAlloc ){
736 if( pM->xRealloc==0 ){
737 nNewChar = pM->nAlloc - pM->nChar - 1;
739 int nAlloc = pM->nChar + nNewChar*2 + 1;
740 if( pM->zText==pM->zBase ){
741 pM->zText = pM->xRealloc(0, nAlloc);
744 pM->iMallocFailed = 1;
746 }else if( pM->nChar ){
747 memcpy(pM->zText, pM->zBase, pM->nChar);
751 zNew = pM->xRealloc(pM->zText, nAlloc);
755 pM->iMallocFailed = 1;
756 pM->xRealloc(pM->zText, 0);
766 memcpy(&pM->zText[pM->nChar], zNewText, nNewChar);
767 pM->nChar += nNewChar;
769 pM->zText[pM->nChar] = 0;
774 ** This routine is a wrapper around xprintf() that invokes mout() as
777 static char *base_vprintf(
778 void *(*xRealloc)(void*, int), /* realloc() function. May be NULL */
779 int useInternal, /* Use internal %-conversions if true */
780 char *zInitBuf, /* Initially write here, before mallocing */
781 int nInitBuf, /* Size of zInitBuf[] */
782 const char *zFormat, /* format string */
783 va_list ap /* arguments */
786 sM.zBase = sM.zText = zInitBuf;
787 sM.nChar = sM.nTotal = 0;
788 sM.nAlloc = nInitBuf;
789 sM.xRealloc = xRealloc;
790 sM.iMallocFailed = 0;
791 vxprintf(mout, &sM, useInternal, zFormat, ap);
792 assert(sM.iMallocFailed==0 || sM.zText==0);
793 if( xRealloc && !sM.iMallocFailed ){
794 if( sM.zText==sM.zBase ){
795 sM.zText = xRealloc(0, sM.nChar+1);
797 memcpy(sM.zText, sM.zBase, sM.nChar+1);
799 }else if( sM.nAlloc>sM.nChar+10 ){
801 sqlite3MallocBenignFailure(1);
802 zNew = xRealloc(sM.zText, sM.nChar+1);
812 ** Realloc that is a real function, not a macro.
814 static void *printf_realloc(void *old, int size){
815 return sqlite3_realloc(old, size);
819 ** Print into memory obtained from sqliteMalloc(). Use the internal
820 ** %-conversion extensions.
822 char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
824 char zBase[SQLITE_PRINT_BUF_SIZE];
825 z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
827 db->mallocFailed = 1;
833 ** Print into memory obtained from sqliteMalloc(). Use the internal
834 ** %-conversion extensions.
836 char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){
839 char zBase[SQLITE_PRINT_BUF_SIZE];
840 va_start(ap, zFormat);
841 z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
844 db->mallocFailed = 1;
850 ** Print into memory obtained from sqlite3_malloc(). Omit the internal
851 ** %-conversion extensions.
853 char *sqlite3_vmprintf(const char *zFormat, va_list ap){
854 char zBase[SQLITE_PRINT_BUF_SIZE];
855 return base_vprintf(sqlite3_realloc, 0, zBase, sizeof(zBase), zFormat, ap);
859 ** Print into memory obtained from sqlite3_malloc()(). Omit the internal
860 ** %-conversion extensions.
862 char *sqlite3_mprintf(const char *zFormat, ...){
865 va_start(ap, zFormat);
866 z = sqlite3_vmprintf(zFormat, ap);
872 ** sqlite3_snprintf() works like snprintf() except that it ignores the
873 ** current locale settings. This is important for SQLite because we
874 ** are not able to use a "," as the decimal point in place of "." as
875 ** specified by some locales.
877 char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
885 va_start(ap,zFormat);
886 z = base_vprintf(0, 0, zBuf, n, zFormat, ap);
891 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) || defined(SQLITE_MEMDEBUG)
893 ** A version of printf() that understands %lld. Used for debugging.
894 ** The printf() built into some versions of windows does not understand %lld
895 ** and segfaults if you give it a long long int.
897 void sqlite3DebugPrintf(const char *zFormat, ...){
898 extern int getpid(void);
901 va_start(ap, zFormat);
902 base_vprintf(0, 0, zBuf, sizeof(zBuf), zFormat, ap);
904 fprintf(stdout,"%s", zBuf);