[PHP-CVS] cvs: php-src(PHP_5_3) /main snprintf.c snprintf.h
scottmacFri 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.5r2=1.37.2.4.2.14.2.6diff_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.2r2=1.32.2.3.2.5.2.3diff_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.2Thu 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
[PHP-CVS] cvs: php-src(PHP_5_3) /main snprintf.c snprintf.h spprintf.c spprintf.h
helly Thu Feb 7 12:47:44 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/main snprintf.c snprintf.h spprintf.c spprintf.h Log: - MFH WS http://cvs.php.net/viewvc.cgi/php-src/main/snprintf.c?r1=1.37.2.4.2.14.2.2r2=1.37.2.4.2.14.2.3diff_format=u Index: php-src/main/snprintf.c diff -u php-src/main/snprintf.c:1.37.2.4.2.14.2.2 php-src/main/snprintf.c:1.37.2.4.2.14.2.3 --- php-src/main/snprintf.c:1.37.2.4.2.14.2.2 Mon Dec 31 07:17:17 2007 +++ php-src/main/snprintf.c Thu Feb 7 12:47:44 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: snprintf.c,v 1.37.2.4.2.14.2.2 2007/12/31 07:17:17 sebastian Exp $ */ +/* $Id: snprintf.c,v 1.37.2.4.2.14.2.3 2008/02/07 12:47:44 helly Exp $ */ #include php.h @@ -156,7 +156,7 @@ } for (i = 0; i ndigit digits[i] != '\0'; i++); - + if ((decpt = 0 decpt - i 4) || (decpt 0 decpt -3)) { /* use E-style */ /* exponential format (e.g. 1.2345e+13) */ @@ -241,7 +241,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - *notice, this list of conditions and the following disclaimer. + *notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in @@ -327,7 +327,7 @@ *is_negative = (num 0); /* -* On a 2's complement machine, negating the most negative integer +* On a 2's complement machine, negating the most negative integer * results in a number that cannot be represented as a signed integer. * Here is what we do to obtain the number's magnitude: * a. add 1 to the number @@ -344,7 +344,7 @@ } /* -* We use a do-while loop so that we write at least 1 digit +* We use a do-while loop so that we write at least 1 digit */ do { register u_wide_int new_magnitude = magnitude / 10; @@ -763,7 +763,7 @@ fmt++; } /* these are promoted to int, so no break */ - default: + default: modifier = LM_STD; break; } @@ -961,7 +961,7 @@ pad_char = ' '; break; - + case 'f': case 'F': case 'e': @@ -1084,17 +1084,17 @@ goto skip_output; /* -* Always extract the argument as a char * pointer. We -* should be using void * but there are still machines +* Always extract the argument as a char * pointer. We +* should be using void * but there are still machines * that don't understand it. * If the pointer size is equal to the size of an unsigned -* integer we convert the pointer to a hex number, otherwise +* integer we convert the pointer to a hex number, otherwise * we print %p to indicate that we don't handle %p. */ case 'p': if (sizeof(char *) = sizeof(u_wide_int)) { ui_num = (u_wide_int)((size_t) va_arg(ap, char *)); - s = ap_php_conv_p2(ui_num, 4, 'x', + s = ap_php_conv_p2(ui_num, 4, 'x', num_buf[NUM_BUF_SIZE], s_len); if (ui_num != 0) { *--s = 'x'; @@ -1152,7 +1152,7 @@ PAD(min_width, s_len, pad_char); } /* -* Print the string s. +* Print the string s. */ for (i = s_len; i != 0; i--) { INS_CHAR(*s, sp, bep, cc);