mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added ERROR() and WARNING() for debugging.
This commit is contained in:
parent
543b129ba7
commit
3dfaa464ac
|
@ -26,9 +26,40 @@
|
||||||
|
|
||||||
unsigned char * hex_string_to_bin(char hex_string[]);
|
unsigned char * hex_string_to_bin(char hex_string[]);
|
||||||
|
|
||||||
|
/* WARNING(msg) takes a printf()-styled string and prints it
|
||||||
|
* with some additional details.
|
||||||
|
* ERROR(exit_status, msg) does the same thing as WARNING(), but
|
||||||
|
* also exits the program with the given exit status.
|
||||||
|
* Examples:
|
||||||
|
* WARNING("<insert warning message here>");
|
||||||
|
* int exit_status = 2;
|
||||||
|
* ERROR(exit_status, "exiting with status %i", exit_status);
|
||||||
|
*/
|
||||||
|
#ifdef DEBUG
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define DEBUG_PRINT(str, ...) do { \
|
||||||
|
char msg[1000]; \
|
||||||
|
sprintf(msg, "%s(): line %d (file %s): %s%%c\n", __FUNCTION__, __LINE__, __FILE__, str); \
|
||||||
|
fprintf(stderr, msg, __VA_ARGS__); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define WARNING(...) do { \
|
||||||
|
fprintf(stderr, "warning in "); \
|
||||||
|
DEBUG_PRINT(__VA_ARGS__, ' '); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ERROR(exit_status, ...) do { \
|
||||||
|
fprintf(stderr, "error in "); \
|
||||||
|
DEBUG_PRINT(__VA_ARGS__, ' '); \
|
||||||
|
exit(exit_status); \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
#define WARNING(...)
|
||||||
|
#define ERROR(...)
|
||||||
|
#endif // DEBUG
|
||||||
|
|
||||||
/************************Linked List***********************
|
/************************Linked List***********************
|
||||||
* This is a simple linked list implementation, very similar
|
* This is a simple linked list implementation, very similar
|
||||||
|
|
Loading…
Reference in New Issue
Block a user