I'm trying to learn more about kernels, so naturally I started to program one. I'm using tutorials from here. Right now I have modified the printf() that was supplied there. It used goto and I didn't like that.
Can anyone see anything wrong with this code? It worked fine when I tested it.
printf("hello %c world %c",'x','y')
int printf(const char* restrict format, ...)
{
va_list parameters;
va_start(parameters, format);
int written = 0;
size_t amount;
while(*format != '\0')
{
if (*format != '%')
{
amount = 1;
while(format[amount] && format[amount] != '%') //print every character until, % is encountered.
amount++;
print(format, amount);
format += amount;
written += amount;
continue;
}
switch(*(++format)) //since format points now to %, move on step
{
case 'c':
format++; //prepare next char
char c = (char)va_arg(parameters, int);
print(&c, sizeof(c));
written++;
break;
}
}
return written;
}
And print(), left completely unmodified:
static void print(const char* data, size_t data_length)
{
for ( size_t i = 0; i < data_length; i++ )
putchar((int) ((const unsigned char*) data)[i]);
}