PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ stringbuffer_avprintf()

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 197 of file stringbuffer.c.

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

Referenced by stringbuffer_aprintf().

198 {
199  int maxlen = (s->capacity - (s->str_end - s->str_start));
200  int len = 0; /* Length of the output */
201  va_list ap2;
202 
203  /* Make a copy of the variadic arguments, in case we need to print twice */
204  /* Print to our buffer */
205  va_copy(ap2, ap);
206  len = vsnprintf(s->str_end, maxlen, fmt, ap2);
207  va_end(ap2);
208 
209  /* Propogate errors up */
210  if ( len < 0 )
211  #if defined(__MINGW64_VERSION_MAJOR)
212  len = _vscprintf(fmt, ap2);
213  #else
214  return len;
215  #endif
216 
217  /* We didn't have enough space! */
218  /* Either Unix vsnprint returned write length larger than our buffer */
219  /* or Windows vsnprintf returned an error code. */
220  if ( len >= maxlen )
221  {
222  stringbuffer_makeroom(s, len + 1);
223  maxlen = (s->capacity - (s->str_end - s->str_start));
224 
225  /* Try to print a second time */
226  len = vsnprintf(s->str_end, maxlen, fmt, ap);
227 
228  /* Printing error? Error! */
229  if ( len < 0 ) return len;
230  /* Too long still? Error! */
231  if ( len >= maxlen ) return -1;
232  }
233 
234  /* Move end pointer forward and return. */
235  s->str_end += len;
236  return len;
237 }
def fmt
Definition: pixval.py:92
char * str_start
Definition: stringbuffer.h:52
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:94
Here is the call graph for this function:
Here is the caller graph for this function: