Last active
December 15, 2015 11:09
-
-
Save thachhoang/5250835 to your computer and use it in GitHub Desktop.
Flexible error printing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdarg.h> /* va_start, va_end */ | |
#define DEBUG 0 | |
void fail(const char *, ...); | |
void ftrace(FILE *, const char *, ...); | |
void trace(const char *, ...); | |
void fail(const char *fmt, ...) { | |
// Error message | |
va_list args; | |
va_start(args, fmt); | |
vfprintf(stderr, fmt, args); | |
va_end(args); | |
fprintf(stderr, ".\n"); | |
exit(EXIT_FAILURE); | |
} | |
void ftrace(FILE *stream, const char* fmt, ...){ | |
if(!DEBUG) | |
return; | |
va_list args; | |
va_start(args, fmt); | |
vfprintf(stream, fmt, args); | |
va_end(args); | |
} | |
void trace(const char* fmt, ...){ | |
if(!DEBUG) | |
return; | |
va_list args; | |
va_start(args, fmt); | |
vfprintf(stdout, fmt, args); | |
va_end(args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment