iPXE
vsprintf.h
Go to the documentation of this file.
00001 #ifndef _IPXE_VSPRINTF_H
00002 #define _IPXE_VSPRINTF_H
00003 
00004 /** @file
00005  *
00006  * printf() and friends
00007  *
00008  * Etherboot's printf() functions understand the following subset of
00009  * the standard C printf()'s format specifiers:
00010  *
00011  *      - Flag characters
00012  *              - '#'           - Alternate form (i.e. "0x" prefix)
00013  *              - '0'           - Zero-pad
00014  *      - Field widths
00015  *      - Length modifiers
00016  *              - 'hh'          - Signed / unsigned char
00017  *              - 'h'           - Signed / unsigned short
00018  *              - 'l'           - Signed / unsigned long
00019  *              - 'll'          - Signed / unsigned long long
00020  *              - 'z'           - Signed / unsigned size_t
00021  *      - Conversion specifiers
00022  *              - 'd'           - Signed decimal
00023  *              - 'x','X'       - Unsigned hexadecimal
00024  *              - 'c'           - Character
00025  *              - 's'           - String
00026  *              - 'p'           - Pointer
00027  *
00028  * Hexadecimal numbers are always zero-padded to the specified field
00029  * width (if any); decimal numbers are always space-padded.  Decimal
00030  * long longs are not supported.
00031  *
00032  */
00033 
00034 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00035 
00036 #include <stdint.h>
00037 #include <stdarg.h>
00038 #include <stdio.h>
00039 
00040 /**
00041  * A printf context
00042  *
00043  * Contexts are used in order to be able to share code between
00044  * vprintf() and vsnprintf(), without requiring the allocation of a
00045  * buffer for vprintf().
00046  */
00047 struct printf_context {
00048         /**
00049          * Character handler
00050          *
00051          * @v ctx       Context
00052          * @v c         Character
00053          *
00054          * This method is called for each character written to the
00055          * formatted string.
00056          */
00057         void ( * handler ) ( struct printf_context *ctx, unsigned int c );
00058         /** Length of formatted string
00059          *
00060          * When handler() is called, @len will be set to the number of
00061          * characters written so far (i.e. zero for the first call to
00062          * handler()).
00063          */
00064         size_t len;
00065 };
00066 
00067 extern size_t vcprintf ( struct printf_context *ctx, const char *fmt,
00068                          va_list args );
00069 extern int vssnprintf ( char *buf, ssize_t ssize, const char *fmt,
00070                         va_list args );
00071 extern int __attribute__ (( format ( printf, 3, 4 ) ))
00072 ssnprintf ( char *buf, ssize_t ssize, const char *fmt, ... );
00073 
00074 #endif /* _IPXE_VSPRINTF_H */