LwPRINTF

group LWPRINTF

Lightweight stdio manager.

Defines

LWPRINTF_UNUSED(x)

Unused variable macro.

Parameters
  • x ([in]) – Unused variable

LWPRINTF_ARRAYSIZE(x)

Calculate size of statically allocated array.

Parameters
  • x ([in]) – Input array

Returns

Number of array elements

lwprintf_sprintf_ex(lw, s, format, ...)

Write formatted data from variable argument list to sized buffer.

Parameters
  • lw ([inout]) – LwPRINTF instance. Set to NULL to use default instance

  • s ([in]) – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • format ([in]) – C string that contains a format string that follows the same specifications as format in printf

  • ... ([in]) – Optional arguments for format string

Returns

The number of characters that would have been written, not counting the terminating null character.

lwprintf_init(out_fn)

Initialize default LwPRINTF instance.

See

lwprintf_init_ex

Parameters
  • out_fn ([in]) – Output function used for print operation

Returns

1 on success, 0 otherwise

lwprintf_vprintf(format, arg)

Print formatted data from variable argument list to the output with default LwPRINTF instance.

Parameters
  • format ([in]) – C string that contains the text to be written to output

  • arg ([in]) – A value identifying a variable arguments list initialized with va_start. va_list is a special type defined in <cstdarg>.

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

lwprintf_printf(format, ...)

Print formatted data to the output with default LwPRINTF instance.

Parameters
  • format ([in]) – C string that contains the text to be written to output

  • ... ([in]) – Optional arguments for format string

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

lwprintf_vsnprintf(s, n, format, arg)

Write formatted data from variable argument list to sized buffer with default LwPRINTF instance.

Parameters
  • s ([in]) – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • n ([in]) – Maximum number of bytes to be used in the buffer. The generated string has a length of at most n - 1, leaving space for the additional terminating null character

  • format ([in]) – C string that contains a format string that follows the same specifications as format in printf

  • arg ([in]) – A value identifying a variable arguments list initialized with va_start. va_list is a special type defined in <cstdarg>.

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

lwprintf_snprintf(s, n, format, ...)

Write formatted data from variable argument list to sized buffer with default LwPRINTF instance.

Parameters
  • s ([in]) – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • n ([in]) – Maximum number of bytes to be used in the buffer. The generated string has a length of at most n - 1, leaving space for the additional terminating null character

  • format ([in]) – C string that contains a format string that follows the same specifications as format in printf

  • ... ([in]) – Optional arguments for format string

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

lwprintf_sprintf(s, format, ...)

Write formatted data from variable argument list to sized buffer with default LwPRINTF instance.

Parameters
  • s ([in]) – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • format ([in]) – C string that contains a format string that follows the same specifications as format in printf

  • ... ([in]) – Optional arguments for format string

Returns

The number of characters that would have been written, not counting the terminating null character.

lwprintf

Print formatted data to the output with default LwPRINTF instance.

Note

This function is equivalent to lwprintf_printf and available only if LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled

Parameters
  • format ([in]) – C string that contains the text to be written to output

  • ... ([in]) – Optional arguments for format string

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

lwvprintf

Print formatted data from variable argument list to the output with default LwPRINTF instance.

Note

This function is equivalent to lwprintf_vprintf and available only if LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled

Parameters
  • format ([in]) – C string that contains the text to be written to output

  • arg ([in]) – A value identifying a variable arguments list initialized with va_start. va_list is a special type defined in <cstdarg>.

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

lwvsnprintf

Write formatted data from variable argument list to sized buffer with default LwPRINTF instance.

Note

This function is equivalent to lwprintf_vsnprintf and available only if LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled

Parameters
  • s ([in]) – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • n ([in]) – Maximum number of bytes to be used in the buffer. The generated string has a length of at most n - 1, leaving space for the additional terminating null character

  • format ([in]) – C string that contains a format string that follows the same specifications as format in printf

  • arg ([in]) – A value identifying a variable arguments list initialized with va_start. va_list is a special type defined in <cstdarg>.

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

lwsnprintf

Write formatted data from variable argument list to sized buffer with default LwPRINTF instance.

Note

This function is equivalent to lwprintf_snprintf and available only if LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled

Parameters
  • s ([in]) – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • n ([in]) – Maximum number of bytes to be used in the buffer. The generated string has a length of at most n - 1, leaving space for the additional terminating null character

  • format ([in]) – C string that contains a format string that follows the same specifications as format in printf

  • ... ([in]) – Optional arguments for format string

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

lwsprintf

Write formatted data from variable argument list to sized buffer with default LwPRINTF instance.

Note

This function is equivalent to lwprintf_sprintf and available only if LWPRINTF_CFG_ENABLE_SHORTNAMES is enabled

Parameters
  • s ([in]) – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • format ([in]) – C string that contains a format string that follows the same specifications as format in printf

  • ... ([in]) – Optional arguments for format string

Returns

The number of characters that would have been written, not counting the terminating null character.

printf

Print formatted data to the output with default LwPRINTF instance.

Note

This function is equivalent to lwprintf_printf and available only if LWPRINTF_CFG_ENABLE_STD_NAMES is enabled

Parameters
  • format ([in]) – C string that contains the text to be written to output

  • ... ([in]) – Optional arguments for format string

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

vprintf

Print formatted data from variable argument list to the output with default LwPRINTF instance.

Note

This function is equivalent to lwprintf_vprintf and available only if LWPRINTF_CFG_ENABLE_STD_NAMES is enabled

Parameters
  • format ([in]) – C string that contains the text to be written to output

  • arg ([in]) – A value identifying a variable arguments list initialized with va_start. va_list is a special type defined in <cstdarg>.

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

vsnprintf

Write formatted data from variable argument list to sized buffer with default LwPRINTF instance.

Note

This function is equivalent to lwprintf_vsnprintf and available only if LWPRINTF_CFG_ENABLE_STD_NAMES is enabled

Parameters
  • s ([in]) – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • n ([in]) – Maximum number of bytes to be used in the buffer. The generated string has a length of at most n - 1, leaving space for the additional terminating null character

  • format ([in]) – C string that contains a format string that follows the same specifications as format in printf

  • arg ([in]) – A value identifying a variable arguments list initialized with va_start. va_list is a special type defined in <cstdarg>.

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

snprintf

Write formatted data from variable argument list to sized buffer with default LwPRINTF instance.

Note

This function is equivalent to lwprintf_snprintf and available only if LWPRINTF_CFG_ENABLE_STD_NAMES is enabled

Parameters
  • s ([in]) – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • n ([in]) – Maximum number of bytes to be used in the buffer. The generated string has a length of at most n - 1, leaving space for the additional terminating null character

  • format ([in]) – C string that contains a format string that follows the same specifications as format in printf

  • ... ([in]) – Optional arguments for format string

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

sprintf

Write formatted data from variable argument list to sized buffer with default LwPRINTF instance.

Note

This function is equivalent to lwprintf_sprintf and available only if LWPRINTF_CFG_ENABLE_STD_NAMES is enabled

Parameters
  • s ([in]) – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • format ([in]) – C string that contains a format string that follows the same specifications as format in printf

  • ... ([in]) – Optional arguments for format string

Returns

The number of characters that would have been written, not counting the terminating null character.

Typedefs

typedef int (*lwprintf_output_fn)(int ch, struct lwprintf *lw)

Callback function for character output.

Parameters
  • [in] ch – Character to print

  • [in] lw – LwPRINTF instance

Returns

ch on success, 0 to terminate further string processing

Functions

uint8_t lwprintf_init_ex(lwprintf_t *lw, lwprintf_output_fn out_fn)

Initialize LwPRINTF instance.

Parameters
  • [inout] lw – LwPRINTF working instance

  • [in] out_fn – Output function used for print operation

Returns

1 on success, 0 otherwise

int lwprintf_vprintf_ex(lwprintf_t *const lw, const char *format, va_list arg)

Print formatted data from variable argument list to the output.

Parameters
  • [inout] lw – LwPRINTF instance. Set to NULL to use default instance

  • [in] format – C string that contains the text to be written to output

  • [in] arg – A value identifying a variable arguments list initialized with va_start. va_list is a special type defined in <cstdarg>.

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

int lwprintf_printf_ex(lwprintf_t *const lw, const char *format, ...)

Print formatted data to the output.

Parameters
  • [inout] lw – LwPRINTF instance. Set to NULL to use default instance

  • [in] format – C string that contains the text to be written to output

  • [in] ... – Optional arguments for format string

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

int lwprintf_vsnprintf_ex(lwprintf_t *const lw, char *s, size_t n, const char *format, va_list arg)

Write formatted data from variable argument list to sized buffer.

Parameters
  • [inout] lw – LwPRINTF instance. Set to NULL to use default instance

  • [in] s – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • [in] n – Maximum number of bytes to be used in the buffer. The generated string has a length of at most n - 1, leaving space for the additional terminating null character

  • [in] format – C string that contains a format string that follows the same specifications as format in printf

  • [in] arg – A value identifying a variable arguments list initialized with va_start. va_list is a special type defined in <cstdarg>.

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

int lwprintf_snprintf_ex(lwprintf_t *const lw, char *s, size_t n, const char *format, ...)

Write formatted data from variable argument list to sized buffer.

Parameters
  • [inout] lw – LwPRINTF instance. Set to NULL to use default instance

  • [in] s – Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least n characters

  • [in] n – Maximum number of bytes to be used in the buffer. The generated string has a length of at most n - 1, leaving space for the additional terminating null character

  • [in] format – C string that contains a format string that follows the same specifications as format in printf

  • [in] ... – Optional arguments for format string

Returns

The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.

struct lwprintf_t
#include <lwprintf.h>

LwPRINTF instance.

Public Members

lwprintf_output_fn out_fn

Output function for direct print operations

LWPRINTF_CFG_OS_MUTEX_HANDLE mutex

OS mutex handle