PostGIS  3.0.6dev-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 168 of file stringbuffer.c.

169 {
170  int maxlen = (s->capacity - (s->str_end - s->str_start));
171  int len = 0; /* Length of the output */
172  va_list ap2;
173 
174  /* Make a copy of the variadic arguments, in case we need to print twice */
175  /* Print to our buffer */
176  va_copy(ap2, ap);
177  len = vsnprintf(s->str_end, maxlen, fmt, ap2);
178  va_end(ap2);
179 
180  /* Propogate errors up */
181  if ( len < 0 )
182  #if defined(__MINGW64_VERSION_MAJOR)
183  len = _vscprintf(fmt, ap2);
184  #else
185  return len;
186  #endif
187 
188  /* We didn't have enough space! */
189  /* Either Unix vsnprint returned write length larger than our buffer */
190  /* or Windows vsnprintf returned an error code. */
191  if ( len >= maxlen )
192  {
193  stringbuffer_makeroom(s, len + 1);
194  maxlen = (s->capacity - (s->str_end - s->str_start));
195 
196  /* Try to print a second time */
197  len = vsnprintf(s->str_end, maxlen, fmt, ap);
198 
199  /* Printing error? Error! */
200  if ( len < 0 ) return len;
201  /* Too long still? Error! */
202  if ( len >= maxlen ) return -1;
203  }
204 
205  /* Move end pointer forward and return. */
206  s->str_end += len;
207  return len;
208 }
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:68

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: