1 /* estream-printf.h - Versatile C-99 compliant printf formatting.
2 * Copyright (C) 2007 g10 Code GmbH
4 * This file is part of Libestream.
6 * Libestream is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2 of the License,
9 * or (at your option) any later version.
11 * Libestream is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Libestream; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef ESTREAM_PRINTF_H
21 #define ESTREAM_PRINTF_H
26 /* To use this file with libraries the following macro is useful:
28 #define _ESTREAM_EXT_SYM_PREFIX _foo_
30 This prefixes all external symbols with "_foo_".
32 For the implementation of the code (estream-printf.c) the following
33 macros may be used to tune the implementation for certain systems:
35 #define _ESTREAM_PRINTF_MALLOC foo_malloc
36 #define _ESTREAM_PRINTF_FREE foo_free
38 Make estream_asprintf and estream_vasprintf use foo_malloc and
39 foo_free instead of the standard malloc and free functions to
40 allocate the memory returned to the caller.
42 #define _ESTREAM_PRINTF_EXTRA_INCLUDE "foo.h"
44 This includes the file "foo.h" which may provide prototypes for
45 the custom memory allocation functions.
49 #ifdef _ESTREAM_EXT_SYM_PREFIX
50 #ifndef _ESTREAM_PREFIX
51 #define _ESTREAM_PREFIX1(x,y) x ## y
52 #define _ESTREAM_PREFIX2(x,y) _ESTREAM_PREFIX1(x,y)
53 #define _ESTREAM_PREFIX(x) _ESTREAM_PREFIX2(_ESTREAM_EXT_SYM_PREFIX,x)
54 #endif /*_ESTREAM_PREFIX*/
55 #define estream_printf_out_t _ESTREAM_PREFIX(estream_printf_out_t)
56 #define estream_format _ESTREAM_PREFIX(estream_format)
57 #define estream_printf _ESTREAM_PREFIX(estream_printf)
58 #define estream_fprintf _ESTREAM_PREFIX(estream_fprintf)
59 #define estream_vfprintf _ESTREAM_PREFIX(estream_vfprintf)
60 #define estream_snprintf _ESTREAM_PREFIX(estream_snprintf)
61 #define estream_vsnprintf _ESTREAM_PREFIX(estream_vsnprintf)
62 #define estream_asprintf _ESTREAM_PREFIX(estream_asprintf)
63 #define estream_vasprintf _ESTREAM_PREFIX(estream_vasprintf)
64 #endif /*_ESTREAM_EXT_SYM_PREFIX*/
66 #ifndef _ESTREAM_GCC_A_PRINTF
67 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
68 # define _ESTREAM_GCC_A_PRINTF( f, a ) __attribute__ ((format (printf,f,a)))
70 # define _ESTREAM_GCC_A_PRINTF( f, a )
72 #endif /*_ESTREAM_GCC_A_PRINTF*/
84 typedef int (*estream_printf_out_t
)
85 (void *outfncarg
, const char *buf
, size_t buflen
);
87 int estream_format (estream_printf_out_t outfnc
, void *outfncarg
,
88 const char *format
, va_list vaargs
)
89 _ESTREAM_GCC_A_PRINTF(3,0);
90 int estream_printf (const char *format
, ...)
91 _ESTREAM_GCC_A_PRINTF(1,2);
92 int estream_fprintf (FILE *fp
, const char *format
, ... )
93 _ESTREAM_GCC_A_PRINTF(2,3);
94 int estream_vfprintf (FILE *fp
, const char *format
, va_list arg_ptr
)
95 _ESTREAM_GCC_A_PRINTF(2,0);
96 int estream_snprintf (char *buf
, size_t bufsize
, const char *format
, ...)
97 _ESTREAM_GCC_A_PRINTF(3,4);
98 int estream_vsnprintf (char *buf
,size_t bufsize
,
99 const char *format
, va_list arg_ptr
)
100 _ESTREAM_GCC_A_PRINTF(3,0);
101 int estream_asprintf (char **bufp
, const char *format
, ...)
102 _ESTREAM_GCC_A_PRINTF(2,3);
103 int estream_vasprintf (char **bufp
, const char *format
, va_list arg_ptr
)
104 _ESTREAM_GCC_A_PRINTF(2,0);
110 #endif /*ESTREAM_PRINTF_H*/