内核小碎碎-第三集 pr_info

使用示例:

pr_info(" %s[%#x]\t[%pa-%pa], %pa bytes%s flags: %#x\n",
			type->name, idx, &base, &end, &size, nid_buf, flags);

追踪:

#define pr_info(fmt, ...)	__pr(__pr_info, fmt, ##__VA_ARGS__)

#define __pr(func, fmt, ...)	\
do {				\
	if ((func))		\
		(func)("libapi: " fmt, ##__VA_ARGS__); \
} while (0)

libapi_print_fn_t __pr_info    = __base_pr;

static int __base_pr(const char *format, ...)
{
	va_list args;
	int err;

	va_start(args, format);
	err = vfprintf(stderr, format, args);
	va_end(args);
	return err;
}

//头文件
#include 
#include 

所以,示例展开为:

__base_pr(" %s[%#x]\t[%pa-%pa], %pa bytes%s flags: %#x\n", type->name, idx, &base, &end, &size, nid_buf, flags);

迁移到应用程序中使用:

#include 
#include 
int vfprintf(FILE *stream, const char *format, va_list ap);

vfprintf() write output to the given output stream;
参数可参考man手册。

你可能感兴趣的:(内核小碎碎-第三集 pr_info)