PostGIS  3.3.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 179 of file stringbuffer.c.

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

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: