Print function and line when calling Error

This commit is contained in:
Kp 2012-07-07 18:37:55 +00:00
parent 2cd7748e93
commit 9ba729ca3a
2 changed files with 6 additions and 4 deletions

View file

@ -39,7 +39,8 @@ int error_init(void (*func)(const char *)); //init error system, returns 0=ok
void Warning(const char *fmt,...) __attribute_format_printf(1, 2); //print out warning message to user
void set_warn_func(void (*f)(const char *s));//specifies the function to call with warning messages
void clear_warn_func();//say this function no longer valid
void Error(const char *fmt,...) __noreturn __attribute_format_printf(1, 2); //exit with error code=1, print message
void Error(const char *func, unsigned line, const char *fmt,...) __noreturn __attribute_format_printf(3, 4); //exit with error code=1, print message
#define Error(F,...) ((Error)(__func__, __LINE__, (F), ## __VA_ARGS__))
#define Assert assert
#ifndef NDEBUG //macros for debugging

View file

@ -62,13 +62,14 @@ void print_exit_message(const char *exit_message)
}
//terminates with error code 1, printing message
void Error(const char *fmt,...)
void (Error)(const char *func, const unsigned line, const char *fmt,...)
{
char exit_message[MAX_MSG_LEN]="Error: "; // don't put the new line in for dialog output
char exit_message[MAX_MSG_LEN]; // don't put the new line in for dialog output
va_list arglist;
int leader = snprintf(exit_message, sizeof(exit_message), "%s:%u: error: ", func, line);
va_start(arglist,fmt);
vsnprintf(exit_message+7,sizeof(exit_message)-7,fmt,arglist);
vsnprintf(exit_message+leader,sizeof(exit_message)-leader,fmt,arglist);
va_end(arglist);
Int3();