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