check_error.c
来自「一个单元测试框架,主要和应用文件一起编译运行」· C语言 代码 · 共 48 行
C
48 行
#include "config.h"#include <stdarg.h>#include <stdlib.h>#include <string.h>#include <stdio.h>#include <errno.h>#include "check_error.h"void eprintf (const char *fmt, const char *file, int line, ...){ va_list args; fflush(stderr); fprintf(stderr,"%s:%d: ",file,line); va_start(args, line); vfprintf(stderr, fmt, args); va_end(args); /*include system error information if format ends in colon */ if (fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':') fprintf(stderr, " %s", strerror(errno)); fprintf(stderr, "\n"); exit(2);}void *emalloc (size_t n){ void *p; p = malloc(n); if (p == NULL) eprintf("malloc of %u bytes failed:", __FILE__, __LINE__, n); return p;}void *erealloc (void * ptr, size_t n){ void *p; p = realloc (ptr, n); if (p == NULL) eprintf("realloc of %u bytes failed:", __FILE__, __LINE__, n); return p;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?