LwPRINTF

group LWPRINTF

Lightweight stdio manager.

Defines

LWPRINTF_UNUSED(x)

Unused variable macro.

Parameters
  • [in] x: Unused variable

LWPRINTF_ARRAYSIZE(x)

Calculate size of statically allocated array.

Return

Number of array elements

Parameters
  • [in] x: Input array

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

Write formatted data from variable argument list to sized buffer.

Return

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

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] format: C string that contains a format string that follows the same specifications as format in printf

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

lwprintf_init(out_fn)

Initialize default LwPRINTF instance.

Return

1 on success, 0 otherwise

See

lwprintf_init_ex

Parameters
  • [in] out_fn: Output function used for print operation

lwprintf_vprintf(format, arg)

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

Return

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

Parameters
  • [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>.

lwprintf_printf(format, ...)

Print formatted data to the output with default LwPRINTF instance.

Return

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

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

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

lwprintf_vsnprintf(s, n, format, arg)

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

Return

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

Parameters
  • [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>.

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

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

Return

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

Parameters
  • [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

lwprintf_sprintf(s, format, ...)

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

Return

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

Parameters
  • [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] format: C string that contains a format string that follows the same specifications as format in printf

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

lwprintf

Print formatted data to the output with default LwPRINTF instance.

Return

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

Note

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

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

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

lwvprintf

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

Return

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

Note

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

Parameters
  • [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>.

lwvsnprintf

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

Return

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

Note

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

Parameters
  • [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>.

lwsnprintf

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

Return

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

Note

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

Parameters
  • [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

lwsprintf

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

Return

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

Note

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

Parameters
  • [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] format: C string that contains a format string that follows the same specifications as format in printf

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

printf

Print formatted data to the output with default LwPRINTF instance.

Return

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

Note

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

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

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

vprintf

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

Return

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

Note

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

Parameters
  • [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>.

vsnprintf

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

Return

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

Note

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

Parameters
  • [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>.

snprintf

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

Return

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

Note

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

Parameters
  • [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

sprintf

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

Return

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

Note

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

Parameters
  • [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] format: C string that contains a format string that follows the same specifications as format in printf

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

Typedefs

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

Callback function for character output.

Return

ch on success, 0 to terminate further string processing

Parameters
  • [in] ch: Character to print

  • [in] lw: LwPRINTF instance

Functions

uint8_t lwprintf_init_ex(lwprintf_t *lw, lwprintf_output_fn out_fn)

Initialize LwPRINTF instance.

Return

1 on success, 0 otherwise

Parameters
  • [inout] lw: LwPRINTF working instance

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

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

Print formatted data from variable argument list to the output.

Return

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

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>.

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

Print formatted data to the output.

Return

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

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

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.

Return

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

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>.

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.

Return

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

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

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