Skip to content

Commit

Permalink
Add optional stdio function names with options macro
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Sep 27, 2020
1 parent b14d218 commit 9ad40da
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
49 changes: 48 additions & 1 deletion lwprintf/src/include/lwprintf/lwprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,37 +171,84 @@ int lwprintf_snprintf_ex(lwprintf_t* const lw, char* s, size_t n, const
*/
#define lwprintf_sprintf(s, format, ...) lwprintf_sprintf_ex(NULL, (s), (format), ## __VA_ARGS__)

/* Shortcut versions */
#if LWPRINTF_CFG_ENABLE_SHORTNAMES || __DOXYGEN__

/**
* \copydoc lwprintf_printf
* \note This function is equivalent to \ref lwprintf_printf
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
*/
#define lwprintf lwprintf_printf

/**
* \copydoc lwprintf_vprintf
* \note This function is equivalent to \ref lwprintf_vprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
*/
#define lwvprintf lwprintf_vprintf

/**
* \copydoc lwprintf_vsnprintf
* \note This function is equivalent to \ref lwprintf_vsnprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
*/
#define lwvsnprintf lwprintf_vsnprintf

/**
* \copydoc lwprintf_snprintf
* \note This function is equivalent to \ref lwprintf_snprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
*/
#define lwsnprintf lwprintf_snprintf

/**
* \copydoc lwprintf_sprintf
* \note This function is equivalent to \ref lwprintf_sprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled
*/
#define lwsprintf lwprintf_sprintf

#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES || __DOXYGEN__ */

#if LWPRINTF_CFG_ENABLE_STD_NAMES || __DOXYGEN__

/**
* \copydoc lwprintf_printf
* \note This function is equivalent to \ref lwprintf_printf
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
*/
#define printf lwprintf_printf

/**
* \copydoc lwprintf_vprintf
* \note This function is equivalent to \ref lwprintf_vprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
*/
#define vprintf lwprintf_vprintf

/**
* \copydoc lwprintf_vsnprintf
* \note This function is equivalent to \ref lwprintf_vsnprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
*/
#define vsnprintf lwprintf_vsnprintf

/**
* \copydoc lwprintf_snprintf
* \note This function is equivalent to \ref lwprintf_snprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
*/
#define snprintf lwprintf_snprintf

/**
* \copydoc lwprintf_sprintf
* \note This function is equivalent to \ref lwprintf_sprintf
* and available only if \ref LWPRINTF_CFG_ENABLE_STD_NAMES is enabled
*/
#define sprintf lwprintf_sprintf

#endif /* LWPRINTF_CFG_ENABLE_STD_NAMES || __DOXYGEN__ */

/**
* \}
*/
Expand Down
20 changes: 20 additions & 0 deletions lwprintf/src/include/lwprintf/lwprintf_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ extern "C" {
#define LWPRINTF_CFG_FLOAT_DEFAULT_PRECISION 6
#endif

/**
* \brief Enables `1` or disables `0` optional short names for LwPRINTF API functions.
*
* It adds functions for default instance: `lwprintf`, `lwsnprintf` and others
*/
#ifndef LWPRINTF_CFG_ENABLE_SHORTNAMES
#define LWPRINTF_CFG_ENABLE_SHORTNAMES 1
#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES */

/**
* \brief Enables `1` or disables `0` C standard API names
*
* Disabled by default not to interfere with compiler implementation.
* Application may need to remove standard C STDIO library from linkage
* to be able to properly compile LwPRINTF with this option enabled
*/
#ifndef LWPRINTF_CFG_ENABLE_STD_NAMES
#define LWPRINTF_CFG_ENABLE_STD_NAMES 0
#endif /* LWPRINTF_CFG_ENABLE_SHORTNAMES */

/**
* \}
*/
Expand Down

0 comments on commit 9ad40da

Please sign in to comment.