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(lwobj, s, format, ...)
Write formatted data from variable argument list to sized buffer.
- Parameters
lwobj – [inout] LwPRINTF instance. Set to
NULL
to use default instances – [in] Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least
n
charactersformat – [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 also
- 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
charactersn – [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 characterformat – [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
charactersn – [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 characterformat – [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
charactersformat – [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_protect()
Manually enable mutual exclusion.
- Returns
1
if protected,0
otherwise
-
lwprintf_unprotect()
Manually disable mutual exclusion.
- Returns
1
if protected,0
otherwise
-
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
charactersn – [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 characterformat – [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
charactersn – [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 characterformat – [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
charactersformat – [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
charactersn – [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 characterformat – [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
charactersn – [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 characterformat – [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
charactersformat – [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 *lwobj)
Callback function for character output.
- Param ch
[in] Character to print
- Param lwobj
[in] LwPRINTF instance
- Return
ch
on success,0
to terminate further string processing
Functions
-
uint8_t lwprintf_init_ex(lwprintf_t *lwobj, lwprintf_output_fn out_fn)
Initialize LwPRINTF instance.
- Parameters
lwobj – [inout] LwPRINTF working instance
out_fn – [in] Output function used for print operation
- Returns
1
on success,0
otherwise
-
int lwprintf_vprintf_ex(lwprintf_t *const lwobj, const char *format, va_list arg)
Print formatted data from variable argument list to the output.
- Parameters
lwobj – [inout] LwPRINTF instance. Set to
NULL
to use default instanceformat – [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.
-
int lwprintf_printf_ex(lwprintf_t *const lwobj, const char *format, ...)
Print formatted data to the output.
- Parameters
lwobj – [inout] LwPRINTF instance. Set to
NULL
to use default instanceformat – [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.
-
int lwprintf_vsnprintf_ex(lwprintf_t *const lwobj, char *s, size_t n, const char *format, va_list arg)
Write formatted data from variable argument list to sized buffer.
- Parameters
lwobj – [inout] LwPRINTF instance. Set to
NULL
to use default instances – [in] Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least
n
charactersn – [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 characterformat – [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.
-
int lwprintf_snprintf_ex(lwprintf_t *const lwobj, char *s, size_t n, const char *format, ...)
Write formatted data from variable argument list to sized buffer.
- Parameters
lwobj – [inout] LwPRINTF instance. Set to
NULL
to use default instances – [in] Pointer to a buffer where the resulting C-string is stored. The buffer should have a size of at least
n
charactersn – [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 characterformat – [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.
-
uint8_t lwprintf_protect_ex(lwprintf_t *const lwobj)
Manually enable mutual exclusion.
- Parameters
lwobj – [inout] LwPRINTF instance. Set to
NULL
to use default instance- Returns
1
if protected,0
otherwise
-
uint8_t lwprintf_unprotect_ex(lwprintf_t *const lwobj)
Manually disable mutual exclusion.
- Parameters
lwobj – [inout] LwPRINTF instance. Set to
NULL
to use default instance- Returns
1
if protection disabled,0
otherwise
-
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
-
lwprintf_output_fn out_fn
-
LWPRINTF_UNUSED(x)