bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new module 'vsprintf-posix'


From: Bruno Haible
Subject: new module 'vsprintf-posix'
Date: Wed, 7 Mar 2007 04:26:24 +0100
User-agent: KMail/1.5.4

Does it require a comment? :-)

2007-03-06  Bruno Haible  <address@hidden>

        * modules/vsprintf-posix: New file.
        * lib/vsprintf.c: New file.
        * m4/vsprintf-posix.m4: New file.
        * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Set also GNULIB_VSPRINTF_POSIX,
        REPLACE_VSPRINTF.
        * lib/stdio_.h (vsprintf): New declaration.
        * modules/stdio (Makefile.am): Substitute also GNULIB_VSPRINTF_POSIX,
        REPLACE_VSPRINTF.

============================ modules/vsprintf-posix ===========================
Description:
POSIX compatible vsprintf() function: print formatted output to a string

Files:
lib/vsprintf.c
m4/vsprintf-posix.m4
m4/printf.m4

Depends-on:
stdio
vasnprintf
isnan-nolibm
isnanl-nolibm
printf-frexp
printf-frexpl

configure.ac:
gl_FUNC_VSPRINTF_POSIX
gl_STDIO_MODULE_INDICATOR([vsprintf-posix])

Makefile.am:

Include:
<stdio.h>

License:
LGPL

Maintainer:
Bruno Haible

=============================== lib/vsprintf.c ================================
/* Formatted output to strings.
   Copyright (C) 2004, 2006-2007 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

/* Specification.  */
#include <stdio.h>

#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>

#include "vasnprintf.h"

/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW.  */
#ifndef EOVERFLOW
# define EOVERFLOW E2BIG
#endif

#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif

/* Print formatted output to string STR.
   Return string length of formatted string.  On error, return a negative
   value. */
int
vsprintf (char *str, const char *format, va_list args)
{
  char *output;
  size_t len;
  size_t lenbuf = SIZE_MAX;

  output = vasnprintf (str, &lenbuf, format, args);
  len = lenbuf;

  if (!output)
    return -1;

  if (output != str)
    {
      /* len is near SIZE_MAX.  */
      free (output);
      errno = EOVERFLOW;
      return -1;
    }

  if (len > INT_MAX)
    {
      errno = EOVERFLOW;
      return -1;
    }

  return len;
}
============================= m4/vsprintf-posix.m4 ============================
# vsprintf-posix.m4 serial 1
dnl Copyright (C) 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_VSPRINTF_POSIX],
[
  AC_REQUIRE([gl_EOVERFLOW])
  AC_REQUIRE([gl_PRINTF_SIZES_C99])
  AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
  AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
  AC_REQUIRE([gl_PRINTF_POSITIONS])
  if expr "$gl_cv_func_printf_sizes_c99" : ".*yes" > /dev/null \
     && expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null \
     && expr "$gl_cv_func_printf_directive_n" : ".*yes" > /dev/null \
     && expr "$gl_cv_func_printf_positions" : ".*yes" > /dev/null; then
    : # vsprintf exists and is already POSIX compliant.
  else
    if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then
      AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1,
        [Define if the vasnprintf implementation needs special code for
         the 'a' and 'A' directives.])
    fi
    gl_REPLACE_VASNPRINTF
    gl_REPLACE_VSPRINTF
  fi
])

AC_DEFUN([gl_REPLACE_VSPRINTF],
[
  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
  AC_LIBOBJ([vsprintf])
  REPLACE_VSPRINTF=1
  gl_PREREQ_VSPRINTF
])

AC_DEFUN([gl_PREREQ_VSPRINTF], [:])
===============================================================================
*** m4/stdio_h.m4       7 Mar 2007 01:59:05 -0000       1.3
--- m4/stdio_h.m4       7 Mar 2007 03:20:22 -0000
***************
*** 21,31 ****
  
  AC_DEFUN([gl_STDIO_H_DEFAULTS],
  [
!   GNULIB_SNPRINTF=0;     AC_SUBST([GNULIB_SNPRINTF])
!   GNULIB_VSNPRINTF=0;    AC_SUBST([GNULIB_VSNPRINTF])
    dnl Assume proper GNU behavior unless another module says otherwise.
!   REPLACE_SNPRINTF=0;    AC_SUBST([REPLACE_SNPRINTF])
!   HAVE_DECL_SNPRINTF=1;  AC_SUBST([HAVE_DECL_SNPRINTF])
!   REPLACE_VSNPRINTF=0;   AC_SUBST([REPLACE_VSNPRINTF])
!   HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF])
  ])
--- 21,33 ----
  
  AC_DEFUN([gl_STDIO_H_DEFAULTS],
  [
!   GNULIB_SNPRINTF=0;       AC_SUBST([GNULIB_SNPRINTF])
!   GNULIB_VSNPRINTF=0;      AC_SUBST([GNULIB_VSNPRINTF])
!   GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX])
    dnl Assume proper GNU behavior unless another module says otherwise.
!   REPLACE_SNPRINTF=0;      AC_SUBST([REPLACE_SNPRINTF])
!   HAVE_DECL_SNPRINTF=1;    AC_SUBST([HAVE_DECL_SNPRINTF])
!   REPLACE_VSNPRINTF=0;     AC_SUBST([REPLACE_VSNPRINTF])
!   HAVE_DECL_VSNPRINTF=1;   AC_SUBST([HAVE_DECL_VSNPRINTF])
!   REPLACE_VSPRINTF=0;      AC_SUBST([REPLACE_VSPRINTF])
  ])
*** lib/stdio_.h        7 Mar 2007 01:59:05 -0000       1.4
--- lib/stdio_.h        7 Mar 2007 03:20:22 -0000
***************
*** 70,75 ****
--- 70,89 ----
       vsnprintf (b, s, f, a))
  #endif
  
+ #if @GNULIB_VSPRINTF_POSIX@
+ # if @REPLACE_VSPRINTF@
+ #  define vsprintf rpl_vsprintf
+ extern int vsprintf (char *str, const char *format, va_list args);
+ # endif
+ #elif defined GNULIB_POSIXCHECK
+ # undef vsprintf
+ # define vsprintf(b,f,a) \
+     (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
+                       "use gnulib module vsprintf-posix for portable " \
+                       "POSIX compliance"), \
+      vsprintf (b, f, a))
+ #endif
+ 
  
  #ifdef __cplusplus
  }
*** modules/stdio       7 Mar 2007 01:59:05 -0000       1.3
--- modules/stdio       7 Mar 2007 03:20:22 -0000
***************
*** 23,32 ****
--- 23,34 ----
          sed -e 's|@''ABSOLUTE_STDIO_H''@|$(ABSOLUTE_STDIO_H)|g' \
              -e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \
              -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
+             -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \
              -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \
              -e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \
              -e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \
              -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \
+             -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \
              -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
              < $(srcdir)/stdio_.h; \
        } > address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]