PostGIS  2.4.9dev-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 204 of file stringbuffer.c.

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

Referenced by stringbuffer_aprintf().

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