]> git.sesse.net Git - bcachefs-tools-debian/blob - linux/printbuf_userspace.c
Update bcachefs sources to 8d3fc97ca3 bcachefs: Fixes for building in userspace
[bcachefs-tools-debian] / linux / printbuf_userspace.c
1
2 #include <stdio.h>
3 #include <linux/printbuf.h>
4
5 void prt_vprintf(struct printbuf *out, const char *fmt, va_list args)
6 {
7         int len;
8
9         do {
10                 va_list args2;
11
12                 va_copy(args2, args);
13                 len = vsnprintf(out->buf + out->pos, printbuf_remaining(out), fmt, args2);
14         } while (len + 1 >= printbuf_remaining(out) &&
15                  !printbuf_make_room(out, len + 1));
16
17         len = min_t(size_t, len,
18                   printbuf_remaining(out) ? printbuf_remaining(out) - 1 : 0);
19         out->pos += len;
20 }
21
22 void prt_printf(struct printbuf *out, const char *fmt, ...)
23 {
24         va_list args;
25
26         va_start(args, fmt);
27         prt_vprintf(out, fmt, args);
28         va_end(args);
29 }
30
31 void prt_u64(struct printbuf *out, u64 v)
32 {
33         prt_printf(out, "%llu", v);
34 }