2003-04-22 21:02:15 +02:00
|
|
|
/*
|
|
|
|
* linux/lib/vsprintf.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
|
|
|
|
/*
|
|
|
|
* Wirzenius wrote this portably, Torvalds fucked it up :-)
|
|
|
|
*/
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2004-05-28 17:07:03 +02:00
|
|
|
int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args);
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2004-05-28 17:07:03 +02:00
|
|
|
/* FIXME this global makes vsprintf non-reentrant */
|
2003-04-22 21:02:15 +02:00
|
|
|
|
|
|
|
static char *str_buf;
|
|
|
|
static void str_tx_byte(unsigned char byte)
|
|
|
|
{
|
|
|
|
*str_buf = byte;
|
|
|
|
str_buf++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vsprintf(char * buf, const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
str_buf = buf;
|
|
|
|
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';
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sprintf(char * buf, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
i=vsprintf(buf,fmt,args);
|
|
|
|
va_end(args);
|
|
|
|
return i;
|
|
|
|
}
|