// Simple implementation of cprintf console output for the kernel,
//内核输出的简单实现(cprintf函数的简单实现)
// based on printfmt() and the kernel console's cputchar().
//基于printfmt.C和console.C的cputchar()
#include <inc/types.h>
#include <inc/stdio.h>
#include <inc/stdarg.h>
/*
* cputchar() 是console.C中的函数 作用是:输出一个 character 到 console
*/
static void
putch(int ch, int *cnt)
{
cputchar(ch);
*cnt++;
}
int
vcprintf(const char *fmt, va_list ap)
{
int cnt = 0;
vprintfmt((void*)putch, &cnt, fmt, ap);
return cnt;
}
int
cprintf(const char *fmt, ...)
{
//VA_LIST 是在C语言中解决变参问题的一组宏,
//所在头文件:#include <stdarg.h>,用于获取不确定个数的参数。
va_list ap;
int cnt;
va_start(ap, fmt);
cnt = vcprintf(fmt, ap);
va_end(ap);
return cnt;
}