coreboot/src/console/vsprintf.c
Elyes Haouas 08375b5082 tree: Remove unused <string.h>
Change-Id: I9ed1a82fcd3fc29124ddc406592bd45dc84d4628
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/82666
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Reviewed-by: Yidi Lin <yidilin@google.com>
2024-05-29 10:34:08 +00:00

45 lines
788 B
C

/* SPDX-License-Identifier: GPL-2.0-only */
#include <console/vtxprintf.h>
#include <stdio.h>
struct vsnprintf_context {
char *str_buf;
size_t buf_limit;
};
static void str_tx_byte(unsigned char byte, void *data)
{
struct vsnprintf_context *ctx = data;
if (ctx->buf_limit) {
*ctx->str_buf = byte;
ctx->str_buf++;
ctx->buf_limit--;
}
}
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
int i;
struct vsnprintf_context ctx;
ctx.str_buf = buf;
ctx.buf_limit = size ? size - 1 : 0;
i = vtxprintf(str_tx_byte, fmt, args, &ctx);
if (size)
*ctx.str_buf = '\0';
return i;
}
int snprintf(char *buf, size_t size, const char *fmt, ...)
{
va_list args;
int i;
va_start(args, fmt);
i = vsnprintf(buf, size, fmt, args);
va_end(args);
return i;
}