1 #ifndef _STDIO_H
2 #define _STDIO_H
3
4 FILE_LICENCE ( GPL2_OR_LATER );
5
6 #include <stdint.h>
7 #include <stdarg.h>
8
9 extern int __attribute__ (( format ( printf, 1, 2 ) ))
10 printf ( const char *fmt, ... );
11
12 extern int __attribute__ (( format ( printf, 3, 4 ) ))
13 snprintf ( char *buf, size_t size, const char *fmt, ... );
14
15 extern int __attribute__ (( format ( printf, 2, 3 ) ))
16 asprintf ( char **strp, const char *fmt, ... );
17
18 extern int vprintf ( const char *fmt, va_list args );
19
20 extern int vsnprintf ( char *buf, size_t size, const char *fmt, va_list args );
21
22 extern int vasprintf ( char **strp, const char *fmt, va_list args );
23
24 /**
25 * Write a formatted string to a buffer
26 *
27 * @v buf Buffer into which to write the string
28 * @v fmt Format string
29 * @v ... Arguments corresponding to the format string
30 * @ret len Length of formatted string
31 */
32 #define sprintf( buf, fmt, ... ) \
33 snprintf ( (buf), ~( ( size_t ) 0 ), (fmt), ## __VA_ARGS__ )
34
35 /**
36 * Write a formatted string to a buffer
37 *
38 * @v buf Buffer into which to write the string
39 * @v fmt Format string
40 * @v args Arguments corresponding to the format string
41 * @ret len Length of formatted string
42 */
vsprintf(char * buf,const char * fmt,va_list args)43 static inline int vsprintf ( char *buf, const char *fmt, va_list args ) {
44 return vsnprintf ( buf, ~( ( size_t ) 0 ), fmt, args );
45 }
46
47 #endif /* _STDIO_H */
48