4 Copyright (C) 2004 Kustaa Nyholm
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef __TFP_PRINTF__
23 #define __TFP_PRINTF__
27 /* Global configuration */
29 /* Set this to 0 if you do not want to provide tfp_printf */
30 #ifndef TINYPRINTF_DEFINE_TFP_PRINTF
31 # define TINYPRINTF_DEFINE_TFP_PRINTF 1
34 /* Set this to 0 if you do not want to provide
35 tfp_sprintf/snprintf/vsprintf/vsnprintf */
36 #ifndef TINYPRINTF_DEFINE_TFP_SPRINTF
37 # define TINYPRINTF_DEFINE_TFP_SPRINTF 1
40 /* Set this to 0 if you do not want tfp_printf and
41 tfp_{vsn,sn,vs,s}printf to be also available as
42 printf/{vsn,sn,vs,s}printf */
43 #ifndef TINYPRINTF_OVERRIDE_LIBC
44 # define TINYPRINTF_OVERRIDE_LIBC 1
47 /* Optional external types dependencies */
49 #if TINYPRINTF_DEFINE_TFP_SPRINTF
50 # include <sys/types.h> /* size_t */
56 # define _TFP_SPECIFY_PRINTF_FMT(fmt_idx,arg1_idx) \
57 __attribute__((format (printf, fmt_idx, arg1_idx)))
59 # define _TFP_SPECIFY_PRINTF_FMT(fmt_idx,arg1_idx)
66 typedef void (*putcf) (void *, char);
69 'tfp_format' really is the central function for all tinyprintf. For
70 each output character after formatting, the 'putf' callback is
72 - an arbitrary void* 'putp' param defined by the user and
73 passed unmodified from 'tfp_format',
75 The 'tfp_printf' and 'tfp_sprintf' functions simply define their own
76 callback and pass to it the right 'putp' it is expecting.
78 void tfp_format(void *putp, putcf putf, const char *fmt, va_list va);
80 #if TINYPRINTF_DEFINE_TFP_SPRINTF
81 int tfp_vsnprintf(char *str, size_t size, const char *fmt, va_list ap);
82 int tfp_snprintf(char *str, size_t size, const char *fmt, ...) \
83 _TFP_SPECIFY_PRINTF_FMT(3, 4);
84 int tfp_vsprintf(char *str, const char *fmt, va_list ap);
85 int tfp_sprintf(char *str, const char *fmt, ...) \
86 _TFP_SPECIFY_PRINTF_FMT(2, 3);
87 # if TINYPRINTF_OVERRIDE_LIBC
88 # define vsnprintf tfp_vsnprintf
89 # define snprintf tfp_snprintf
90 # define vsprintf tfp_vsprintf
91 # define sprintf tfp_sprintf
95 #if TINYPRINTF_DEFINE_TFP_PRINTF
96 void init_printf(void *putp, putcf putf);
97 void tfp_printf(char *fmt, ...) _TFP_SPECIFY_PRINTF_FMT(1, 2);
98 # if TINYPRINTF_OVERRIDE_LIBC
99 # define printf tfp_printf