coreboot/src/console/vsprintf.c
<<
>>
Prefs
   1/*
   2 * This file is part of the coreboot project.
   3 *
   4 * Copyright (C) 2009 coresystems GmbH
   5 *
   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.
  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
  20 */
  21
  22#include <string.h>
  23#include <smp/spinlock.h>
  24#include <console/vtxprintf.h>
  25
  26DECLARE_SPIN_LOCK(vsprintf_lock)
  27
  28static char *str_buf;
  29
  30static void str_tx_byte(unsigned char byte)
  31{
  32        *str_buf = byte;
  33        str_buf++;
  34}
  35
  36static int vsprintf(char *buf, const char *fmt, va_list args)
  37{
  38        int i;
  39
  40        spin_lock(&vsprintf_lock);
  41
  42        str_buf = buf;
  43        i = vtxprintf(str_tx_byte, fmt, args);
  44        *str_buf = '\0';
  45
  46        spin_unlock(&vsprintf_lock);
  47
  48        return i;
  49}
  50
  51int sprintf(char *buf, const char *fmt, ...)
  52{
  53        va_list args;
  54        int i;
  55
  56        va_start(args, fmt);
  57        i = vsprintf(buf, fmt, args);
  58        va_end(args);
  59
  60        return i;
  61}
  62
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.