# HG changeset patch # User Andre Heinecke # Date 1396349380 0 # Node ID bd7fb50078b4d60c7eca8f2a26723d1a0c0a1c87 # Parent c596568fa45bd004ebab269d6d20cea047f4bb56 Add logging.h for some logging / debug functions The stuff from debug.h is now in logging.h diff -r c596568fa45b -r bd7fb50078b4 cinst/mozilla.c --- a/cinst/mozilla.c Tue Apr 01 10:48:35 2014 +0000 +++ b/cinst/mozilla.c Tue Apr 01 10:49:40 2014 +0000 @@ -55,7 +55,7 @@ #include #define DEBUGPREFIX "MOZ-" -#include "debug.h" +#include "logging.h" #include "errorcodes.h" #include "portpath.h" diff -r c596568fa45b -r bd7fb50078b4 common/CMakeLists.txt --- a/common/CMakeLists.txt Tue Apr 01 10:48:35 2014 +0000 +++ b/common/CMakeLists.txt Tue Apr 01 10:49:40 2014 +0000 @@ -2,6 +2,7 @@ listutil.c strhelp.c portpath.c + logging.c ) add_library(m13_common STATIC ${m13_common_src}) diff -r c596568fa45b -r bd7fb50078b4 common/debug.h --- a/common/debug.h Tue Apr 01 10:48:35 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -#ifndef DEBUG_H -#define DEBUG_H - -/** - * @file - * @brief Helper macros for debugging - */ - -/** - * @def DEBUGOUTPUT - * @brief If defined code for extra debugging output will be generated. - * - * Will be defined if current build is not an RELEASE_BUILD. - */ -#ifndef RELEASE_BUILD -#define DEBUGOUTPUT -#endif - -/** - * @def DEBUGPREFIX - * @brief A string prepended to debug output. - * - * Should be defined to indicate which module created the output. - */ -#ifndef DEBUGPREFIX -#define DEBUGPREFIX "" -#endif - -/** - * @def DEBUGPRINTF(fmt, ...) - * @brief Debug printf - * - * Prints to stderr if DEBUGOUTPUT is defined. - */ -#ifdef DEBUGOUTPUT -#define DEBUGPRINTF(fmt, ...) fprintf(stderr, DEBUGPREFIX "DEBUG: " fmt, ##__VA_ARGS__); -#else -#define DEBUGPRINTF(fmt, ...) -#endif - -#endif diff -r c596568fa45b -r bd7fb50078b4 common/logging.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/logging.c Tue Apr 01 10:49:40 2014 +0000 @@ -0,0 +1,40 @@ +#include "logging.h" +#include "strhelp.h" + +#include + +#ifdef WIN32 +char * +getLastErrorMsg() +{ + LPWSTR bufPtr = NULL; + DWORD err = GetLastError(); + char *retval = NULL; + FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, err, 0, (LPWSTR) &bufPtr, 0, NULL); + if (!bufPtr) + { + HMODULE hWinhttp = GetModuleHandleW (L"crypt32"); + if (hWinhttp) + { + FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_HMODULE | + FORMAT_MESSAGE_IGNORE_INSERTS, + hWinhttp, HRESULT_CODE (err), 0, + (LPWSTR) &bufPtr, 0, NULL); + } + } + if (!bufPtr) { + fprintf (stderr, "Error getting last error for code: %lx \n", err); + return NULL; + } + + retval = wchar_to_utf8(bufPtr, wcslen(bufPtr)); + LocalFree (bufPtr); + + return retval; +} + +#endif diff -r c596568fa45b -r bd7fb50078b4 common/logging.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/logging.h Tue Apr 01 10:49:40 2014 +0000 @@ -0,0 +1,63 @@ +#ifndef COMMON_LOGGING_H +#define COMMON_LOGGING_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * @file + * @brief Logging and debugging functions + */ + +#ifdef WIN32 + +#include + +/** @brief Gets the localized error message for the last error + * returned by GetLastError + * + * @returns utf8 error message that needs to be freed by the caller. + **/ + +char *getLastErrorMsg(); + +#endif + +/** + * @def DEBUGOUTPUT + * @brief If defined code for extra debugging output will be generated. + * + * Will be defined if current build is not an RELEASE_BUILD. + */ +#ifndef RELEASE_BUILD +#define DEBUGOUTPUT +#endif + +/** + * @def DEBUGPREFIX + * @brief A string prepended to debug output. + * + * Should be defined to indicate which module created the output. + */ +#ifndef DEBUGPREFIX +#define DEBUGPREFIX "" +#endif + +/** + * @def DEBUGPRINTF(fmt, ...) + * @brief Debug printf + * + * Prints to stderr if DEBUGOUTPUT is defined. + */ +#ifdef DEBUGOUTPUT +#define DEBUGPRINTF(fmt, ...) fprintf(stderr, DEBUGPREFIX "DEBUG: " fmt, ##__VA_ARGS__); +#else +#define DEBUGPRINTF(fmt, ...) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* COMMON_LOGGING_H */