封装错误信息打印的函数

在应用程序中经常需要用到打印错误信息的函数,以便我们能更方便地调试。
考虑到程序的可扩展性,将对该函数作如下的封装:

static int stderrfn(const char *fmt, va_list ap)
{
return vfprintf(stderr, fmt, ap);
}

/*
* Change this hook to point to your custom error handling function.
*/
int (*ts_error_fn)(const char *fmt, va_list ap) = stderrfn;

int ts_error(const char *fmt, ...)
{
va_list ap;
int ret;

va_start(ap, fmt);
ret
= ts_error_fn(fmt, ap);
va_end(ap);

return ret;
}
原文地址:https://www.cnblogs.com/hoys/p/2026807.html