Common: add internal bt_common_custom_vsnprintf()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 23 Feb 2018 03:01:15 +0000 (22:01 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 03:32:03 +0000 (23:32 -0400)
commit85cd02cf3c1ded45ef8664ae3be7728ba1f05af6
tree5867aad509c9ee5b0c35216494e7dae625dd6069
parentdeaa6f85e512084aafa0ec0576ee31debb6ac75d
Common: add internal bt_common_custom_vsnprintf()

This new utility function (and its corresponding
bt_common_custom_snprintf()) is like vsnprintf(), but it also allows to
use custom conversion specifiers with the help of a user callback which
consumes one or more variadic arguments and writes to the current output
buffer position according to the custom conversion specifier.

For example, it allows the following:

    bt_common_custom_snprintf(buf, buf_size, '@', handle_specifier,
                              NULL, "hello %d world %@s (%02x-%@+d)",
                              -23, my_object, 17.5, "meow", my_fd);

Here, the `%d` and `%02x` conversion specifiers are used to consume the
`-23` and `17.5` arguments as you would expect, but the custom `%@s` and
`%@+d` specifiers consume the `my_object`, `"meow"`, and `my_fd`
parameters thanks to the user-provided handle_specifier() callback.

See the block comment above the bt_common_custom_vsnprintf() declaration
for more details and for limitations regarding the format string.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
common/common.c
include/babeltrace/common-internal.h
This page took 0.024594 seconds and 4 git commands to generate.