1 //-----------------------------------------------------------------------------
2 // Borrowed initially from https://github.com/mpaland/printf
3 // Copyright (C) Marco Paland 2014-2019, PALANDesign Hannover, Germany
4 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // This program 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
14 // GNU General Public License for more details.
16 // See LICENSE.txt for the text of the license.
17 //-----------------------------------------------------------------------------
18 // Tiny printf, sprintf and (v)snprintf implementation, optimized for speed on
19 // embedded systems with a very limited resources. These routines are thread
20 // safe and reentrant!
21 // Use this instead of the bloated standard/newlib printf cause these use
22 // malloc for printf (and may not be thread safe).
23 //-----------------------------------------------------------------------------
34 * Output a character to a custom device like UART, used by the printf() function
35 * This function is declared here only. You have to write your custom implementation somewhere
36 * \param character Character to output
38 void _putchar(char character
);
42 * Tiny printf implementation
43 * You have to implement _putchar if you use printf()
44 * To avoid conflicts with the regular printf() API it is overridden by macro defines
45 * and internal underscore-appended functions like printf_() are used
46 * \param format A string that specifies the format of the output
47 * \return The number of characters that are written into the array, not counting the terminating null character
49 #define printf printf_
50 int printf_(const char *format
, ...);
54 * Tiny sprintf implementation
55 * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD!
56 * \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output!
57 * \param format A string that specifies the format of the output
58 * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
60 #define sprintf sprintf_
61 int sprintf_(char *buffer
, const char *format
, ...);
65 * Tiny snprintf/vsnprintf implementation
66 * \param buffer A pointer to the buffer where to store the formatted string
67 * \param count The maximum number of characters to store in the buffer, including a terminating null character
68 * \param format A string that specifies the format of the output
69 * \param va A value identifying a variable arguments list
70 * \return The number of characters that COULD have been written into the buffer, not counting the terminating
71 * null character. A value equal or larger than count indicates truncation. Only when the returned value
72 * is non-negative and less than count, the string has been completely written.
74 #define snprintf snprintf_
75 #define vsnprintf vsnprintf_
76 int snprintf_(char *buffer
, size_t count
, const char *format
, ...);
77 int vsnprintf_(char *buffer
, size_t count
, const char *format
, va_list va
);
81 * Tiny vprintf implementation
82 * \param format A string that specifies the format of the output
83 * \param va A value identifying a variable arguments list
84 * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
86 #define vprintf vprintf_
87 int vprintf_(const char *format
, va_list va
);
91 * printf with output function
92 * You may use this as dynamic alternative to printf() with its fixed _putchar() output
93 * \param out An output function which takes one character and an argument pointer
94 * \param arg An argument pointer for user data passed to output function
95 * \param format A string that specifies the format of the output
96 * \return The number of characters that are sent to the output function, not counting the terminating null character
98 int fctprintf(void (*out
)(char character
, void *arg
), void *arg
, const char *format
, ...);