PostGIS  3.1.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 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  len = _vscprintf(fmt, ap2);
195  #else
196  return len;
197  #endif
198 
199  /* We didn't have enough space! */
200  /* Either Unix vsnprint returned write length larger than our buffer */
201  /* or Windows vsnprintf returned an error code. */
202  if ( len >= maxlen )
203  {
204  stringbuffer_makeroom(s, len + 1);
205  maxlen = (s->capacity - (s->str_end - s->str_start));
206 
207  /* Try to print a second time */
208  len = vsnprintf(s->str_end, maxlen, fmt, ap);
209 
210  /* Printing error? Error! */
211  if ( len < 0 ) return len;
212  /* Too long still? Error! */
213  if ( len >= maxlen ) return -1;
214  }
215 
216  /* Move end pointer forward and return. */
217  s->str_end += len;
218  return len;
219 }
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: