diff --git a/include/debug.h b/include/debug.h index 4bac17cf1c9..cb184a6b5bc 100644 --- a/include/debug.h +++ b/include/debug.h @@ -1021,11 +1021,23 @@ extern "C" void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, unsigned int buflen); +/* Dump a buffer of data to a specified file descriptor. */ + +void lib_writebuffer(int fd, FAR const char *msg, + FAR const uint8_t *buffer, unsigned int buflen); + /* Do a pretty buffer dump from multiple buffers. */ void lib_dumpvbuffer(FAR const char *msg, FAR const struct iovec *iov, int iovcnt); +/* Do a pretty buffer dump from multiple buffers + * to a specified file descriptor. + */ + +void lib_writevbuffer(int fd, FAR const char *msg, + FAR const struct iovec *iov, int iovcnt); + /* The system logging interfaces are normally accessed via the macros * provided above. If the cross-compiler's C pre-processor supports a * variable number of macro arguments, then those macros below will map all diff --git a/libs/libc/misc/lib_dumpbuffer.c b/libs/libc/misc/lib_dumpbuffer.c index db1705fbb01..100d24a511e 100644 --- a/libs/libc/misc/lib_dumpbuffer.c +++ b/libs/libc/misc/lib_dumpbuffer.c @@ -54,3 +54,26 @@ void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, lib_dumpvbuffer(msg, &buf, 1); } + +/**************************************************************************** + * Name: lib_writebuffer + * + * Description: + * Do a pretty buffer dump to a specified file descriptor. + * + * A fairly large on-stack buffer is used for the case where timestamps are + * applied to each line. + * + ****************************************************************************/ + +void lib_writebuffer(int fd, FAR const char *msg, + FAR const uint8_t *buffer, unsigned int buflen) +{ + struct iovec buf = + { + .iov_base = (FAR char *)buffer, + .iov_len = buflen, + }; + + lib_writevbuffer(fd, msg, &buf, 1); +} diff --git a/libs/libc/misc/lib_dumpvbuffer.c b/libs/libc/misc/lib_dumpvbuffer.c index d9e10a1f0a6..3405d39df01 100644 --- a/libs/libc/misc/lib_dumpvbuffer.c +++ b/libs/libc/misc/lib_dumpvbuffer.c @@ -26,6 +26,7 @@ #include #include +#include #include /**************************************************************************** @@ -70,18 +71,19 @@ static char lib_nibble(unsigned char nibble) ****************************************************************************/ /**************************************************************************** - * Name: lib_dumpvbuffer + * Name: lib_writevbuffer * * Description: - * Do a pretty buffer dump from multiple buffers. + * Do a pretty buffer dump from multiple buffers to a specified file + * descriptor. * * A fairly large on-stack buffer is used for the case where timestamps are * applied to each line. * ****************************************************************************/ -void lib_dumpvbuffer(FAR const char *msg, FAR const struct iovec *iov, - int iovcnt) +void lib_writevbuffer(int fd, FAR const char *msg, + FAR const struct iovec *iov, int iovcnt) { FAR const struct iovec *piov = iov; FAR const uint8_t *iov_buf; @@ -96,7 +98,14 @@ void lib_dumpvbuffer(FAR const char *msg, FAR const struct iovec *iov, if (msg) { - syslog(LOG_INFO, "%s (%p):\n", msg, iov->iov_base); + if (fd > 0) + { + dprintf(fd, "%s (%p):\n", msg, iov->iov_base); + } + else + { + syslog(LOG_INFO, "%s (%p):\n", msg, iov->iov_base); + } } for (i = 0; i < iovcnt; i++) @@ -170,6 +179,30 @@ void lib_dumpvbuffer(FAR const char *msg, FAR const struct iovec *iov, *ptr++ = ' '; /* Plus 1 byte */ } - syslog(LOG_INFO, "%04x %s\n", i, line); + if (fd > 0) + { + dprintf(fd, "%04x %s\n", i, line); + } + else + { + syslog(LOG_INFO, "%04x %s\n", i, line); + } } } + +/**************************************************************************** + * Name: lib_dumpvbuffer + * + * Description: + * Do a pretty buffer dump from multiple buffers. + * + * A fairly large on-stack buffer is used for the case where timestamps are + * applied to each line. + * + ****************************************************************************/ + +void lib_dumpvbuffer(FAR const char *msg, FAR const struct iovec *iov, + int iovcnt) +{ + lib_writevbuffer(-1, msg, iov, iovcnt); +}