On Fri, Feb 16, 2007 at 04:57:15PM -0800, Ben Pfaff wrote:
> RCS file: /sources/gnulib/gnulib/m4/vsnprintf.m4,v
> retrieving revision 1.2
> diff -u -p -r1.2 vsnprintf.m4
> --- m4/vsnprintf.m4   23 Jan 2005 08:06:57 -0000      1.2
> +++ m4/vsnprintf.m4   17 Feb 2007 00:56:09 -0000
> @@ -1,12 +1,27 @@
> -# vsnprintf.m4 serial 2
> -dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
> +# vsnprintf.m4 serial 3
> +dnl Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
>  dnl This file is free software; the Free Software Foundation
>  dnl gives unlimited permission to copy and/or distribute it,
>  dnl with or without modifications, as long as this notice is preserved.
>  
>  AC_DEFUN([gl_FUNC_VSNPRINTF],
>  [
> -  AC_REPLACE_FUNCS(vsnprintf)
> +  AC_REQUIRE([gl_AC_NATIVE_W32])
> +  AC_CHECK_FUNCS_ONCE(vsnprintf)
> +  AC_MSG_CHECKING([for C99-compliant vsnprintf])
> +  if test $ac_cv_func_vsnprintf = no || test $gl_cv_native_w32 = yes; then
> +    AC_LIBOBJ(vsnprintf)
> +    AC_DEFINE(vsnprintf, rpl_vsnprintf,
> +      [Define to rpl_vsnprintf if the replacement function should be used.])
> +    AC_MSG_RESULT([no])
> +  else
> +    AC_MSG_RESULT([yes])
> +  fi
> +  if test $gl_cv_native_w32 = yes; then
> +    AC_LIBOBJ(_vsnprintf)
> +    AC_DEFINE(_vsnprintf, rpl__vsnprintf,
> +      [Define to rpl__vsnprintf if the replacement function should be used.])
> +  fi
>    AC_CHECK_DECLS_ONCE(vsnprintf)
>    gl_PREREQ_VSNPRINTF
>  ])

Huh? So, if vsnprintf() exists, you assume it's C99-compliant? glib
has a check for this, AC_FUNC_VSNPRINTF_C99, because that's not the
case on some systems. And, we found that Solaris and AIX 5.1 do not
have a C99-compliant vsnprintf(). The attached program returns -1 on
Solaris 6/SPARC thru Solaris 9/SPARC which has vsnprintf(), for
example.

-- 
albert chin ([EMAIL PROTECTED])
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

int
doit(char * s, ...)
{
  char buffer[32];
  va_list args;
  int r;

  /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
     implementation. The above will return 7 but if you replace
     the size of the buffer with 0, it borks! */
  va_start(args, s);
  r = vsnprintf(buffer, 0, s, args);
  va_end(args);
printf("r: %d\n", r);

  if (r != 7)
    exit(1);

  exit(0);
}

int
main(void)
{
  doit("1234567");
  exit(1);
}

Reply via email to