]> granicus.if.org Git - php/commitdiff
MFH Add asprintf, use regular system malloc and free and add checks in configure...
authorScott MacVicar <scottmac@php.net>
Thu, 27 Nov 2008 19:45:27 +0000 (19:45 +0000)
committerScott MacVicar <scottmac@php.net>
Thu, 27 Nov 2008 19:45:27 +0000 (19:45 +0000)
configure.in
ext/fileinfo/libmagic/print.c
main/snprintf.c
main/snprintf.h

index dc5658ece4a00bad3a38a228640675666df090a7..d83f01d348ac07df99481a89d42fb99e9711bb65 100644 (file)
@@ -637,6 +637,8 @@ usleep \
 nanosleep \
 utime \
 vsnprintf \
+vasprintf \
+asprintf \
 )
 
 dnl Check for getaddrinfo, should be a better way, but...
index 5a54fb692c478d6399a135cf8f71eebb1e83e839..5edb67f12469b4ca88495615f0723af8d7bf53b0 100644 (file)
@@ -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 *
index dbe7b10023948f7fe72d63259f98c2307bd4b546..ac53a893033e7ed0f17d1d18528ce4a97c5b6864 100644 (file)
@@ -1280,9 +1280,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;
                        }
                }
@@ -1292,6 +1292,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
index c55d5cb35a15a8642ad686bbe9af005fa17df620..0b7470874efff4770a601a2893eeb922144c6099 100644 (file)
@@ -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