version 1.140, 2014/06/14 16:14:04
|
version 1.141, 2014/07/17 19:55:40
|
|
|
return p - (Uint8*)dest; | return p - (Uint8*)dest; |
} | } |
| |
// Function to return a formatted char* from a va_list. |
|
// Allocates space for the returned char* and repeats the |
|
// build process until the allocated space is large enough |
|
// to hold the result. This is internal only and the core function |
|
// used by stringPrintf and stringVPrintf |
|
|
|
static char* _charVPrintf(const char* format, va_list ap) |
|
{ |
|
// Iniitial allocation size. This is a guess assuming that |
|
// most printfs are one or two lines long |
|
int allocSize = 256; |
|
|
|
int rtnSize; |
|
char *p; |
|
|
|
// initial allocate for output |
|
if ((p = (char*)malloc(allocSize)) == NULL) |
|
{ |
|
return 0; |
|
} |
|
|
|
// repeat formatting with increased realloc until it works. |
|
do |
|
{ |
|
rtnSize = vsnprintf(p, allocSize, format, ap); |
|
|
|
// return if successful if not negative and |
|
// returns less than allocated size. |
|
if (rtnSize > -1 && rtnSize < allocSize) |
|
{ |
|
return p; |
|
} |
|
|
|
// increment alloc size. Assumes that positive return is |
|
// expected size and negative is error. |
|
allocSize = (rtnSize > -1)? (rtnSize + 1) : allocSize * 2; |
|
|
|
} while((p = (char*)peg_inln_realloc(p, allocSize)) != NULL); |
|
|
|
// return error code if realloc failed |
|
return 0; |
|
} |
|
|
|
//============================================================================== | //============================================================================== |
// | // |
// class CString | // class CString |