PostGIS  2.1.10dev-r@@SVN_REVISION@@
static int stringbuffer_avprintf ( stringbuffer_t s,
const char *  fmt,
va_list  ap 
)
static

Appends a formatted string to the current string buffer, using the format and argument list provided.

Returns -1 on error, check errno for reasons, documented in the printf man page.

Definition at line 198 of file stringbuffer.c.

References stringbuffer_t::capacity, stringbuffer_t::str_end, stringbuffer_t::str_start, stringbuffer_makeroom(), and va_copy.

Referenced by stringbuffer_aprintf().

199 {
200  int maxlen = (s->capacity - (s->str_end - s->str_start));
201  int len = 0; /* Length of the output */
202  va_list ap2;
203 
204  /* Make a copy of the variadic arguments, in case we need to print twice */
205  /* Print to our buffer */
206  va_copy(ap2, ap);
207  len = vsnprintf(s->str_end, maxlen, fmt, ap2);
208  va_end(ap2);
209 
210  /* Propogate errors up */
211  if ( len < 0 )
212  #if defined(__MINGW64_VERSION_MAJOR)
213  len = _vscprintf(fmt, ap2);
214  #else
215  return len;
216  #endif
217 
218  /* We didn't have enough space! */
219  /* Either Unix vsnprint returned write length larger than our buffer */
220  /* or Windows vsnprintf returned an error code. */
221  if ( len >= maxlen )
222  {
223  stringbuffer_makeroom(s, len + 1);
224  maxlen = (s->capacity - (s->str_end - s->str_start));
225 
226  /* Try to print a second time */
227  len = vsnprintf(s->str_end, maxlen, fmt, ap);
228 
229  /* Printing error? Error! */
230  if ( len < 0 ) return len;
231  /* Too long still? Error! */
232  if ( len >= maxlen ) return -1;
233  }
234 
235  /* Move end pointer forward and return. */
236  s->str_end += len;
237  return len;
238 }
tuple fmt
Definition: pixval.py:92
char * str_start
Definition: stringbuffer.h:53
static void stringbuffer_makeroom(stringbuffer_t *s, size_t size_to_add)
If necessary, expand the stringbuffer_t internal buffer to accomodate the specified additional size...
Definition: stringbuffer.c:95
#define va_copy(d, s)
Definition: vsprintf.c:42

Here is the call graph for this function:

Here is the caller graph for this function: