Hello Scott,

  this does not anything we don't have yet. Your vasprintf does exactly the
same as vspprintf. Also the a in the name typically denotes malloc. In fact
there is a vasprintf on several systems which would collide:

ASPRINTF(3)                Linux Programmer's Manual               ASPRINTF(3)

NAME
       asprintf, vasprintf - print to allocated string

SYNOPSIS
       #define _GNU_SOURCE
       #include <stdio.h>

       int asprintf(char **strp, const char *fmt, ...);

       int vasprintf(char **strp, const char *fmt, va_list ap);

DESCRIPTION
       The functions asprintf() and vasprintf() are analogues of sprintf() and
       vsprintf(), except that they allocate a string large enough to hold the
       output  including the terminating null byte, and return a pointer to it
       via the first parameter.  This pointer should be passed to  free(3)  to
       release the allocated storage when it is no longer needed.

RETURN VALUE
       When  successful,  these  functions return the number of bytes printed,
       just like sprintf(3).  If memory allocation wasn't  possible,  or  some
       other error occurs, these functions will return -1, and the contents of
       strp is undefined.

CONFORMING TO
       These functions are GNU extensions, not in C or POSIX.  They  are  also
       available  under *BSD.  The FreeBSD implementation sets strp to NULL on
       error.

SEE ALSO
       free(3), malloc(3), printf(3), feature_test_macros(7)

GNU                               2001-12-18                       ASPRINTF(3)


Thus the proper action is to turn this into malloc rather than emalloc.
Also provide asprintf and add the missing checks for the two library
functions in config.m4, probably in configure.in's AC_CHECK_FUNCS block.

marcus

Friday, November 21, 2008, 10:49:52 PM, you wrote:

> scottmac                Fri Nov 21 21:49:52 2008 UTC

>   Modified files:              
>     /php-src/main       snprintf.c snprintf.h 
>   Log:
>   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.64&r2=1.65&diff_format=u
> Index: php-src/main/snprintf.c
> diff -u php-src/main/snprintf.c:1.64 php-src/main/snprintf.c:1.65
> --- php-src/main/snprintf.c:1.64        Mon Sep 15 11:47:27 2008
> +++ php-src/main/snprintf.c     Fri Nov 21 21:49:52 2008
> @@ -16,7 +16,7 @@
>    +----------------------------------------------------------------------+
>  */
>  
> -/* $Id: snprintf.c,v 1.64 2008/09/15 11:47:27 dmitry Exp $ */
> +/* $Id: snprintf.c,v 1.65 2008/11/21 21:49:52 scottmac Exp $ */
>  
>  
>  #include "php.h"
> @@ -1315,6 +1315,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.42&r2=1.43&diff_format=u
> Index: php-src/main/snprintf.h
> diff -u php-src/main/snprintf.h:1.42 php-src/main/snprintf.h:1.43
> --- php-src/main/snprintf.h:1.42        Thu Feb  7 12:45:42 2008
> +++ php-src/main/snprintf.h     Fri Nov 21 21:49:52 2008
> @@ -17,7 +17,7 @@
>    
> +----------------------------------------------------------------------+
>  */
>  
> -/* $Id: snprintf.h,v 1.42 2008/02/07 12:45:42 helly Exp $ */
> +/* $Id: snprintf.h,v 1.43 2008/11/21 21:49:52 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






Best regards,
 Marcus


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to