Skip to content

Instantly share code, notes, and snippets.

@cloudrain21
Created January 15, 2016 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudrain21/c5f9053d935d1e0d915d to your computer and use it in GitHub Desktop.
Save cloudrain21/c5f9053d935d1e0d915d to your computer and use it in GitHub Desktop.
c/c++ macro
#define VOMIT_ON_FAILURE(a) do { if (0 != (a)) { VOMIT_ABORT(errno, #a); } } while (0)
#define VOMIT_ON_FAILURE_NO_ERRNO(a) do { int err = (a); if (0 != err) { VOMIT_ABORT(err, #a); } } while (0)
#define VOMIT_ABORT(err, str) do { int code = (err); fprintf(stderr, "%s failed on line %d in file %s: %d (%s)\n", str, __LINE__, __FILE__, code, strerror(code)); abort(); } while(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment