#include <stdint.h>
#include <stdarg.h>
#include <stdio.h>
Go to the source code of this file.
Data Structures | |
| struct | printf_context |
| A printf context. More... | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| size_t | vcprintf (struct printf_context *ctx, const char *fmt, va_list args) |
| Write a formatted string to a printf context. | |
| int | vssnprintf (char *buf, ssize_t ssize, const char *fmt, va_list args) |
| Version of vsnprintf() that accepts a signed buffer size. | |
| int | __attribute__ ((format(printf, 3, 4))) ssnprintf(char *buf |
Variables | |
| int ssize_t | ssize |
| int ssize_t const char * | fmt |
Etherboot's printf() functions understand the following subset of the standard C printf()'s format specifiers:
Hexadecimal numbers are always zero-padded to the specified field width (if any); decimal numbers are always space-padded. Decimal long longs are not supported.
Definition in file vsprintf.h.
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| size_t vcprintf | ( | struct printf_context * | ctx, | |
| const char * | fmt, | |||
| va_list | args | |||
| ) |
Write a formatted string to a printf context.
| ctx | Context | |
| fmt | Format string | |
| args | Arguments corresponding to the format string |
| len | Length of formatted string |
Definition at line 165 of file vsprintf.c.
References ALT_FORM, cputchar(), format_decimal(), format_hex(), INT_LEN, LCASE, printf_context::len, SIZE_T_LEN, type_sizes, and va_arg.
Referenced by vprintf(), vsnprintf(), and vw_printw().
00165 { 00166 int flags; 00167 int width; 00168 uint8_t *length; 00169 char *ptr; 00170 char tmp_buf[32]; /* 32 is enough for all numerical formats. 00171 * Insane width fields could overflow this buffer. */ 00172 00173 /* Initialise context */ 00174 ctx->len = 0; 00175 00176 for ( ; *fmt ; fmt++ ) { 00177 /* Pass through ordinary characters */ 00178 if ( *fmt != '%' ) { 00179 cputchar ( ctx, *fmt ); 00180 continue; 00181 } 00182 fmt++; 00183 /* Process flag characters */ 00184 flags = 0; 00185 for ( ; ; fmt++ ) { 00186 if ( *fmt == '#' ) { 00187 flags |= ALT_FORM; 00188 } else if ( *fmt == '0' ) { 00189 /* We always 0-pad hex and space-pad decimal */ 00190 } else { 00191 /* End of flag characters */ 00192 break; 00193 } 00194 } 00195 /* Process field width */ 00196 width = 0; 00197 for ( ; ; fmt++ ) { 00198 if ( ( ( unsigned ) ( *fmt - '0' ) ) < 10 ) { 00199 width = ( width * 10 ) + ( *fmt - '0' ); 00200 } else { 00201 break; 00202 } 00203 } 00204 /* We don't do floating point */ 00205 /* Process length modifier */ 00206 length = &type_sizes[INT_LEN]; 00207 for ( ; ; fmt++ ) { 00208 if ( *fmt == 'h' ) { 00209 length--; 00210 } else if ( *fmt == 'l' ) { 00211 length++; 00212 } else if ( *fmt == 'z' ) { 00213 length = &type_sizes[SIZE_T_LEN]; 00214 } else { 00215 break; 00216 } 00217 } 00218 /* Process conversion specifier */ 00219 ptr = tmp_buf + sizeof ( tmp_buf ) - 1; 00220 *ptr = '\0'; 00221 if ( *fmt == 'c' ) { 00222 cputchar ( ctx, va_arg ( args, unsigned int ) ); 00223 } else if ( *fmt == 's' ) { 00224 ptr = va_arg ( args, char * ); 00225 if ( ! ptr ) 00226 ptr = "<NULL>"; 00227 } else if ( *fmt == 'p' ) { 00228 intptr_t ptrval; 00229 00230 ptrval = ( intptr_t ) va_arg ( args, void * ); 00231 ptr = format_hex ( ptr, ptrval, width, 00232 ( ALT_FORM | LCASE ) ); 00233 } else if ( ( *fmt & ~0x20 ) == 'X' ) { 00234 unsigned long long hex; 00235 00236 flags |= ( *fmt & 0x20 ); /* LCASE */ 00237 if ( *length >= sizeof ( unsigned long long ) ) { 00238 hex = va_arg ( args, unsigned long long ); 00239 } else if ( *length >= sizeof ( unsigned long ) ) { 00240 hex = va_arg ( args, unsigned long ); 00241 } else { 00242 hex = va_arg ( args, unsigned int ); 00243 } 00244 ptr = format_hex ( ptr, hex, width, flags ); 00245 } else if ( ( *fmt == 'd' ) || ( *fmt == 'i' ) ){ 00246 signed long decimal; 00247 00248 if ( *length >= sizeof ( signed long ) ) { 00249 decimal = va_arg ( args, signed long ); 00250 } else { 00251 decimal = va_arg ( args, signed int ); 00252 } 00253 ptr = format_decimal ( ptr, decimal, width ); 00254 } else { 00255 *(--ptr) = *fmt; 00256 } 00257 /* Write out conversion result */ 00258 for ( ; *ptr ; ptr++ ) { 00259 cputchar ( ctx, *ptr ); 00260 } 00261 } 00262 00263 return ctx->len; 00264 }
Version of vsnprintf() that accepts a signed buffer size.
| buf | Buffer into which to write the string | |
| size | Size of buffer | |
| fmt | Format string | |
| args | Arguments corresponding to the format string |
| len | Length of formatted string |
Definition at line 352 of file vsprintf.c.
References vsnprintf().
Referenced by ssnprintf().
00352 { 00353 00354 /* Treat negative buffer size as zero buffer size */ 00355 if ( ssize < 0 ) 00356 ssize = 0; 00357 00358 /* Hand off to vsnprintf */ 00359 return vsnprintf ( buf, ssize, fmt, args ); 00360 }
| int __attribute__ | ( | (format(printf, 3, 4)) | ) |
Definition at line 72 of file vsprintf.h.
Definition at line 72 of file vsprintf.h.
1.5.7.1