4 * Copyright (C) 2002,2004 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See devlib/README for information.
8 * \brief sprintf() implementation based on _formatted_write()
11 * \author Bernardo Innocenti <bernie@develer.com>
16 *#* Revision 1.5 2004/10/03 18:54:36 bernie
17 *#* sprintf(): Fix a serious bug; snprintf(): New function.
19 *#* Revision 1.4 2004/08/25 14:12:09 rasky
20 *#* Aggiornato il comment block dei log RCS
22 *#* Revision 1.3 2004/06/27 15:20:26 aleph
23 *#* Change UNUSED() macro to accept two arguments: type and name;
24 *#* Add macro GNUC_PREREQ to detect GCC version during build;
25 *#* Some spacing cleanups and typo fix
27 *#* Revision 1.2 2004/06/03 11:27:09 bernie
28 *#* Add dual-license information.
30 *#* Revision 1.1 2004/05/23 15:43:16 bernie
31 *#* Import mware modules.
33 *#* Revision 1.4 2004/04/03 20:42:27 aleph
34 *#* Remove duplicated defines
36 *#* Revision 1.3 2004/03/24 15:48:53 bernie
37 *#* Remove Copyright messages from Doxygen output
39 *#* Revision 1.2 2004/03/19 16:51:30 bernie
40 *#* Add PROGMEM kludge.
42 *#* Revision 1.1 2004/02/23 09:45:09 aleph
43 *#* Add missing library functions.
45 *#* Revision 1.1 2003/11/13 16:56:37 aleph
46 *#* Add first implementation of dsp firmware
55 static void __str_put_char(char c, void *ptr)
58 * This Does not work on Code Warrior. Hmm...
59 * *(*((char **)ptr))++ = c;
66 static void __null_put_char(UNUSED(char, c), UNUSED(void *, ptr))
72 int PGM_FUNC(vsprintf)(char * str, const char * PGM_ATTR fmt, va_list ap)
76 result = PGM_FUNC(_formatted_write)(
77 fmt, (str ? __str_put_char : __null_put_char), &str, ap);
79 /* Terminate string */
86 int PGM_FUNC(sprintf)(char *str, const char * fmt, ...)
92 result = PGM_FUNC(vsprintf)(str, fmt, ap);
99 * State information for __sn_put_char()
108 * formatted_write() callback used [v]snprintf().
110 static void __sn_put_char(char c, void *ptr)
112 struct __sn_state *state = (struct __sn_state *)ptr;
122 int PGM_FUNC(vsnprintf)(char * str, size_t size, const char * PGM_ATTR fmt, va_list ap)
125 struct __sn_state state = { str, size };
127 result = PGM_FUNC(_formatted_write)(
128 fmt, (str ? __sn_put_char : __null_put_char), &state, ap);
130 /* Terminate string */
137 int PGM_FUNC(snprintf)(char *str, size_t size, const char * fmt, ...)
143 result = PGM_FUNC(vsnprintf)(str, size, fmt, ap);