From: Scott MacVicar Date: Thu, 27 Nov 2008 19:45:16 +0000 (+0000) Subject: Add asprintf, use regular system malloc and free and add checks in configure.in for... X-Git-Tag: BEFORE_HEAD_NS_CHANGES_MERGE~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36660c01ab1d18ff52c98517121b95d3118a9116;p=php Add asprintf, use regular system malloc and free and add checks in configure.in for the functions --- diff --git a/configure.in b/configure.in index 76cf9c744c..5453e81a24 100644 --- a/configure.in +++ b/configure.in @@ -637,6 +637,8 @@ usleep \ nanosleep \ utime \ vsnprintf \ +vasprintf \ +asprintf \ ) dnl Check for getaddrinfo, should be a better way, but... diff --git a/ext/fileinfo/libmagic/print.c b/ext/fileinfo/libmagic/print.c index 5a54fb692c..5edb67f124 100644 --- a/ext/fileinfo/libmagic/print.c +++ b/ext/fileinfo/libmagic/print.c @@ -62,7 +62,7 @@ file_magwarn(struct magic_set *ms, const char *f, ...) php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Warning: %s", expanded_format); - efree(expanded_format); + free(expanded_format); } protected const char * diff --git a/main/snprintf.c b/main/snprintf.c index ada64ac268..b00e4c53db 100644 --- a/main/snprintf.c +++ b/main/snprintf.c @@ -1327,9 +1327,9 @@ PHPAPI int ap_php_vasprintf(char **buf, const char *format, va_list ap) /* {{{ * *buf = NULL; if (cc >= 0) { - if ((*buf = emalloc(++cc)) != NULL) { + if ((*buf = malloc(++cc)) != NULL) { if ((cc = ap_php_vsnprintf(*buf, cc, format, ap)) < 0) { - efree(*buf); + free(*buf); *buf = NULL; } } @@ -1339,6 +1339,18 @@ PHPAPI int ap_php_vasprintf(char **buf, const char *format, va_list ap) /* {{{ * } /* }}} */ +PHPAPI int ap_php_asprintf(char **buf, const char *format, ...) /* {{{ */ +{ + int cc; + va_list ap; + + va_start(ap, format); + cc = vasprintf(buf, format, ap); + va_end(ap); + return cc; +} +/* }}} */ + /* * Local variables: * tab-width: 4 diff --git a/main/snprintf.h b/main/snprintf.h index c55d5cb35a..0b7470874e 100644 --- a/main/snprintf.h +++ b/main/snprintf.h @@ -83,6 +83,7 @@ PHPAPI int ap_php_vslprintf(char *buf, size_t len, const char *format, va_list a 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 ap_php_asprintf(char **buf, const char *format, ...); 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, @@ -110,10 +111,13 @@ END_EXTERN_C() #endif #define vsnprintf ap_php_vsnprintf -#ifdef vasprintf -#undef vasprintf -#endif +#ifndef HAVE_VASPRINTF #define vasprintf ap_php_vasprintf +#endif + +#ifndef HAVE_ASPRINTF +#define asprintf ap_php_asprintf +#endif #ifdef sprintf #undef sprintf