nb/intel/pineview: Remove unused code
[coreboot.git] / src / console / vsprintf.c
blob4892fdd1ff3092caa3231a107584bcc29f6404b0
1 /*
2 * This file is part of the coreboot project.
4 * Copyright (C) 2009 coresystems GmbH
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <console/vtxprintf.h>
18 #include <string.h>
19 #include <trace.h>
21 struct vsnprintf_context {
22 char *str_buf;
23 size_t buf_limit;
26 static void str_tx_byte(unsigned char byte, void *data)
28 struct vsnprintf_context *ctx = data;
29 if (ctx->buf_limit) {
30 *ctx->str_buf = byte;
31 ctx->str_buf++;
32 ctx->buf_limit--;
36 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
38 int i;
39 struct vsnprintf_context ctx;
41 DISABLE_TRACE;
43 ctx.str_buf = buf;
44 ctx.buf_limit = size ? size - 1 : 0;
45 i = vtxprintf(str_tx_byte, fmt, args, &ctx);
46 if (size)
47 *ctx.str_buf = '\0';
49 ENABLE_TRACE;
51 return i;
54 int snprintf(char *buf, size_t size, const char *fmt, ...)
56 va_list args;
57 int i;
59 va_start(args, fmt);
60 i = vsnprintf(buf, size, fmt, args);
61 va_end(args);
63 return i;