/* * Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _PRINTF_H_ #define _PRINTF_H_ #include #include #ifdef __cplusplus extern "C" { #endif /** * Tiny printf implementation * You have to implement _putchar if you use printf() * To avoid conflicts with the regular printf() API it is overridden by macro defines * and internal underscore-appended functions like printf_() are used * \param format A string that specifies the format of the output * \return The number of characters that are written into the array, not counting the terminating null character */ #define printf printf_ int printf_(const char* format, ...); /** * Tiny snprintf/vsnprintf implementation * \param buffer A pointer to the buffer where to store the formatted string * \param count The maximum number of characters to store in the buffer, including a terminating null character * \param format A string that specifies the format of the output * \param va A value identifying a variable arguments list * \return The number of characters that COULD have been written into the buffer, not counting the terminating * null character. A value equal or larger than count indicates truncation. Only when the returned value * is non-negative and less than count, the string has been completely written. */ #define snprintf vsnprintf_ #define vsnprintf vsnprintf_ int snprintf_(char* buffer, size_t count, const char* format, ...); int vsnprintf_(char* buffer, size_t count, const char* format, va_list va); /** * printf with output function * You may use this as dynamic alternative to printf() with its fixed _putchar() output * \param out An output function which takes one character and an argument pointer * \param arg An argument pointer for user data passed to output function * \param format A string that specifies the format of the output * \return The number of characters that are sent to the output function, not counting the terminating null character */ int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...); #ifdef __cplusplus } #endif #endif // _PRINTF_H_