32 aux.
max_length = buf_size > 0 ? buf_size - 1 : 0;
85 retval =
vprintf (format, args);
149 void (*output) (
char,
void *),
void *aux);
151 void (*output) (
char,
void *),
void *aux);
154 void (*output) (
char,
void *),
void *aux);
158 void (*output) (
char,
void *),
void *aux)
160 for (; *format !=
'\0'; format++)
167 output (*format, aux);
259#if UINTMAX_MAX != PTRDIFF_MAX
272 case 'o': b = &
base_o;
break;
273 case 'u': b = &
base_d;
break;
274 case 'x': b = &
base_x;
break;
275 case 'X': b = &
base_X;
break;
286 char ch =
va_arg (args,
int);
294 const char *
s =
va_arg (args,
char *);
309 void *p =
va_arg (args,
void *);
313 &
base_x, &c, output, aux);
325 __printf (
"<<no %%%c in kernel>>", output, aux, *format);
329 __printf (
"<<no %%%c conversion>>", output, aux, *format);
373 if (c->
flags & MINUS)
387 for (;
isdigit (*format); format++)
409 for (;
isdigit (*format); format++)
473 void (*output) (
char,
void *),
void *aux)
489 sign = negative ?
'-' :
'+';
490 else if (c->
flags & SPACE)
491 sign = negative ?
'-' :
' ';
508 if ((c->
flags & GROUP) && digit_cnt > 0 && digit_cnt % b->
group == 0)
521 while (cp -
buf < precision && cp <
buf +
sizeof buf - 1)
523 if ((c->
flags & POUND) && b->
base == 8 && (cp ==
buf || cp[-1] !=
'0'))
527 pad_cnt = c->
width - (cp -
buf) - (
x ? 2 : 0) - (sign != 0);
532 if ((c->
flags & (MINUS | ZERO)) == 0)
545 if (c->
flags & MINUS)
551output_dup (
char ch,
size_t cnt,
void (*output) (
char,
void *),
void *aux)
563 void (*output) (
char,
void *),
void *aux)
566 if (c->
width > length && (c->
flags & MINUS) == 0)
568 for (i = 0; i < length; i++)
569 output (
string[i], aux);
570 if (c->
width > length && (c->
flags & MINUS) != 0)
578 void (*output) (
char,
void *),
void *aux, ...)
596 const size_t per_line = 16;
600 size_t start, end, n;
604 start = ofs % per_line;
606 if (end -
start > size)
612 for (i = 0; i <
start; i++)
616 buf[i -
start], i == per_line / 2 - 1?
'-' :
' ');
619 for (; i < per_line; i++)
622 for (i = 0; i <
start; i++)
627 for (; i < per_line; i++)
648 static const char *factors[] = {
"bytes",
"kB",
"MB",
"GB",
"TB",
NULL};
651 for (fp = factors; size >= 1024 && fp[1] !=
NULL; fp++)
static char buf[BUF_SIZE]
static int isprint(int c)
static int isdigit(int c)
#define NOT_REACHED()
lib/debug.h
int vprintf(const char *format, va_list args)
The standard vprintf() function, which is like printf() but uses a va_list.
static const struct integer_base base_x
int vsnprintf(char *buffer, size_t buf_size, const char *format, va_list args)
Like vprintf(), except that output is stored into BUFFER, which must have space for BUF_SIZE characte...
void __printf(const char *format, void(*output)(char, void *), void *aux,...)
Wrapper for __vprintf() that converts varargs into a va_list.
void print_human_readable_size(uint64_t size)
Prints SIZE, which represents a number of bytes, in a human-readable format, e.g.
void __vprintf(const char *format, va_list args, void(*output)(char, void *), void *aux)
Internal functions.
static const struct integer_base base_o
static const char * parse_conversion(const char *format, struct printf_conversion *, va_list *)
Parses conversion option characters starting at FORMAT and initializes C appropriately.
int snprintf(char *buffer, size_t buf_size, const char *format,...)
Like printf(), except that output is stored into BUFFER, which must have space for BUF_SIZE character...
static void output_dup(char ch, size_t cnt, void(*output)(char, void *), void *aux)
Writes CH to OUTPUT with auxiliary data AUX, CNT times.
int printf(const char *format,...)
Writes formatted output to the console.
static void vsnprintf_helper(char, void *)
Helper function for vsnprintf().
static const struct integer_base base_X
void hex_dump(uintptr_t ofs, const void *buf_, size_t size, bool ascii)
Dumps the SIZE bytes in BUF to the console as hex bytes arranged 16 per line.
static const struct integer_base base_d
static void format_string(const char *string, int length, struct printf_conversion *, void(*output)(char, void *), void *aux)
Formats the LENGTH characters starting at STRING according to the conversion specified in C.
static void format_integer(uintmax_t value, bool is_signed, bool negative, const struct integer_base *, const struct printf_conversion *, void(*output)(char, void *), void *aux)
Performs an integer conversion, writing output to OUTPUT with auxiliary data AUX.
static char x
Verifies that mapping over the data segment is disallowed.
static uint8_t s[256]
RC4-based pseudo-random number generator (PRNG).
#define ROUND_DOWN(X, STEP)
Yields X rounded down to the nearest multiple of STEP.
#define va_arg(LIST, TYPE)
#define va_start(LIST, ARG)
__builtin_va_list va_list
GCC has <stdarg.h> functionality as built-ins, so all we need is to use it.
__PTRDIFF_TYPE__ ptrdiff_t
GCC predefines the types we need for ptrdiff_t and size_t, so that we don't have to guess.
#define SIZE_MAX
lib/stdint.h
unsigned long long int uint64_t
size_t strnlen(const char *string, size_t maxlen)
If STRING is less than MAXLEN characters in length, returns its actual length.
int x
‘x’ character to use, for base 16 only.
int group
Number of digits to group with ' flag.
const char * digits
Collection of digits.
printf() formatting internals.
enum printf_conversion::@1 flags
enum printf_conversion::@2 type
Auxiliary data for vsnprintf_helper().
char * p
Current output position.
int max_length
Max length of output string.
int length
Length of output string.