From: Arran Cudbard-Bell Date: Tue, 4 Oct 2022 00:27:32 +0000 (-0400) Subject: Add 'v' variants to strerror logging functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab0e3b34251ff8bfa0c7ab67e1bc2ff9278e6515;p=thirdparty%2Ffreeradius-server.git Add 'v' variants to strerror logging functions --- diff --git a/src/lib/util/strerror.c b/src/lib/util/strerror.c index 4204e716d77..0afd7dce06a 100644 --- a/src/lib/util/strerror.c +++ b/src/lib/util/strerror.c @@ -225,39 +225,38 @@ static fr_log_entry_t *strerror_vprintf_push(fr_log_buffer_t *buffer, char const * * @param[in] fmt printf style format string. * If NULL clears any existing messages. - * @param[in] ... Arguments for the format string. + * @param[in] ap Arguments for the format string. * * @hidecallergraph */ -void fr_strerror_printf(char const *fmt, ...) +void fr_strerror_vprintf(char const *fmt, va_list ap) { - va_list ap; + va_list our_ap; - va_start(ap, fmt); - strerror_vprintf(fmt, ap); - va_end(ap); + va_copy(our_ap, ap); + strerror_vprintf(fmt, our_ap); + va_end(our_ap); } /** Add a message to an existing stack of messages at the tail * * @param[in] fmt printf style format string. - * If NULL clears any existing messages. - * @param[in] ... Arguments for the format string. + * @param[in] ap Arguments for the format string. * * @hidecallergraph */ -void fr_strerror_printf_push(char const *fmt, ...) +void fr_strerror_vprintf_push(char const *fmt, va_list ap) { - va_list ap; + va_list our_ap; fr_log_buffer_t *buffer; fr_log_entry_t *entry; buffer = fr_strerror_init(); if (unlikely(!buffer)) return; - va_start(ap, fmt); - entry = strerror_vprintf_push(buffer, fmt, ap); - va_end(ap); + va_copy(our_ap, ap); + entry = strerror_vprintf_push(buffer, fmt, our_ap); + va_end(our_ap); if (unlikely(!entry)) return; @@ -267,23 +266,22 @@ void fr_strerror_printf_push(char const *fmt, ...) /** Add a message to an existing stack of messages at the head * * @param[in] fmt printf style format string. - * If NULL clears any existing messages. - * @param[in] ... Arguments for the format string. + * @param[in] ap Arguments for the format string. * * @hidecallergraph */ -void fr_strerror_printf_push_head(char const *fmt, ...) +void fr_strerror_vprintf_push_head(char const *fmt, va_list ap) { - va_list ap; + va_list our_ap; fr_log_buffer_t *buffer; fr_log_entry_t *entry; buffer = fr_strerror_init(); if (unlikely(!buffer)) return; - va_start(ap, fmt); - entry = strerror_vprintf_push(buffer, fmt, ap); - va_end(ap); + va_copy(our_ap, ap); + entry = strerror_vprintf_push(buffer, fmt, our_ap); + va_end(our_ap); if (unlikely(!entry)) return; @@ -296,18 +294,18 @@ void fr_strerror_printf_push_head(char const *fmt, ...) * @param[in] offset Positive offset to show where the error * should be positioned. * @param[in] fmt Error string. - * @param[in] ... Arguments for the error string. + * @param[in] ap Arguments for the error string. * * @hidecallergraph */ -void fr_strerror_marker_printf(char const *subject, size_t offset, char const *fmt, ...) +void fr_strerror_marker_vprintf(char const *subject, size_t offset, char const *fmt, va_list ap) { - va_list ap; + va_list our_ap; fr_log_entry_t *entry; - va_start(ap, fmt); - entry = strerror_vprintf(fmt, ap); - va_end(ap); + va_copy(our_ap, ap); + entry = strerror_vprintf(fmt, our_ap); + va_end(our_ap); if (unlikely(!entry)) return; @@ -321,22 +319,22 @@ void fr_strerror_marker_printf(char const *subject, size_t offset, char const *f * @param[in] offset Positive offset to show where the error * should be positioned. * @param[in] fmt Error string. - * @param[in] ... Arguments for the error string. + * @param[in] ap Arguments for the error string. * * @hidecallergraph */ -void fr_strerror_marker_printf_push(char const *subject, size_t offset, char const *fmt, ...) +void fr_strerror_marker_vprintf_push(char const *subject, size_t offset, char const *fmt, va_list ap) { - va_list ap; + va_list our_ap; fr_log_entry_t *entry; fr_log_buffer_t *buffer; buffer = fr_strerror_init(); if (unlikely(!buffer)) return; - va_start(ap, fmt); - entry = strerror_vprintf_push(buffer, fmt, ap); - va_end(ap); + va_copy(our_ap, ap); + entry = strerror_vprintf_push(buffer, fmt, our_ap); + va_end(our_ap); if (unlikely(!entry)) return; @@ -352,22 +350,22 @@ void fr_strerror_marker_printf_push(char const *subject, size_t offset, char con * @param[in] offset Positive offset to show where the error * should be positioned. * @param[in] fmt Error string. - * @param[in] ... Arguments for the error string. + * @param[in] ap Arguments for the error string. * * @hidecallergraph */ -void fr_strerror_marker_printf_push_head(char const *subject, size_t offset, char const *fmt, ...) +void fr_strerror_marker_vprintf_push_head(char const *subject, size_t offset, char const *fmt, va_list ap) { - va_list ap; + va_list our_ap; fr_log_entry_t *entry; fr_log_buffer_t *buffer; buffer = fr_strerror_init(); if (unlikely(!buffer)) return; - va_start(ap, fmt); - entry = strerror_vprintf_push(buffer, fmt, ap); - va_end(ap); + va_copy(our_ap, ap); + entry = strerror_vprintf_push(buffer, fmt, our_ap); + va_end(our_ap); if (unlikely(!entry)) return; diff --git a/src/lib/util/strerror.h b/src/lib/util/strerror.h index 1a7f6c49b44..38a3edfc552 100644 --- a/src/lib/util/strerror.h +++ b/src/lib/util/strerror.h @@ -31,6 +31,7 @@ extern "C" { #include #include #include +#include /** @name Add an error string to the thread local error stack * @@ -40,14 +41,68 @@ extern "C" { * * @{ */ + /** @hidecallergraph */ -void fr_strerror_printf(char const *fmt, ...) CC_HINT(nonnull) CC_HINT(format (printf, 1, 2)); +void fr_strerror_vprintf(char const *fmt, va_list ap); /** @hidecallergraph */ -void fr_strerror_printf_push(char const *fmt, ...) CC_HINT(nonnull) CC_HINT(format (printf, 1, 2)); +void fr_strerror_vprintf_push(char const *fmt, va_list ap); /** @hidecallergraph */ -void fr_strerror_printf_push_head(char const *fmt, ...) CC_HINT(nonnull) CC_HINT(format (printf, 1, 2)); +void fr_strerror_vprintf_push_head(char const *fmt, va_list ap); + +/** Log to thread local error buffer + * + * @param[in] fmt printf style format string. + * If NULL clears any existing messages. + * @param[in] ... Arguments for the format string. + * + * @hidecallergraph + */ +static inline CC_HINT(nonnull) CC_HINT(format (printf, 1, 2)) +void fr_strerror_printf(char const *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fr_strerror_vprintf(fmt, ap); + va_end(ap); +} + +/** Add a message to an existing stack of messages at the tail + * + * @param[in] fmt printf style format string. + * @param[in] ... Arguments for the format string. + * + * @hidecallergraph + */ + +static inline CC_HINT(nonnull) CC_HINT(format (printf, 1, 2)) +void fr_strerror_printf_push(char const *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fr_strerror_vprintf_push(fmt, ap); + va_end(ap); +} + +/** Add a message to an existing stack of messages at the head + * + * @param[in] fmt printf style format string. + * @param[in] ... Arguments for the format string. + * + * @hidecallergraph + */ +static inline CC_HINT(nonnull) CC_HINT(format (printf, 1, 2)) +void fr_strerror_printf_push_head(char const *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fr_strerror_vprintf_push_head(fmt, ap); + va_end(ap); +} /** @} */ /** @name Add an error string with marker to the thread local error stack @@ -59,13 +114,73 @@ void fr_strerror_printf_push_head(char const *fmt, ...) CC_HINT(nonnull) CC_HIN * @{ */ /** @hidecallergraph */ -void fr_strerror_marker_printf(char const *subject, size_t offset, char const *fmt, ...) CC_HINT(nonnull) CC_HINT(format (printf, 3, 4)); +void fr_strerror_marker_vprintf(char const *subject, size_t offset, char const *fmt, va_list ap); /** @hidecallergraph */ -void fr_strerror_marker_printf_push(char const *subject, size_t offset, char const *fmt, ...) CC_HINT(nonnull) CC_HINT(format (printf, 3, 4)); +void fr_strerror_marker_vprintf_push(char const *subject, size_t offset, char const *fmt, va_list ap); /** @hidecallergraph */ -void fr_strerror_marker_printf_push_head(char const *subject, size_t offset, char const *fmt, ...) CC_HINT(nonnull) CC_HINT(format (printf, 3, 4)); +void fr_strerror_marker_vprintf_push_head(char const *subject, size_t offset, char const *fmt, va_list ap); + +/** Add an error marker to an existing stack of messages + * + * @param[in] subject to mark up. + * @param[in] offset Positive offset to show where the error + * should be positioned. + * @param[in] fmt Error string. + * @param[in] ... Arguments for the error string. + * + * @hidecallergraph + */ +static inline CC_HINT(nonnull) CC_HINT(format (printf, 3, 4)) +void fr_strerror_marker_printf(char const *subject, size_t offset, char const *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fr_strerror_marker_vprintf(subject, offset, fmt, ap); + va_end(ap); +} + +/** Add an error marker to an existing stack of messages at the tail + * + * @param[in] subject to mark up. + * @param[in] offset Positive offset to show where the error + * should be positioned. + * @param[in] fmt Error string. + * @param[in] ... Arguments for the error string. + * + * @hidecallergraph + */ +static inline CC_HINT(nonnull) CC_HINT(format (printf, 3, 4)) +void fr_strerror_marker_printf_push(char const *subject, size_t offset, char const *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fr_strerror_marker_vprintf_push(subject, offset, fmt, ap); + va_end(ap); +} + +/** Add an error marker to an existing stack of messages at the head + * + * @param[in] subject to mark up. + * @param[in] offset Positive offset to show where the error + * should be positioned. + * @param[in] fmt Error string. + * @param[in] ... Arguments for the error string. + * + * @hidecallergraph + */ +static inline CC_HINT(nonnull) CC_HINT(format (printf, 3, 4)) +void fr_strerror_marker_printf_push_head(char const *subject, size_t offset, char const *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fr_strerror_marker_vprintf_push_head(subject, offset, fmt, ap); + va_end(ap); +} /** @} */ /** @name Add a const error string to the thread local error stack