bfa6ffebab9989b3a4dbe91a9669883c22d2ef94
[coreboot.git] / src / console / vsprintf.c
1 /*
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  */
11 #include <stdarg.h>
12 #include <string.h>
13
14 int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args);
15
16 int vsprintf(char * buf, const char *fmt, va_list args)
17 {
18         char *str_buf;
19
20         /* this function is only used by vsprintf.
21            To keep str_buf local (for reentrancy
22            and to avoid .bss use, nest it */
23         void str_tx_byte(unsigned char byte)
24         {
25                 *str_buf = byte;
26                 str_buf++;
27         }
28
29         int i;
30         str_buf = buf;
31         i = vtxprintf(str_tx_byte, fmt, args);
32         *str_buf = '\0';
33         return i;
34 }
35
36 int 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 }