Make vsprintf reentrant. More importantly, eliminate global variable.

Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
Acked-by: Myles Watson <mylesgw@gmail.com>


git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4307 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Patrick Georgi 2009-05-26 14:31:37 +00:00
parent f2152ecf4f
commit 736221f1b2
1 changed files with 11 additions and 11 deletions

View File

@ -13,22 +13,22 @@
int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args); int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args);
/* FIXME this global makes vsprintf non-reentrant */ int vsprintf(char * buf, const char *fmt, va_list args)
{
char *str_buf;
static char *str_buf; /* this function is only used by vsprint.
static void str_tx_byte(unsigned char byte) To keep str_buf local (for reentrancy
and to avoid .bss use, nest it */
void str_tx_byte(unsigned char byte)
{ {
*str_buf = byte; *str_buf = byte;
str_buf++; str_buf++;
} }
int vsprintf(char * buf, const char *fmt, va_list args)
{
int i; int i;
str_buf = buf; str_buf = buf;
i = vtxprintf(str_tx_byte, fmt, args); i = vtxprintf(str_tx_byte, fmt, args);
/* maeder/Ispiri -- The null termination was missing a deference */
/* and was just zeroing out the pointer instead */
*str_buf = '\0'; *str_buf = '\0';
return i; return i;
} }