summaryrefslogtreecommitdiff
path: root/include/linux/kernel.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-05-01 03:05:14 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2022-06-09 14:26:22 -0400
commit02c1aead2a7d47c9cba28bfcaf9b09f64a8fa667 (patch)
treeacfbd99da1e50f0a6842e49c45c897aa2dd981f3 /include/linux/kernel.h
parenta72d165bed2e26f9ea3d7aadccd0adcc3448991c (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/kernel.h')
-rw-r--r--include/linux/kernel.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index fe6efb24d151..5c4f4b6d36ab 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -207,6 +207,10 @@ extern int num_to_str(char *buf, int size,
/* lib/printf utilities */
+struct printbuf;
+extern __printf(2, 3) void prt_printf(struct printbuf *out, const char *fmt, ...);
+extern __printf(2, 0) void prt_vprintf(struct printbuf *out, const char *fmt, va_list);
+
extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...);
extern __printf(2, 0) int vsprintf(char *buf, const char *, va_list);
extern __printf(3, 4)