diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-05-01 03:05:14 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2022-06-09 14:26:22 -0400 |
commit | 02c1aead2a7d47c9cba28bfcaf9b09f64a8fa667 (patch) | |
tree | acfbd99da1e50f0a6842e49c45c897aa2dd981f3 /include/linux/string.h | |
parent | a72d165bed2e26f9ea3d7aadccd0adcc3448991c (diff) |
vsprintf: Convert to printbuf
This converts vsnprintf() to printbufs: instead of passing around raw
char * pointers for current buf position and end of buf, we have a real
type!
This makes the calling convention for our existing pretty printers a lot
saner and less error prone, plus printbufs add some new helpers that
make the code smaller and more readable, with a lot less crazy pointer
arithmetic.
There are a lot more refactorings to be done: this patch tries to stick
to just converting the calling conventions, as that needs to be done all
at once in order to avoid introducing a ton of wrappers that will just
be deleted.
Thankfully we have good unit tests for printf, and they have been run
and are all passing with this patch.
We have two new exported functions with this patch:
- prt_printf(), which is like snprintf but outputs to a printbuf
- prt_vprintf, like vsnprintf
These are the actual core print routines now - vsnprintf() is a wrapper
around prt_vprintf().
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'include/linux/string.h')
-rw-r--r-- | include/linux/string.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/include/linux/string.h b/include/linux/string.h index b6572aeca2f5..0a737d5b9203 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -195,7 +195,12 @@ int __sysfs_match_string(const char * const *array, size_t n, const char *s); */ #define sysfs_match_string(_a, _s) __sysfs_match_string(_a, ARRAY_SIZE(_a), _s) +struct printbuf; + #ifdef CONFIG_BINARY_PRINTF +void prt_vbinprintf(struct printbuf *out, const char *fmt, va_list args); +void prt_bstrprintf(struct printbuf *out, const char *fmt, const u32 *bin_buf); +void prt_bprintf(struct printbuf *out, const char *fmt, ...) __printf(2, 3); int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args); int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf); int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4); |