Mercurial > trustbridge
diff common/logging.h @ 524:a097dd86cb4d
merged.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 29 Apr 2014 15:26:43 +0200 |
parents | 5e2af38266f6 |
children | 2a4f7364ab81 |
line wrap: on
line diff
--- a/common/logging.h Tue Apr 29 15:26:02 2014 +0200 +++ b/common/logging.h Tue Apr 29 15:26:43 2014 +0200 @@ -17,6 +17,8 @@ * @brief Logging and debugging functions */ +#include <stdio.h> + #ifdef WIN32 #include <windows.h> @@ -79,8 +81,31 @@ * * Prints an error to stderr */ -#define ERRORPRINTF(fmt, ...) fprintf(stderr, DEBUGPREFIX "ERROR: " fmt, ##__VA_ARGS__); +#ifdef WIN32 +# define ERRORPRINTF(fmt, ...) \ + { \ + char buf[512]; \ + snprintf(buf, 511, "ERROR: " fmt, ##__VA_ARGS__); \ + buf[511] = '\0'; \ + OutputDebugStringA(buf); \ + } +#else +# define ERRORPRINTF(fmt, ...) fprintf(stderr, DEBUGPREFIX "ERROR: " fmt, ##__VA_ARGS__); +#endif +/** + * @def PRINTLASTERROR(msg) + * @brief Prints the last windows error with a custom message + * + * Prints an error to stderr + */ +#define PRINTLASTERROR(msg) \ + char *my_error = getLastErrorMsg(); \ + if (my_error) { \ + ERRORPRINTF(msg" : %s\n", my_error); \ + free (my_error); \ + } \ + ERRORPRINTF ("Failed to get error information\n"); #ifdef __cplusplus