Mercurial > trustbridge
annotate common/logging.c @ 586:ecfd77751daf
Disambiguate enumerator values and add portable wrapper.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 27 May 2014 16:30:58 +0000 |
parents | 17e1c8f37d72 |
children | 2a4f7364ab81 |
rev | line source |
---|---|
404 | 1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=2) | |
5 * and comes with ABSOLUTELY NO WARRANTY! | |
6 * See LICENSE.txt for details. | |
7 */ | |
252
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 #include "logging.h" |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
9 #include "strhelp.h" |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
10 |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
11 #include <stdio.h> |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
12 |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
13 #ifdef WIN32 |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 char * |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
15 getLastErrorMsg() |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
16 { |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
17 LPWSTR bufPtr = NULL; |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
18 DWORD err = GetLastError(); |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
19 char *retval = NULL; |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
20 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
21 FORMAT_MESSAGE_FROM_SYSTEM | |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
22 FORMAT_MESSAGE_IGNORE_INSERTS, |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
23 NULL, err, 0, (LPWSTR) &bufPtr, 0, NULL); |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
24 if (!bufPtr) |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
25 { |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
26 HMODULE hWinhttp = GetModuleHandleW (L"crypt32"); |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
27 if (hWinhttp) |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
28 { |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
29 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
30 FORMAT_MESSAGE_FROM_HMODULE | |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
31 FORMAT_MESSAGE_IGNORE_INSERTS, |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
32 hWinhttp, HRESULT_CODE (err), 0, |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
33 (LPWSTR) &bufPtr, 0, NULL); |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
34 } |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
35 } |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
36 if (!bufPtr) { |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
37 fprintf (stderr, "Error getting last error for code: %lx \n", err); |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
38 return NULL; |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
39 } |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 retval = wchar_to_utf8(bufPtr, wcslen(bufPtr)); |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
42 LocalFree (bufPtr); |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
44 return retval; |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
45 } |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
46 |
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
47 #endif |