Add first structure and start work on format specifier parser

This commit is contained in:
2023-05-29 11:40:13 +02:00
commit af27e79678
4 changed files with 178 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
#ifndef _SIMPLE_PRINTF_H_
#define _SIMPLE_PRINTF_H_
#include <stddef.h>
#ifndef SIMPLE_PRINTF_ATTR_FORMAT
# if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
# define SIMPLE_PRINTF_ATTR_FORMAT(fmt, args) __attribute__((__format__(__printf__, fmt, args)))
# else
# define SIMPLE_PRINTF_ATTR_FORMAT(fmt, args)
# endif
#else
# define SIMPLE_PRINTF_ATTR_FORMAT(fmt, args)
#endif
/**
* @brief Simple implementation of snprintf
*
* Supports the following format specifiers:
* %d, %i, %s, %u, %z, %c, %x, %X
* @param[out] dest Buffer to write result to
* @param dest_size Size of @p dest in bytes
* @param[in] fmt Format string
* @return Number of written bytes. Not including the null terminator.
* @return negative in case of an error
* @note The resulting output in @p dest will always be null terminated.
*/
int simple_snprintf(char *dest, size_t dest_size, const char *fmt, ...) SIMPLE_PRINTF_ATTR_FORMAT(3, 4);
#endif /* _SIMPLE_PRINTF_H_ */