Skip to content

Instantly share code, notes, and snippets.

@mortehu
Created December 11, 2014 22:26
Show Gist options
  • Save mortehu/df056c55958723b6836e to your computer and use it in GitHub Desktop.
Save mortehu/df056c55958723b6836e to your computer and use it in GitHub Desktop.
Error reporting
static __thread char* last_error;
const char* last_error(void) {
return last_error ? last_error : strerror(errno);
}
void clear_error(void) {
free(last_error);
last_error = NULL;
}
void set_error(const char* format, ...) {
va_list args;
free(last_error);
va_start(args, format);
if (-1 == vasprintf(&last_error, format, args))
last_error = NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment