13d0407baSopenharmony_ci/*
23d0407baSopenharmony_ci * Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved.
33d0407baSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43d0407baSopenharmony_ci * you may not use this file except in compliance with the License.
53d0407baSopenharmony_ci * You may obtain a copy of the License at
63d0407baSopenharmony_ci *
73d0407baSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
83d0407baSopenharmony_ci *
93d0407baSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103d0407baSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113d0407baSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123d0407baSopenharmony_ci * See the License for the specific language governing permissions and
133d0407baSopenharmony_ci * limitations under the License.
143d0407baSopenharmony_ci */
153d0407baSopenharmony_ci#ifndef _PRINTF_H_
163d0407baSopenharmony_ci#define _PRINTF_H_
173d0407baSopenharmony_ci
183d0407baSopenharmony_ci#include <stdarg.h>
193d0407baSopenharmony_ci#include <stddef.h>
203d0407baSopenharmony_ci
213d0407baSopenharmony_ci#ifdef __cplusplus
223d0407baSopenharmony_ciextern "C" {
233d0407baSopenharmony_ci#endif
243d0407baSopenharmony_ci
253d0407baSopenharmony_ci
263d0407baSopenharmony_ci/**
273d0407baSopenharmony_ci * Tiny printf implementation
283d0407baSopenharmony_ci * You have to implement _putchar if you use printf()
293d0407baSopenharmony_ci * To avoid conflicts with the regular printf() API it is overridden by macro defines
303d0407baSopenharmony_ci * and internal underscore-appended functions like printf_() are used
313d0407baSopenharmony_ci * \param format A string that specifies the format of the output
323d0407baSopenharmony_ci * \return The number of characters that are written into the array, not counting the terminating null character
333d0407baSopenharmony_ci */
343d0407baSopenharmony_ci#define printf printf_
353d0407baSopenharmony_ciint printf_(const char* format, ...);
363d0407baSopenharmony_ci
373d0407baSopenharmony_ci
383d0407baSopenharmony_ci/**
393d0407baSopenharmony_ci * Tiny snprintf/vsnprintf implementation
403d0407baSopenharmony_ci * \param buffer A pointer to the buffer where to store the formatted string
413d0407baSopenharmony_ci * \param count The maximum number of characters to store in the buffer, including a terminating null character
423d0407baSopenharmony_ci * \param format A string that specifies the format of the output
433d0407baSopenharmony_ci * \param va A value identifying a variable arguments list
443d0407baSopenharmony_ci * \return The number of characters that COULD have been written into the buffer, not counting the terminating
453d0407baSopenharmony_ci *         null character. A value equal or larger than count indicates truncation. Only when the returned value
463d0407baSopenharmony_ci *         is non-negative and less than count, the string has been completely written.
473d0407baSopenharmony_ci */
483d0407baSopenharmony_ci#define snprintf  vsnprintf_
493d0407baSopenharmony_ci#define vsnprintf vsnprintf_
503d0407baSopenharmony_ciint  snprintf_(char* buffer, size_t count, const char* format, ...);
513d0407baSopenharmony_ciint vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
523d0407baSopenharmony_ci
533d0407baSopenharmony_ci
543d0407baSopenharmony_ci/**
553d0407baSopenharmony_ci * printf with output function
563d0407baSopenharmony_ci * You may use this as dynamic alternative to printf() with its fixed _putchar() output
573d0407baSopenharmony_ci * \param out An output function which takes one character and an argument pointer
583d0407baSopenharmony_ci * \param arg An argument pointer for user data passed to output function
593d0407baSopenharmony_ci * \param format A string that specifies the format of the output
603d0407baSopenharmony_ci * \return The number of characters that are sent to the output function, not counting the terminating null character
613d0407baSopenharmony_ci */
623d0407baSopenharmony_ciint fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...);
633d0407baSopenharmony_ci
643d0407baSopenharmony_ci
653d0407baSopenharmony_ci#ifdef __cplusplus
663d0407baSopenharmony_ci}
673d0407baSopenharmony_ci#endif
683d0407baSopenharmony_ci
693d0407baSopenharmony_ci
703d0407baSopenharmony_ci#endif  // _PRINTF_H_