From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 1/4] util: Introduce util_debug_va
Date: Fri, 8 Jan 2021 13:15:10 -0800 [thread overview]
Message-ID: <20210108211513.5180-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This introduces util_debug_va which can take a va_list that enables
callers to create wrapper functions if they need to.
---
src/shared/util.c | 19 ++++++++++++++-----
src/shared/util.h | 4 ++++
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/shared/util.c b/src/shared/util.c
index 525302164..9c2054211 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -15,7 +15,6 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <ctype.h>
-#include <stdarg.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -42,20 +41,30 @@ void *btd_malloc(size_t size)
return NULL;
}
+void util_debug_va(util_debug_func_t function, void *user_data,
+ const char *format, va_list va)
+{
+ char str[78];
+
+ if (!function || !format)
+ return;
+
+ vsnprintf(str, sizeof(str), format, va);
+
+ function(str, user_data);
+}
+
void util_debug(util_debug_func_t function, void *user_data,
const char *format, ...)
{
- char str[78];
va_list ap;
if (!function || !format)
return;
va_start(ap, format);
- vsnprintf(str, sizeof(str), format, ap);
+ util_debug_va(function, user_data, format, ap);
va_end(ap);
-
- function(str, user_data);
}
void util_hexdump(const char dir, const unsigned char *buf, size_t len,
diff --git a/src/shared/util.h b/src/shared/util.h
index 6fb702797..d6de55885 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -10,6 +10,7 @@
#include <stdint.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <alloca.h>
#include <byteswap.h>
#include <string.h>
@@ -89,6 +90,9 @@ void *btd_malloc(size_t size);
typedef void (*util_debug_func_t)(const char *str, void *user_data);
+void util_debug_va(util_debug_func_t function, void *user_data,
+ const char *format, va_list va);
+
void util_debug(util_debug_func_t function, void *user_data,
const char *format, ...)
__attribute__((format(printf, 3, 4)));
--
2.26.2
next reply other threads:[~2021-01-08 21:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-08 21:15 Luiz Augusto von Dentz [this message]
2021-01-08 21:15 ` [PATCH BlueZ 2/4] shared/att: Add debug level to bt_att_set_debug Luiz Augusto von Dentz
2021-01-08 21:15 ` [PATCH BlueZ 3/4] device: Enable ATT layer debugging Luiz Augusto von Dentz
2021-01-08 21:15 ` [PATCH BlueZ 4/4] gatt: Fix assuming service changed has been subscribed Luiz Augusto von Dentz
2021-01-20 9:29 ` Sathish Narasimman
2021-01-20 15:35 ` Luiz Augusto von Dentz
2021-01-08 21:40 ` [BlueZ,1/4] util: Introduce util_debug_va bluez.test.bot
2021-01-11 16:46 ` Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210108211513.5180-1-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).