PostGIS  3.4.0dev-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 196 of file stringbuffer.c.

197 {
198  int maxlen = (s->capacity - (s->str_end - s->str_start));
199  int len = 0; /* Length of the output */
200  va_list ap2;
201 
202  /* Make a copy of the variadic arguments, in case we need to print twice */
203  /* Print to our buffer */
204  va_copy(ap2, ap);
205  len = vsnprintf(s->str_end, maxlen, fmt, ap2);
206  va_end(ap2);
207 
208  /* Propogate errors up */
209  if ( len < 0 )
210  #if defined(__MINGW64_VERSION_MAJOR)
211  va_copy(ap2, ap);
212  len = _vscprintf(fmt, ap2);
213  va_end(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 }
char * s
Definition: cu_in_wkt.c:23
def fmt
Definition: pixval.py:93
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: