linux

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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

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;
}
posted on 2011-04-25 10:32  h13  阅读(448)  评论(0编辑  收藏  举报