Documentation: Fix sphinx configuration
[coreboot.git] / src / console / vsprintf.c
blobd0c569bf598dc1460177b8722d834598914f91c1
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/vtxprintf.h>
4 #include <string.h>
5 #include <trace.h>
7 struct vsnprintf_context {
8 char *str_buf;
9 size_t buf_limit;
12 static void str_tx_byte(unsigned char byte, void *data)
14 struct vsnprintf_context *ctx = data;
15 if (ctx->buf_limit) {
16 *ctx->str_buf = byte;
17 ctx->str_buf++;
18 ctx->buf_limit--;
22 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
24 int i;
25 struct vsnprintf_context ctx;
27 DISABLE_TRACE;
29 ctx.str_buf = buf;
30 ctx.buf_limit = size ? size - 1 : 0;
31 i = vtxprintf(str_tx_byte, fmt, args, &ctx);
32 if (size)
33 *ctx.str_buf = '\0';
35 ENABLE_TRACE;
37 return i;
40 int snprintf(char *buf, size_t size, const char *fmt, ...)
42 va_list args;
43 int i;
45 va_start(args, fmt);
46 i = vsnprintf(buf, size, fmt, args);
47 va_end(args);
49 return i;