PKUOS - Pintos
Pintos source browser for PKU Operating System course
|
#include <stdio.h>
#include <ctype.h>
#include <inttypes.h>
#include <round.h>
#include <stdint.h>
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | vsnprintf_aux |
Auxiliary data for vsnprintf_helper(). More... | |
struct | printf_conversion |
printf() formatting internals. More... | |
struct | integer_base |
Functions | |
static void | vsnprintf_helper (char ch, void *aux_) |
Helper function for vsnprintf(). More... | |
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 characters. More... | |
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 characters. More... | |
int | printf (const char *format,...) |
Writes formatted output to the console. More... | |
static const char * | parse_conversion (const char *format, struct printf_conversion *c, va_list *args) |
Parses conversion option characters starting at FORMAT and initializes C appropriately. More... | |
static void | format_integer (uintmax_t value, bool is_signed, bool negative, const struct integer_base *b, const struct printf_conversion *c, void(*output)(char, void *), void *aux) |
Performs an integer conversion, writing output to OUTPUT with auxiliary data AUX. More... | |
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. More... | |
static void | format_string (const char *string, int length, struct printf_conversion *c, void(*output)(char, void *), void *aux) |
Formats the LENGTH characters starting at STRING according to the conversion specified in C. More... | |
void | __vprintf (const char *format, va_list args, void(*output)(char, void *), void *aux) |
Internal functions. More... | |
void | __printf (const char *format, void(*output)(char, void *), void *aux,...) |
Wrapper for __vprintf() that converts varargs into a va_list. More... | |
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. More... | |
void | print_human_readable_size (uint64_t size) |
Prints SIZE, which represents a number of bytes, in a human-readable format, e.g. More... | |
Variables | |
static const struct integer_base | base_d = {10, "0123456789", 0, 3} |
static const struct integer_base | base_o = {8, "01234567", 0, 3} |
static const struct integer_base | base_x = {16, "0123456789abcdef", 'x', 4} |
static const struct integer_base | base_X = {16, "0123456789ABCDEF", 'X', 4} |
void __printf | ( | const char * | format, |
void(*)(char, void *) | output, | ||
void * | aux, | ||
... | |||
) |
Wrapper for __vprintf() that converts varargs into a va_list.
Definition at line 577 of file stdio.c.
References __vprintf(), va_end, and va_start.
Referenced by __vprintf().
void __vprintf | ( | const char * | format, |
va_list | args, | ||
void(*)(char, void *) | output, | ||
void * | aux | ||
) |
Internal functions.
Definition at line 157 of file stdio.c.
References __printf(), base_d, base_o, base_x, base_X, printf_conversion::CHAR, printf_conversion::flags, format_integer(), format_string(), printf_conversion::INT, printf_conversion::INTMAX, printf_conversion::LONG, printf_conversion::LONGLONG, NOT_REACHED, NULL, parse_conversion(), printf_conversion::precision, PTRDIFF_MAX, printf_conversion::PTRDIFFT, s, printf_conversion::SHORT, SIZE_MAX, printf_conversion::SIZET, strnlen(), printf_conversion::type, and va_arg.
Referenced by __printf(), vhprintf(), vprintf(), and vsnprintf().
|
static |
Performs an integer conversion, writing output to OUTPUT with auxiliary data AUX.
The integer converted has absolute value VALUE. If IS_SIGNED is true, does a signed conversion with NEGATIVE indicating a negative value; otherwise does an unsigned conversion and ignores NEGATIVE. The output is done according to the provided base B. Details of the conversion are in C.
< Buffer and current position.
< ‘x’ character to use or 0 if none.
< Sign character or 0 if none.
< Rendered precision.
< # of pad characters to fill field width.
< # of digits output so far.
Definition at line 470 of file stdio.c.
References integer_base::base, buf, integer_base::digits, printf_conversion::flags, integer_base::group, output_dup(), printf_conversion::precision, printf_conversion::width, integer_base::x, and x.
Referenced by __vprintf().
|
static |
Formats the LENGTH characters starting at STRING according to the conversion specified in C.
Writes output to OUTPUT with auxiliary data AUX.
Definition at line 561 of file stdio.c.
References printf_conversion::flags, output_dup(), and printf_conversion::width.
Referenced by __vprintf().
Dumps the SIZE bytes in BUF to the console as hex bytes arranged 16 per line.
Nonstandard functions.
Numeric offsets are also included, starting at OFS for the first byte in BUF. If ASCII is true then the corresponding ASCII characters are also rendered alongside.
< Maximum bytes per line.
Definition at line 593 of file stdio.c.
References buf, isprint(), printf(), ROUND_DOWN, and start.
Referenced by bitmap_dump(), compare_bytes(), fsutil_cat(), and main().
|
static |
Writes CH to OUTPUT with auxiliary data AUX, CNT times.
Definition at line 551 of file stdio.c.
Referenced by format_integer(), and format_string().
|
static |
Parses conversion option characters starting at FORMAT and initializes C appropriately.
Returns the character in FORMAT that indicates the conversion (e.g. the ‘d’ in ‘d’). Uses ARGS for ‘*’ field widths and precisions.
Definition at line 340 of file stdio.c.
References printf_conversion::flags, isdigit(), printf_conversion::precision, printf_conversion::type, va_arg, and printf_conversion::width.
Referenced by __vprintf().
void print_human_readable_size | ( | uint64_t | size | ) |
Prints SIZE, which represents a number of bytes, in a human-readable format, e.g.
"256 kB".
Definition at line 642 of file stdio.c.
References NULL, printf(), and PRIu64.
Referenced by block_register(), and identify_ata_device().
int printf | ( | const char * | format, |
... | |||
) |
Writes formatted output to the console.
In the kernel, the console is both the video display and first serial port. In userspace, the console is file descriptor 1.
Definition at line 79 of file stdio.c.
References va_end, va_start, and vprintf().
Referenced by archive_directory(), archive_file(), archive_ordinary_file(), backspace(), block_print_stats(), block_register(), checkf(), console_print_stats(), debug_backtrace(), debug_panic(), do_format(), do_write(), exception_print_stats(), fail(), found_partition(), fsutil_append(), fsutil_cat(), fsutil_extract(), fsutil_ls(), fsutil_rm(), hex_dump(), identify_ata_device(), init_pool(), interrupt_handler(), intr_dump_frame(), kbd_print_stats(), kill(), list_dir(), load(), main(), make_tar_archive(), msg(), page_fault(), partition_scan(), pass(), pintos_init(), print_human_readable_size(), print_stacktrace(), read_command_line(), read_partition_table(), run_task(), sema_self_test(), shutdown_power_off(), shutdown_reboot(), syscall_handler(), test(), thread_print_stats(), timer_calibrate(), timer_print_stats(), unexpected_interrupt(), usage(), ustar_make_header(), wait_until_idle(), and wait_while_busy().
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 characters.
Writes at most BUF_SIZE - 1 characters to BUFFER, followed by a null terminator. BUFFER will always be null-terminated unless BUF_SIZE is zero. Returns the number of characters that would have been written to BUFFER, not including a null terminator, had there been enough room.
Definition at line 62 of file stdio.c.
References buffer, va_end, va_start, and vsnprintf().
Referenced by exec_children(), found_partition(), ide_init(), identify_ata_device(), list_dir(), main(), make_tree(), remove_tree(), sort_chunks(), spawn_child(), test_main(), test_mlfqs_fair(), test_sleep(), ustar_make_header(), and vmsg().
Like vprintf(), except that output is stored into BUFFER, which must have space for BUF_SIZE characters.
Writes at most BUF_SIZE - 1 characters to BUFFER, followed by a null terminator. BUFFER will always be null-terminated unless BUF_SIZE is zero. Returns the number of characters that would have been written to BUFFER, not including a null terminator, had there been enough room.
Definition at line 26 of file stdio.c.
References __vprintf(), buffer, vsnprintf_aux::length, vsnprintf_aux::max_length, vsnprintf_aux::p, and vsnprintf_helper().
Referenced by checkf(), do_mkdir(), do_remove(), do_touch(), snprintf(), and vmsg().
|
static |
Helper function for vsnprintf().
Definition at line 46 of file stdio.c.
References vsnprintf_aux::length, vsnprintf_aux::max_length, and vsnprintf_aux::p.
Referenced by vsnprintf().
|
static |
Definition at line 138 of file stdio.c.
Referenced by __vprintf().
|
static |
Definition at line 139 of file stdio.c.
Referenced by __vprintf().
|
static |
Definition at line 140 of file stdio.c.
Referenced by __vprintf().
|
static |
Definition at line 141 of file stdio.c.
Referenced by __vprintf().