Created
February 28, 2011 21:06
-
-
Save vojto/848037 to your computer and use it in GitHub Desktop.
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
#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(); | |
} | |
} |
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
/// 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