CS318 - Pintos
Pintos source browser for JHU CS318 course
Data Structures | Functions | Variables
stdio.c File Reference
#include <stdio.h>
#include <ctype.h>
#include <inttypes.h>
#include <round.h>
#include <stdint.h>
#include <string.h>
Include dependency graph for stdio.c:

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}
 

Function Documentation

◆ __printf()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ __vprintf()

void __vprintf ( const char *  format,
va_list  args,
void(*)(char, void *)  output,
void *  aux 
)

◆ format_integer()

static void format_integer ( uintmax_t  value,
bool  is_signed,
bool  negative,
const struct integer_base b,
const struct printf_conversion c,
void(*)(char, void *)  output,
void *  aux 
)
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, x, and integer_base::x.

Referenced by __vprintf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format_string()

static void format_string ( const char *  string,
int  length,
struct printf_conversion c,
void(*)(char, void *)  output,
void *  aux 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hex_dump()

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.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_dup()

static void output_dup ( char  ch,
size_t  cnt,
void(*)(char, void *)  output,
void *  aux 
)
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().

Here is the caller graph for this function:

◆ parse_conversion()

static const char * parse_conversion ( const char *  format,
struct printf_conversion c,
va_list args 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_human_readable_size()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printf()

int printf ( const char *  format,
  ... 
)

◆ snprintf()

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_alarm_priority(), test_main(), test_mlfqs_fair(), test_mlfqs_load_60(), test_mlfqs_load_avg(), test_priority_condvar(), test_priority_donate_chain(), test_priority_fifo(), test_priority_sema(), test_sleep(), ustar_make_header(), and vmsg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vsnprintf()

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.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vsnprintf_helper()

static void vsnprintf_helper ( char  ch,
void *  aux_ 
)
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().

Here is the caller graph for this function:

Variable Documentation

◆ base_d

const struct integer_base base_d = {10, "0123456789", 0, 3}
static

Definition at line 138 of file stdio.c.

Referenced by __vprintf().

◆ base_o

const struct integer_base base_o = {8, "01234567", 0, 3}
static

Definition at line 139 of file stdio.c.

Referenced by __vprintf().

◆ base_x

const struct integer_base base_x = {16, "0123456789abcdef", 'x', 4}
static

Definition at line 140 of file stdio.c.

Referenced by __vprintf().

◆ base_X

const struct integer_base base_X = {16, "0123456789ABCDEF", 'X', 4}
static

Definition at line 141 of file stdio.c.

Referenced by __vprintf().