diff options
author | David Lamparter <equinox@diac24.net> | 2021-02-19 00:08:11 +0100 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2021-03-30 22:34:51 +0200 |
commit | a4cb97a6c1d8718be40a16c1c7fc0b2738d17947 (patch) | |
tree | ac4c75d84887952de988e85a98b016aff5f5aaa6 /lib/printfrr.h | |
parent | lib: add `%pFB` extension to print struct fbuf * (diff) | |
download | frr-a4cb97a6c1d8718be40a16c1c7fc0b2738d17947.tar.xz frr-a4cb97a6c1d8718be40a16c1c7fc0b2738d17947.zip |
lib: add `%*pHX` + `%*pHS` hexdump in printfrr
(I'll get to `zlog_hexdump()` in a separate pass.)
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/printfrr.h')
-rw-r--r-- | lib/printfrr.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/printfrr.h b/lib/printfrr.h index 8ea8fd69a..7083e8b58 100644 --- a/lib/printfrr.h +++ b/lib/printfrr.h @@ -227,7 +227,11 @@ void printfrr_ext_reg(const struct printfrr_ext *); } \ /* end */ -/* fbuf helper functions */ +/* fbuf helper functions - note all 3 of these return the length that would + * be written regardless of how much space was available in the buffer, as + * needed for implementing printfrr extensions. (They also accept NULL buf + * for that.) + */ static inline ssize_t bputs(struct fbuf *buf, const char *str) { @@ -251,6 +255,17 @@ static inline ssize_t bputch(struct fbuf *buf, char ch) return 1; } +static inline ssize_t bputhex(struct fbuf *buf, uint8_t val) +{ + static const char hexch[] = "0123456789abcdef"; + + if (buf && buf->pos < buf->buf + buf->len) + *buf->pos++ = hexch[(val >> 4) & 0xf]; + if (buf && buf->pos < buf->buf + buf->len) + *buf->pos++ = hexch[val & 0xf]; + return 2; +} + /* %pVA extension, equivalent to Linux kernel %pV */ struct va_format { @@ -261,6 +276,13 @@ struct va_format { #ifdef _FRR_ATTRIBUTE_PRINTFRR #pragma FRR printfrr_ext "%pFB" (struct fbuf *) #pragma FRR printfrr_ext "%pVA" (struct va_format *) + +#pragma FRR printfrr_ext "%pHX" (signed char *) +#pragma FRR printfrr_ext "%pHX" (unsigned char *) +#pragma FRR printfrr_ext "%pHX" (void *) +#pragma FRR printfrr_ext "%pHS" (signed char *) +#pragma FRR printfrr_ext "%pHS" (unsigned char *) +#pragma FRR printfrr_ext "%pHS" (void *) #endif /* when using non-ISO-C compatible extension specifiers... */ |