blob: 1ce6bd1e88df5af06acd52be5f7ec50019dc9a64 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001/*
2 * linux/lib/vsprintf.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
8/*
9 * Wirzenius wrote this portably, Torvalds fucked it up :-)
10 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000011#include <stdarg.h>
12#include <string.h>
13
Stefan Reinauer34e3a142004-05-28 15:07:03 +000014int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args);
Eric Biederman8ca8d762003-04-22 19:02:15 +000015
Stefan Reinauer34e3a142004-05-28 15:07:03 +000016/* FIXME this global makes vsprintf non-reentrant */
Eric Biederman8ca8d762003-04-22 19:02:15 +000017
Eric Biederman8ca8d762003-04-22 19:02:15 +000018static char *str_buf;
19static void str_tx_byte(unsigned char byte)
20{
21 *str_buf = byte;
22 str_buf++;
23}
24
25int vsprintf(char * buf, const char *fmt, va_list args)
26{
27 int i;
28 str_buf = buf;
29 i = vtxprintf(str_tx_byte, fmt, args);
30 /* maeder/Ispiri -- The null termination was missing a deference */
31 /* and was just zeroing out the pointer instead */
32 *str_buf = '\0';
33 return i;
34}
35
36int sprintf(char * buf, const char *fmt, ...)
37{
38 va_list args;
39 int i;
40
41 va_start(args, fmt);
42 i=vsprintf(buf,fmt,args);
43 va_end(args);
44 return i;
45}