Skip to content

Instantly share code, notes, and snippets.

@ducalpha
Created April 15, 2016 07:51
Show Gist options
  • Select an option

  • Save ducalpha/fb83d373b3ed23f4e0a62d8405ec4a64 to your computer and use it in GitHub Desktop.

Select an option

Save ducalpha/fb83d373b3ed23f4e0a62d8405ec4a64 to your computer and use it in GitHub Desktop.
Logging errors
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