summaryrefslogtreecommitdiff
path: root/src/console/vsprintf.c
blob: 1cfb91f02cce06fcb67a72bb4e7d99f6ad823d76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 *  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>

int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args);

int vsprintf(char * buf, const char *fmt, va_list args)
{
	char *str_buf;

	/* this function is only used by vsprint.
	   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++;
	}

	int i;
	str_buf = buf;
	i = vtxprintf(str_tx_byte, fmt, args);
	*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;
}