⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.h

📁 fsmlabs的real time linux的内核
💻 H
字号:
#include <assert.h>/*  * Define some nice color stuff */#define  MOVE_TO_COL(col) "\033["#col"G"#define      SETCOLOR_SUCCESS "\033[1;32m"#define      SETCOLOR_FAILURE "\033[1;31m"#define      SETCOLOR_WARNING "\033[1;33m"#define      SETCOLOR_NORMAL "\033[0;39m"#undef __assert_fail# define __assert_fail(exp,file,line,fun)	\({rtl_printf(SETCOLOR_FAILURE ": %s:%d: %s:assert(%s) failed\n"SETCOLOR_NORMAL,file,line,fun,exp);\global_error++;})//#define NSEC_PER_SEC 1000000000#define timerplusnsec(c,d) (c)->tv_nsec +=(d);             \                           if ((c)->tv_nsec >NSEC_PER_SEC){ \                           (c)->tv_nsec -= NSEC_PER_SEC;(c)->tv_sec++;}#define timerdiff(a,b) (((a)->tv_sec - (b)->tv_sec)*NSEC_PER_SEC + \                         (a)->tv_nsec - (b)->tv_nsec)#define timersum(c,a,b) (c)->tv_sec = ((a)->tv_sec + (b)->tv_sec); \                       (c)->tv_nsec = ((a)->tv_nsec + (b)->tv_nsec); \                       if ((c)->tv_nsec > NSEC_PER_SEC){ \                           (c)->tv_nsec -= NSEC_PER_SEC;(c)->tv_sec++;}#define timer_gt(a,b) (((a)->tv_sec > (b)->tv_sec) ? 1 :  \                      (((a)->tv_sec < (b)->tv_sec) ? 0 :  \                      ((a)->tv_nsec > (b)->tv_nsec)))#define timespec_to_timeval(a,b) (b)->tv_sec = (a)->tv_sec; \                                 (b)->tv_nsec = (a)->tv_usec * 1000int global_error;#define by_now() { char * excolor = (global_error) ? SETCOLOR_FAILURE : \                         SETCOLOR_WARNING;                     \                         fprintf(stderr, \                         "%sEnd of test, %d error(s) found.\n"  \                         SETCOLOR_NORMAL,                      \                         excolor,global_error);                       \                         exit(global_error);}#ifdef debug#undef debug#define debug(a) do {a}while (0)#else#define debug(a) do {} while (0)#endif#define MASK(x) (1<<(x))#define myperror(s) MYperror(__BASE_FILE__,__LINE__,s)int MYperror(char * where,int line,char *what){        rtl_printf(SETCOLOR_FAILURE"%s,%d:",where,line);        //perror(what);        rtl_printf(SETCOLOR_NORMAL);	//exit depending if you are in a th or in init_module	return 0;}#define my_c_perror(e,s) MY_c_perror(e,__BASE_FILE__,__LINE__,s)int MY_c_perror(int e,char * where,int line,char *what){        char *fmt;        fmt = e ? "expected" :SETCOLOR_FAILURE"UNEXPECTED";        rtl_printf("%s %s,%d:",fmt,where,line);	//        perror(what);        if ( ! e) {                global_error++;                rtl_printf(SETCOLOR_NORMAL);        }        return e ? 0:-1;}#define no_error(e,s) No_error(e,__BASE_FILE__,__LINE__,s)int No_error(int e,char * where,int line,char *what){        char *fmt;        fmt = e ? SETCOLOR_FAILURE"ERROR expected but not found" : "Cool";        rtl_printf("%s %s,%d:%s\n"SETCOLOR_NORMAL,fmt,where,line,what);        if ( e) {                global_error++;                rtl_printf(SETCOLOR_NORMAL);        }        return e ? -1 : 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -