Adjusted symbols for printf and updated to latest version.

This commit is contained in:
Werner Koch 2007-05-15 19:47:15 +00:00
parent 5f3bca9682
commit ad3ab7a059
6 changed files with 180 additions and 38 deletions

View File

@ -1,6 +1,8 @@
2007-05-15 Werner Koch <wk@g10code.com>
* configure.ac: Call ESTREAM_INIT and define the memory
* configure.ac: Renamed the estream macros. Remove -Wformat-nonliteral.
* configure.ac: Call ESTREAM_INIT and define the memory
allocators for estream_asprintf.
(gl_MODULES): Remove vasprintf.

View File

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: estream-printf.c 54 2007-05-15 14:12:06Z wk $
* $Id: estream-printf.c 56 2007-05-15 18:38:43Z wk $
*/
/* Required autoconf tests:
@ -34,7 +34,7 @@
Note that the file estream.m4 provides the autoconf macro
ESTREAM_PRINTF_INIT which runs all required checks.
See estream-printf.h for ways to tune this code.
Missing stuff: wchar and wint_t
thousands_sep in pr_float.
@ -61,21 +61,21 @@
#ifdef TEST
# include <locale.h>
#endif
#ifdef ESTREAM_PRINTF_EXTRA_INCLUDE
#include ESTREAM_PRINTF_EXTRA_INCLUDE
#ifdef _ESTREAM_PRINTF_EXTRA_INCLUDE
#include _ESTREAM_PRINTF_EXTRA_INCLUDE
#endif
#include "estream-printf.h"
/* Allow redefinition of asprintf used malloc functions. */
#ifdef ESTREAM_ASPRINTF_MALLOC
#define my_asprintf_malloc(a) ESTREAM_ASPRINTF_MALLOC((a))
#ifdef _ESTREAM_PRINTF_MALLOC
#define my_printf_malloc(a) _ESTREAM_PRINTF_MALLOC((a))
#else
#define my_asprintf_malloc(a) malloc((a))
#define my_printf_malloc(a) malloc((a))
#endif
#ifdef ESTREAM_ASPRINTF_FREE
#define my_asprintf_free(a) ESTREAM_ASPRINTF_FREE((a))
#ifdef _ESTREAM_PRINTF_FREE
#define my_printf_free(a) _ESTREAM_PRINTF_FREE((a))
#else
#define my_asprintf_free(a) free((a))
#define my_printf_free(a) free((a))
#endif
@ -1799,7 +1799,7 @@ estream_vasprintf (char **bufp, const char *format, va_list arg_ptr)
parm.error_flag = 0;
parm.alloced = 512;
parm.used = 0;
parm.buffer = my_asprintf_malloc (parm.alloced);
parm.buffer = my_printf_malloc (parm.alloced);
if (!parm.buffer)
{
*bufp = NULL;
@ -1816,7 +1816,7 @@ estream_vasprintf (char **bufp, const char *format, va_list arg_ptr)
if (rc == -1)
{
memset (parm.buffer, 0, parm.used);
my_asprintf_free (parm.buffer);
my_printf_free (parm.buffer);
*bufp = NULL;
return -1;
}

View File

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: estream-printf.h 54 2007-05-15 14:12:06Z wk $
* $Id: estream-printf.h 56 2007-05-15 18:38:43Z wk $
*/
#ifndef ESTREAM_PRINTF_H
@ -27,10 +27,61 @@
#include <stdarg.h>
#include <stdio.h>
/* To use this file with libraries the following macro is useful:
#define _ESTREAM_EXT_SYM_PREFIX _foo_
This prefixes all external symbols with "_foo_".
For the implementation of the code (estream-printf.c) the following
macros may be used to tune the implementation for certain systems:
#define _ESTREAM_PRINTF_MALLOC foo_malloc
#define _ESTREAM_PRINTF_FREE foo_free
Make estream_asprintf and estream_vasprintf use foo_malloc and
foo_free instead of the standard malloc and free functions to
allocate the memory returned to the caller.
#define _ESTREAM_PRINTF_EXTRA_INCLUDE "foo.h"
This includes the file "foo.h" which may provide prototypes for
the custom memory allocation functions.
*/
#ifdef _ESTREAM_EXT_SYM_PREFIX
#ifndef _ESTREAM_PREFIX
#define _ESTREAM_PREFIX1(x,y) x ## y
#define _ESTREAM_PREFIX2(x,y) _ESTREAM_PREFIX1(x,y)
#define _ESTREAM_PREFIX(x) _ESTREAM_PREFIX2(_ESTREAM_EXT_SYM_PREFIX,x)
#endif /*_ESTREAM_PREFIX*/
#define estream_printf_out_t _ESTREAM_PREFIX(estream_printf_out_t)
#define estream_format _ESTREAM_PREFIX(estream_format)
#define estream_printf _ESTREAM_PREFIX(estream_printf)
#define estream_fprintf _ESTREAM_PREFIX(estream_fprintf)
#define estream_vfprintf _ESTREAM_PREFIX(estream_vfprintf)
#define estream_snprintf _ESTREAM_PREFIX(estream_snprintf)
#define estream_vsnprintf _ESTREAM_PREFIX(estream_vsnprintf)
#define estream_asprintf _ESTREAM_PREFIX(estream_asprintf)
#define estream_vasprintf _ESTREAM_PREFIX(estream_vasprintf)
#endif /*_ESTREAM_EXT_SYM_PREFIX*/
#ifndef _ESTREAM_GCC_A_PRINTF
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
# define ESTREAM_GCC_A_PRINTF( f, a ) __attribute__ ((format (printf,f,a)))
# define _ESTREAM_GCC_A_PRINTF( f, a ) __attribute__ ((format (printf,f,a)))
#else
# define ESTREAM_GCC_A_PRINTF( f, a )
# define _ESTREAM_GCC_A_PRINTF( f, a )
#endif
#endif /*_ESTREAM_GCC_A_PRINTF*/
#ifdef __cplusplus
extern "C"
{
#if 0
}
#endif
#endif
@ -39,22 +90,25 @@ typedef int (*estream_printf_out_t)
int estream_format (estream_printf_out_t outfnc, void *outfncarg,
const char *format, va_list vaargs)
ESTREAM_GCC_A_PRINTF(3,0);
_ESTREAM_GCC_A_PRINTF(3,0);
int estream_printf (const char *format, ...)
ESTREAM_GCC_A_PRINTF(1,2);
_ESTREAM_GCC_A_PRINTF(1,2);
int estream_fprintf (FILE *fp, const char *format, ... )
ESTREAM_GCC_A_PRINTF(2,3);
_ESTREAM_GCC_A_PRINTF(2,3);
int estream_vfprintf (FILE *fp, const char *format, va_list arg_ptr)
ESTREAM_GCC_A_PRINTF(2,0);
_ESTREAM_GCC_A_PRINTF(2,0);
int estream_snprintf (char *buf, size_t bufsize, const char *format, ...)
ESTREAM_GCC_A_PRINTF(3,4);
_ESTREAM_GCC_A_PRINTF(3,4);
int estream_vsnprintf (char *buf,size_t bufsize,
const char *format, va_list arg_ptr)
ESTREAM_GCC_A_PRINTF(3,0);
_ESTREAM_GCC_A_PRINTF(3,0);
int estream_asprintf (char **bufp, const char *format, ...)
ESTREAM_GCC_A_PRINTF(2,3);
_ESTREAM_GCC_A_PRINTF(2,3);
int estream_vasprintf (char **bufp, const char *format, va_list arg_ptr)
ESTREAM_GCC_A_PRINTF(2,0);
_ESTREAM_GCC_A_PRINTF(2,0);
#ifdef __cplusplus
}
#endif
#endif /*ESTREAM_PRINTF_H*/

View File

@ -26,7 +26,82 @@
#include <stdarg.h>
#include <stdio.h>
/* To use this file with libraries the following macro is useful:
#define _ESTREAM_EXT_SYM_PREFIX _foo_
This prefixes all external symbols with "_foo_".
*/
#ifdef _ESTREAM_EXT_SYM_PREFIX
#ifndef _ESTREAM_PREFIX
#define _ESTREAM_PREFIX1(x,y) x ## y
#define _ESTREAM_PREFIX2(x,y) _ESTREAM_PREFIX1(x,y)
#define _ESTREAM_PREFIX(x) _ESTREAM_PREFIX2(_ESTREAM_EXT_SYM_PREFIX,x)
#endif /*_ESTREAM_PREFIX*/
#define es_fopen _ESTREAM_PREFIX(es_fopen)
#define es_mopen _ESTREAM_PREFIX(es_mopen)
#define es_open_memstream _ESTREAM_PREFIX(es_open_memstream)
#define es_fdopen _ESTREAM_PREFIX(es_fdopen)
#define es_freopen _ESTREAM_PREFIX(es_freopen)
#define es_fopencookie _ESTREAM_PREFIX(es_fopencookie)
#define es_fclose _ESTREAM_PREFIX(es_fclose)
#define es_fileno _ESTREAM_PREFIX(es_fileno)
#define es_fileno_unlocked _ESTREAM_PREFIX(es_fileno_unlocked)
#define es_flockfile _ESTREAM_PREFIX(es_flockfile)
#define es_ftrylockfile _ESTREAM_PREFIX(es_ftrylockfile)
#define es_funlockfile _ESTREAM_PREFIX(es_funlockfile)
#define es_feof _ESTREAM_PREFIX(es_feof)
#define es_feof_unlocked _ESTREAM_PREFIX(es_feof_unlocked)
#define es_ferror _ESTREAM_PREFIX(es_ferror)
#define es_ferror_unlocked _ESTREAM_PREFIX(es_ferror_unlocked)
#define es_clearerr _ESTREAM_PREFIX(es_clearerr)
#define es_clearerr_unlocked _ESTREAM_PREFIX(es_clearerr_unlocked)
#define es_fflush _ESTREAM_PREFIX(es_fflush)
#define es_fseek _ESTREAM_PREFIX(es_fseek)
#define es_fseeko _ESTREAM_PREFIX(es_fseeko)
#define es_ftell _ESTREAM_PREFIX(es_ftell)
#define es_ftello _ESTREAM_PREFIX(es_ftello)
#define es_rewind _ESTREAM_PREFIX(es_rewind)
#define es_fgetc _ESTREAM_PREFIX(es_fgetc)
#define es_fputc _ESTREAM_PREFIX(es_fputc)
#define _es_getc_underflow _ESTREAM_PREFIX(_es_getc_underflow)
#define _es_putc_overflow _ESTREAM_PREFIX(_es_putc_overflow)
#define es_ungetc _ESTREAM_PREFIX(es_ungetc)
#define es_read _ESTREAM_PREFIX(es_read)
#define es_write _ESTREAM_PREFIX(es_write)
#define es_write_sanitized _ESTREAM_PREFIX(es_write_sanitized)
#define es_write_hexstring _ESTREAM_PREFIX(es_write_hexstring)
#define es_fread _ESTREAM_PREFIX(es_fread)
#define es_fwrite _ESTREAM_PREFIX(es_fwrite)
#define es_fgets _ESTREAM_PREFIX(es_fgets)
#define es_fputs _ESTREAM_PREFIX(es_fputs)
#define es_getline _ESTREAM_PREFIX(es_getline)
#define es_read_line _ESTREAM_PREFIX(es_read_line)
#define es_free _ESTREAM_PREFIX(es_free)
#define es_fprf _ESTREAM_PREFIX(es_fprf)
#define es_vfprf _ESTREAM_PREFIX(es_vfprf)
#define es_setvbuf _ESTREAM_PREFIX(es_setvbuf)
#define es_setbuf _ESTREAM_PREFIX(es_setbuf)
#define es_tmpfile _ESTREAM_PREFIX(es_tmpfile)
#define es_opaque_set _ESTREAM_PREFIX(es_opaque_set)
#define es_opaque_get _ESTREAM_PREFIX(es_opaque_get)
#define es_write_sanitized_utf8_buffer \
_ESTREAM_PREFIX(es_write_sanitized_utf8_buffer)
#endif /*_ESTREAM_EXT_SYM_PREFIX*/
#ifdef __cplusplus
extern "C"
{
#if 0
}
#endif
#endif
/* Forward declaration for the (opaque) internal type. */
struct estream_internal;
@ -90,6 +165,15 @@ typedef struct es_cookie_io_functions
} es_cookie_io_functions_t;
#ifndef _ESTREAM_GCC_A_PRINTF
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
# define _ESTREAM_GCC_A_PRINTF( f, a ) __attribute__ ((format (printf,f,a)))
#else
# define _ESTREAM_GCC_A_PRINTF( f, a )
#endif
#endif /*_ESTREAM_GCC_A_PRINTF*/
#ifndef ES__RESTRICT
# if defined __GNUC__ && defined __GNUC_MINOR__
# if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 92))
@ -191,16 +275,17 @@ int es_fputs (const char *ES__RESTRICT s, estream_t ES__RESTRICT stream);
ssize_t es_getline (char *ES__RESTRICT *ES__RESTRICT lineptr,
size_t *ES__RESTRICT n,
estream_t stream);
ssize_t es_read_line (estream_t stream,
ssize_t es_read_line (estream_t stream,
char **addr_of_buffer, size_t *length_of_buffer,
size_t *max_length);
void es_free (void *a);
int es_fprintf (estream_t ES__RESTRICT stream,
const char *ES__RESTRICT format, ...);
const char *ES__RESTRICT format, ...)
_ESTREAM_GCC_A_PRINTF(2,3);
int es_vfprintf (estream_t ES__RESTRICT stream,
const char *ES__RESTRICT format, va_list ap);
const char *ES__RESTRICT format, va_list ap)
_ESTREAM_GCC_A_PRINTF(2,0);
int es_setvbuf (estream_t ES__RESTRICT stream,
char *ES__RESTRICT buf, int mode, size_t size);
void es_setbuf (estream_t ES__RESTRICT stream, char *ES__RESTRICT buf);
@ -213,12 +298,13 @@ void *es_opaque_get (estream_t stream);
#ifdef GNUPG_MAJOR_VERSION
int es_write_sanitized_utf8_buffer (estream_t stream,
const void *buffer, size_t length,
const void *buffer, size_t length,
const char *delimiters,
size_t *bytes_written);
#endif /*GNUPG_MAJOR_VERSION*/
#ifdef __cplusplus
}
#endif
#endif /*ESTREAM_H*/

View File

@ -27,8 +27,8 @@
#include "iobuf.h"
#include "estream-printf.h"
#if !defined(ESTREAM_ASPRINTF_MALLOC) || !defined(ESTREAM_ASPRINTF_FREE)
#error Need to define ESTREAM_ASPRINTF_MALLOC and _FREE
#if !defined(_ESTREAM_PRINTF_MALLOC) || !defined(_ESTREAM_PRINTF_FREE)
#error Need to define ESTREAM_PRINTF_MALLOC and _FREE
#endif
/* Same as asprintf but return an allocated buffer suitable to be

View File

@ -428,9 +428,9 @@ AH_BOTTOM([
/* We want to use the libgcrypt provided memory allocation for
asprintf. */
#define ESTREAM_ASPRINTF_MALLOC gcry_malloc
#define ESTREAM_ASPRINTF_FREE gcry_free
#define ESTREAM_PRINTF_EXTRA_INCLUDE "util.h"
#define _ESTREAM_PRINTF_MALLOC gcry_malloc
#define _ESTREAM_PRINTF_FREE gcry_free
#define _ESTREAM_PRINTF_EXTRA_INCLUDE "util.h"
#endif /*GNUPG_CONFIG_H_INCLUDED*/
])
@ -1157,7 +1157,7 @@ if test "$GCC" = yes; then
# them.
if test "$USE_MAINTAINER_MODE" = "yes"; then
CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
CFLAGS="$CFLAGS -Wno-format-y2k -Wformat-security -Wformat-nonliteral"
CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security"
else
CFLAGS="$CFLAGS -Wall"
fi