1 #ifndef _IPXE_VSPRINTF_H
2 #define _IPXE_VSPRINTF_H
3 
4 /** @file
5  *
6  * printf() and friends
7  *
8  * Etherboot's printf() functions understand the following subset of
9  * the standard C printf()'s format specifiers:
10  *
11  *	- Flag characters
12  *		- '#'		- Alternate form (i.e. "0x" prefix)
13  *		- '0'		- Zero-pad
14  *	- Field widths
15  *	- Length modifiers
16  *		- 'hh'		- Signed / unsigned char
17  *		- 'h'		- Signed / unsigned short
18  *		- 'l'		- Signed / unsigned long
19  *		- 'll'		- Signed / unsigned long long
20  *		- 'z'		- Signed / unsigned size_t
21  *	- Conversion specifiers
22  *		- 'd'		- Signed decimal
23  *		- 'x','X'	- Unsigned hexadecimal
24  *		- 'c'		- Character
25  *		- 's'		- String
26  *		- 'p'		- Pointer
27  *
28  * Hexadecimal numbers are always zero-padded to the specified field
29  * width (if any); decimal numbers are always space-padded.  Decimal
30  * long longs are not supported.
31  *
32  */
33 
34 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
35 
36 #include <stdint.h>
37 #include <stdarg.h>
38 #include <stdio.h>
39 
40 /**
41  * A printf context
42  *
43  * Contexts are used in order to be able to share code between
44  * vprintf() and vsnprintf(), without requiring the allocation of a
45  * buffer for vprintf().
46  */
47 struct printf_context {
48 	/**
49 	 * Character handler
50 	 *
51 	 * @v ctx	Context
52 	 * @v c		Character
53 	 *
54 	 * This method is called for each character written to the
55 	 * formatted string.
56 	 */
57 	void ( * handler ) ( struct printf_context *ctx, unsigned int c );
58 	/** Length of formatted string
59 	 *
60 	 * When handler() is called, @len will be set to the number of
61 	 * characters written so far (i.e. zero for the first call to
62 	 * handler()).
63 	 */
64 	size_t len;
65 };
66 
67 extern size_t vcprintf ( struct printf_context *ctx, const char *fmt,
68 			 va_list args );
69 extern int vssnprintf ( char *buf, ssize_t ssize, const char *fmt,
70 			va_list args );
71 extern int __attribute__ (( format ( printf, 3, 4 ) ))
72 ssnprintf ( char *buf, ssize_t ssize, const char *fmt, ... );
73 
74 #endif /* _IPXE_VSPRINTF_H */
75