PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ stringbuffer_avprintf()

static int 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 201 of file stringbuffer.c.

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

References pixval::fmt, s, and stringbuffer_makeroom().

Referenced by stringbuffer_aprintf().

Here is the call graph for this function:
Here is the caller graph for this function: