Skip to content

Instantly share code, notes, and snippets.

@vojto
Created February 28, 2011 21:06
Show Gist options
  • Save vojto/848037 to your computer and use it in GitHub Desktop.
Save vojto/848037 to your computer and use it in GitHub Desktop.
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include "util.h"
void x_log(const char *message, ...) {
va_list args;
va_start(args, message);
char formatted_message[255];
sprintf(formatted_message, ">\e\[32m %s\e\[0m\n", message);
vprintf(formatted_message, args);
va_end(args);
}
void x_report_error() {
printf("\e\[31m/--------------------------------\\\n");
printf("Chyba cislo %d:\n", errno);
perror(NULL);
printf("\\--------------------------------/\e\[0m\n");
}
void x_log_or_report_error(const char *message, int result) {
if (result != -1) {
if(message != NULL) x_log(message);
} else {
x_report_error();
}
}
/// Logs message
void x_log(const char *message, ...);
/// Reports error from errno
void x_report_error();
/// Logs message if result != -1 otherwise reports error from errno
void x_log_or_report_error(const char *message, int result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment