blob: 321ce814902419d267b9793b0dfd19fa6aa75ef2 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001/*
Stefan Reinauer52fc6b12009-10-24 13:06:04 +00002 * This file is part of the coreboot project.
Stefan Reinauer14e22772010-04-27 06:56:47 +00003 *
Stefan Reinauer52fc6b12009-10-24 13:06:04 +00004 * Copyright (C) 2009 coresystems GmbH
Eric Biederman8ca8d762003-04-22 19:02:15 +00005 *
Stefan Reinauer52fc6b12009-10-24 13:06:04 +00006 * 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.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
Eric Biederman8ca8d762003-04-22 19:02:15 +000020 */
21
Myles Watson58170782009-10-28 16:13:28 +000022#include <string.h>
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000023#include <console/vtxprintf.h>
Rudolf Marek7f0e9302011-09-02 23:23:41 +020024#include <trace.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000025
Vladimir Serbinenko22676582013-11-26 21:48:57 +010026struct vsprintf_context
Eric Biederman8ca8d762003-04-22 19:02:15 +000027{
Vladimir Serbinenko22676582013-11-26 21:48:57 +010028 char *str_buf;
29};
30
31static void str_tx_byte(unsigned char byte, void *data)
32{
33 struct vsprintf_context *ctx = data;
34 *ctx->str_buf = byte;
35 ctx->str_buf++;
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000036}
Patrick Georgi736221f12009-05-26 14:31:37 +000037
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000038static int vsprintf(char *buf, const char *fmt, va_list args)
39{
Eric Biederman8ca8d762003-04-22 19:02:15 +000040 int i;
Vladimir Serbinenko22676582013-11-26 21:48:57 +010041 struct vsprintf_context ctx;
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000042
Rudolf Marek7f0e9302011-09-02 23:23:41 +020043 DISABLE_TRACE;
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000044
Vladimir Serbinenko22676582013-11-26 21:48:57 +010045 ctx.str_buf = buf;
46 i = vtxdprintf(str_tx_byte, fmt, args, &ctx);
47 *ctx.str_buf = '\0';
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000048
Rudolf Marek7f0e9302011-09-02 23:23:41 +020049 ENABLE_TRACE;
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000050
Eric Biederman8ca8d762003-04-22 19:02:15 +000051 return i;
52}
53
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000054int sprintf(char *buf, const char *fmt, ...)
Eric Biederman8ca8d762003-04-22 19:02:15 +000055{
56 va_list args;
57 int i;
58
59 va_start(args, fmt);
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000060 i = vsprintf(buf, fmt, args);
Eric Biederman8ca8d762003-04-22 19:02:15 +000061 va_end(args);
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000062
Eric Biederman8ca8d762003-04-22 19:02:15 +000063 return i;
64}