blob: bfa6ffebab9989b3a4dbe91a9669883c22d2ef94 [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
Eric Biederman8ca8d762003-04-22 19:02:15 +000016int vsprintf(char * buf, const char *fmt, va_list args)
17{
Patrick Georgi736221f12009-05-26 14:31:37 +000018 char *str_buf;
19
Stefan Reinauerfc4226c2009-07-26 15:05:40 +000020 /* this function is only used by vsprintf.
Patrick Georgi736221f12009-05-26 14:31:37 +000021 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
Eric Biederman8ca8d762003-04-22 19:02:15 +000029 int i;
30 str_buf = buf;
31 i = vtxprintf(str_tx_byte, fmt, args);
Eric Biederman8ca8d762003-04-22 19:02:15 +000032 *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}