+ if (!(p = malloc(size))) {
+ *destp = NULL;
+ return(-1);
+ }
+ for (;;) {
+ /* Try to print in the allocated space. */
+ n = gvsprintf(p, size, fmt, ap);
+ /* If that worked, return the string. */
+ if (n > -1 && n < size) {
+ *destp = p;
+ return(n);
+ }
+ /* Else try again with more space. */
+ if (n > -1) /* glibc 2.1 */
+ size = n + 1; /* precisely what is needed */
+ else /* glibc 2.0 */
+ size *= 2; /* twice the old size */
+ if (!(pnew = realloc(p, size))) {
+ free(p);
+ *destp = NULL;
+ return(-1);
+ }
+ p = pnew;
+ }
+}
+#endif
+
+#ifndef HAVE_ASPRINTF
+int gasprintf(char **destp, const char *fmt,...)
+{
+ va_list ap;
+ int r;
+
+ va_start(ap,fmt);
+ r = gvasprintf(destp, fmt, ap);
+ va_end(ap);
+ return(r);
+}
+#endif