diff options
author | Scott MacVicar <scottmac@php.net> | 2008-11-21 22:05:03 +0000 |
---|---|---|
committer | Scott MacVicar <scottmac@php.net> | 2008-11-21 22:05:03 +0000 |
commit | bfbe9a34ab0cc9c59e3c1a31317ad9fa44cd98c0 (patch) | |
tree | 6190cc367c42d76c9813dd0dfe8c61c424222cf5 /main/snprintf.c | |
parent | a7dc862b6dd47035846c4221cb4e3eccf171b8ea (diff) | |
download | php-git-bfbe9a34ab0cc9c59e3c1a31317ad9fa44cd98c0.tar.gz |
MFH Add vasprintf() so the buffer can be automatically calculated, you need to efree this when done though!
Diffstat (limited to 'main/snprintf.c')
-rw-r--r-- | main/snprintf.c | 24 |
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 |