NSWI200: Operating Systems
Vojtěch Horký (horky@d3s.mff.cuni.cz)
Viktor Fuglík
(viktor.fuglik@matfyz.cuni.cz)
Jan Papesch (JanPapuch@seznam.cz)
printf
list_t
linked list typeprintf
to kernel codeprintk
into one kernel kmalloc
and kfree
… complete all milestones before mid January (baseline tests must work).
my_printf
list_t
and link_t
my_printf(const char* format, ...)
Print the format string, replacing %
directives with
actual arguments.
Supported directives:
char
) via %c
int
) in decimal via
%d
unsigned int
) in hexadecimal via
%x
and %X
char *
) via
%s
void *
) in hexadecimal via
%p
No need to implement width, precision, length modifiers and other flags.
Extension:
%pL
for printing lists (list_t
)%pT
to print struct timespec *
%pB
to print byte bufferstatic void print_strings(const char* header, ...) {
puts(header);
va_list args;
va_start(args, header);
const char *argument = va_arg(args, const char *);
while (argument != NULL) {
printf(" - '%s'\n", argument);
argument = va_arg(args, const char *);
}
va_end(args);
}
...
print_arguments("Start of alphabet", "a", "b", "c", NULL);
print_arguments("No arguments", NULL);
print_arguments("Bad usage", "a", "b", NULL, "never printed", NULL);
Nothing more complex will be needed or required (this is OS course, not ADS).
Our lists will have maximum of tens (or very low hundreds) of items.
Do not implement them yourself. Seriously.
Switch to more complex data structure only when:
And even then: think twice (and reuse the code from Linux or HelenOS, please).