coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
vsprintf.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/vtxprintf.h>
4 #include <string.h>
5 
7  char *str_buf;
8  size_t buf_limit;
9 };
10 
11 static void str_tx_byte(unsigned char byte, void *data)
12 {
13  struct vsnprintf_context *ctx = data;
14  if (ctx->buf_limit) {
15  *ctx->str_buf = byte;
16  ctx->str_buf++;
17  ctx->buf_limit--;
18  }
19 }
20 
21 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
22 {
23  int i;
24  struct vsnprintf_context ctx;
25 
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';
31 
32  return i;
33 }
34 
35 int snprintf(char *buf, size_t size, const char *fmt, ...)
36 {
37  va_list args;
38  int i;
39 
40  va_start(args, fmt);
41  i = vsnprintf(buf, size, fmt, args);
42  va_end(args);
43 
44  return i;
45 }
struct @413::@414 args
static uint8_t * buf
Definition: uart.c:7
#define va_end(v)
Definition: stdarg.h:14
#define va_start(v, l)
Note: This file is only for POSIX compatibility, and is meant to be chain-included via string....
Definition: stdarg.h:13
__builtin_va_list va_list
Definition: stdarg.h:16
size_t buf_limit
Definition: vsprintf.c:8
char * str_buf
Definition: vsprintf.c:7
static void str_tx_byte(unsigned char byte, void *data)
Definition: vsprintf.c:11
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Definition: vsprintf.c:21
int snprintf(char *buf, size_t size, const char *fmt,...)
Note: This file is only for POSIX compatibility, and is meant to be chain-included via string....
Definition: vsprintf.c:35
int vtxprintf(void(*tx_byte)(unsigned char byte, void *data), const char *fmt, va_list args, void *data)
Definition: vtxprintf.c:102