Created
December 11, 2014 22:26
-
-
Save mortehu/df056c55958723b6836e to your computer and use it in GitHub Desktop.
Error reporting
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
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