Created
June 1, 2021 13:44
-
-
Save HalCanary/c35499751a6c1712b5d05f7bfbf05573 to your computer and use it in GitHub Desktop.
do_or_fail.h
This file contains 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
#ifndef DO_OR_FAIL_H | |
#define DO_OR_FAIL_H | |
extern void fail_now(const char* file, int line, const char* msg, int err); | |
#define DO_OR_FAIL(SUCCESS, MSG) \ | |
do { if (!(SUCCESS)) { fail_now(__FILE__, __LINE__, (MSG), errno); } } while (false) | |
#endif // DO_OR_FAIL_H | |
//////////////////////////////////////////////////////////////////////////////// | |
void fail_now(const char* file, int line, const char* msg, int err) { | |
std::fprintf(stderr, "%s: %d: %s: %s\n", file, line, msg, err ? std::strerror(err) : ""); | |
std::exit(EXIT_FAILURE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment