scottmac Fri Nov 21 22:05:03 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src/main snprintf.c snprintf.h
Log:
MFH Add vasprintf() so the buffer can be automatically calculated, you need
to efree this when done though!
http://cvs.php.net/viewvc.cgi/php-src/main/snprintf.c?r1=1.37.2.4.2.14.2.5&r2=1.37.2.4.2.14.2.6&diff_format=u
Index: php-src/main/snprintf.c
diff -u php-src/main/snprintf.c:1.37.2.4.2.14.2.5
php-src/main/snprintf.c:1.37.2.4.2.14.2.6
--- php-src/main/snprintf.c:1.37.2.4.2.14.2.5 Mon Sep 15 11:47:16 2008
+++ php-src/main/snprintf.c Fri Nov 21 22:05:03 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: snprintf.c,v 1.37.2.4.2.14.2.5 2008/09/15 11:47:16 dmitry Exp $ */
+/* $Id: snprintf.c,v 1.37.2.4.2.14.2.6 2008/11/21 22:05:03 scottmac Exp $ */
#include "php.h"
@@ -1268,6 +1268,30 @@
}
/* }}} */
+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
http://cvs.php.net/viewvc.cgi/php-src/main/snprintf.h?r1=1.32.2.3.2.5.2.2&r2=1.32.2.3.2.5.2.3&diff_format=u
Index: php-src/main/snprintf.h
diff -u php-src/main/snprintf.h:1.32.2.3.2.5.2.2
php-src/main/snprintf.h:1.32.2.3.2.5.2.3
--- php-src/main/snprintf.h:1.32.2.3.2.5.2.2 Thu Feb 7 12:47:44 2008
+++ php-src/main/snprintf.h Fri Nov 21 22:05:03 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: snprintf.h,v 1.32.2.3.2.5.2.2 2008/02/07 12:47:44 helly Exp $ */
+/* $Id: snprintf.h,v 1.32.2.3.2.5.2.3 2008/11/21 22:05:03 scottmac Exp $ */
/*
@@ -82,6 +82,7 @@
PHPAPI int ap_php_vslprintf(char *buf, size_t len, const char *format, va_list
ap);
PHPAPI int ap_php_snprintf(char *, size_t, const char *, ...);
PHPAPI int ap_php_vsnprintf(char *, size_t, const char *, va_list ap);
+PHPAPI int ap_php_vasprintf(char **buf, const char *format, va_list ap);
PHPAPI int php_sprintf (char* s, const char* format, ...)
PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
PHPAPI char * php_gcvt(double value, int ndigit, char dec_point, char
exponent, char *buf);
PHPAPI char * php_conv_fp(register char format, register double num,
@@ -109,6 +110,11 @@
#endif
#define vsnprintf ap_php_vsnprintf
+#ifdef vasprintf
+#undef vasprintf
+#endif
+#define vasprintf ap_php_vasprintf
+
#ifdef sprintf
#undef sprintf
#endif
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php