3rdparty/fsp: Update submodule to upstream master
[coreboot2.git] / src / console / vsprintf.c
blob086ed7cc7886b9fdfad104b931f2dceebeab437a
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/vtxprintf.h>
4 #include <stdio.h>
6 struct vsnprintf_context {
7 char *str_buf;
8 size_t buf_limit;
9 };
11 static void str_tx_byte(unsigned char byte, void *data)
13 struct vsnprintf_context *ctx = data;
14 if (ctx->buf_limit) {
15 *ctx->str_buf = byte;
16 ctx->str_buf++;
17 ctx->buf_limit--;
21 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
23 int i;
24 struct vsnprintf_context ctx;
26 ctx.str_buf = buf;
27 ctx.buf_limit = size ? size - 1 : 0;
28 i = vtxprintf(str_tx_byte, fmt, args, &ctx);
29 if (size)
30 *ctx.str_buf = '\0';
32 return i;
35 int snprintf(char *buf, size_t size, const char *fmt, ...)
37 va_list args;
38 int i;
40 va_start(args, fmt);
41 i = vsnprintf(buf, size, fmt, args);
42 va_end(args);
44 return i;