1 Star 0 Fork 0

ReviewClouds/danche-ttyS2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
debug-msg.h 3.83 KB
一键复制 编辑 原始数据 按行查看 历史
ReviewClouds 提交于 2020-08-26 10:47 . first commit
/**
* @file debug-msg.h
* @brief
* @author rendong (rendong@littt.com)
* @version 1.0
* @date 2020-08-25
*
* @copyright Copyright (c) 2020 成都科鸿凌泰自动识别
*
* @par 修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2020-08-25 <td>1.0 <td>rendong <td>内容
* </table>
*/
#ifndef _DEBUG_MSG_H
#define _DEBUG_MSG_H
#include <stdio.h> /* perror() */
#include <string.h> /* strerror() */
#include <errno.h> /* errno */
/***
* Print the error msg is one thing
* but print the msg is another!!
*/
/**
* @def error_exit
* @brief A macro that prints the @a error msg and exit.
*/
#define error_exit(error) \
do \
{ \
fprintf(stderr, "%s\n", error); \
exit(0); \
} while (0)
/**
* @def error_ret
* @brief A macro that prints the @a error msg and return -1.
*/
#define error_ret(error) \
do \
{ \
fprintf(stderr, "%s\n", error); \
return -1; \
} while (0)
/**
* @def unix_error_exit
* @brief A macro that prints the @a error msg(with errno) and then exit.
* I put 'unix' before the 'function' name because I am using 'errno'.
*/
#define unix_error_exit(error) \
do \
{ \
fprintf(stderr, "%s Info[%d]:%s\n", \
error, errno, strerror(errno)); \
exit(1); \
} while (0)
/**
* @def unix_error_ret
* @brief A macro that prints the @a error msg(with errno) and then return -1.
* I put 'unix' before the 'function' name because I am using 'errno'.
*/
#define unix_error_ret(error) \
do \
{ \
fprintf(stderr, "%s Info[%d]:%s\n", \
error, errno, strerror(errno)); \
return -1; \
} while (0)
/* error handle ,detail version */
/* it can show the file,function and the line */
/**
* @def unix_print_error
* @brief A macro that prints the @a error msg(with errno) and then exit.
* I put 'unix' before the 'function' name because I am using 'errno'.@n
* This error handle(detail version) can show the @p file, @p function
* and @p line where the @a error happens.
* @note I do not often use this 'function' in my program.
*/
#define unix_print_error(error) \
do \
{ \
fprintf(stderr, "Oh God!\nFile:%s Line:%d Function:%s:\n", \
__FILE__, __LINE__, __func__); \
perror(error); \
exit(0); \
} while (0)
/* DEBUG=0 will show nothing */
#ifndef DEBUG
#define DEBUG 1 /**< we debug all the time */
#endif
/**
* @def debug_msg
* @brief A macro that prints the debug msg, as the same with @a printf.
*
*/
#ifdef DEBUG
#define debug_msg(fmt, ...) \
fprintf(stdout, fmt, ##__VA_ARGS__)
#else
#define debug_msg(fmt, ...)
#endif /* DEBUG */
#ifndef TRACE
#define TRACE 1 /**< we trace all the time */
#endif
/**
* @def debug_trace
* @brief A macro that traces the @p file, @p function and @p line.
*
*/
#ifdef TRACE
#define debug_trace(trace) \
fprintf(stdout, "%s File:%s Line:%d Func:%s.\n", \
trace, __FILE__, __LINE__, __func__)
#else
#define debug_trace(trace)
#endif
#endif /* _DEBUG_MSG_H */
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ReviewClouds/danche-tty-s2.git
git@gitee.com:ReviewClouds/danche-tty-s2.git
ReviewClouds
danche-tty-s2
danche-ttyS2
master

搜索帮助