summaryrefslogtreecommitdiff
path: root/main/snprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/snprintf.c')
-rw-r--r--main/snprintf.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/main/snprintf.c b/main/snprintf.c
index 81998cf970..dbe7b10023 100644
--- a/main/snprintf.c
+++ b/main/snprintf.c
@@ -1268,6 +1268,30 @@ PHPAPI int ap_php_vsnprintf(char *buf, size_t len, const char *format, va_list a
}
/* }}} */
+PHPAPI int ap_php_vasprintf(char **buf, const char *format, va_list ap) /* {{{ */
+{
+ va_list ap2;
+ int cc;
+
+ va_copy(ap2, ap);
+ cc = ap_php_vsnprintf(NULL, 0, format, ap2);
+ va_end(ap2);
+
+ *buf = NULL;
+
+ if (cc >= 0) {
+ if ((*buf = emalloc(++cc)) != NULL) {
+ if ((cc = ap_php_vsnprintf(*buf, cc, format, ap)) < 0) {
+ efree(*buf);
+ *buf = NULL;
+ }
+ }
+ }
+
+ return cc;
+}
+/* }}} */
+
/*
* Local variables:
* tab-width: 4