Created
April 15, 2016 07:51
-
-
Save ducalpha/fb83d373b3ed23f4e0a62d8405ec4a64 to your computer and use it in GitHub Desktop.
Logging errors
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
| void LogError(const char *fmt, ...) { | |
| va_list vlist; | |
| va_start(vlist, fmt); | |
| const size_t kLogMessageLength = 128; | |
| char log_message[kLogMessageLength]; | |
| vsnprintf(log_message, kLogMessageLength, fmt, vlist); | |
| LogError(log_message); | |
| va_end(vlist); | |
| } | |
| /* Log the error getting from errno */ | |
| void LogErrno(const char *msg) { | |
| char buf[kBufferSize]; | |
| strerror_r(errno, buf, kBufferSize); | |
| LogError(stderr, "%s: %s\n", msg, buf); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment