]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add 'v' variants to strerror logging functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 4 Oct 2022 00:27:32 +0000 (20:27 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 4 Oct 2022 00:43:21 +0000 (20:43 -0400)
src/lib/util/strerror.c
src/lib/util/strerror.h

index 4204e716d776352c2a86678717d27269d04c06a2..0afd7dce06a3730f81eacb6e0babec16da673f3d 100644 (file)
@@ -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;
 
index 1a7f6c49b44f46a74dd023a28eba0af80937d349..38a3edfc552af92b6a6ac01fa2f9d056111324cf 100644 (file)
@@ -31,6 +31,7 @@ extern "C" {
 #include <freeradius-devel/build.h>
 #include <freeradius-devel/missing.h>
 #include <string.h>
+#include <stdarg.h>
 
 /** @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