Debian Codegraph @

src/utilities/ntrace/os/win32/platform.cpp

raw
1 /*
2 * PROGRAM: SQL Trace plugin
3 * MODULE: platform.cpp
4 * DESCRIPTION: Platform specifics (Win32)
5 *
6 * The contents of this file are subject to the Initial
7 * Developer's Public License Version 1.0 (the "License");
8 * you may not use this file except in compliance with the
9 * License. You may obtain a copy of the License at
10 * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
11 *
12 * Software distributed under the License is distributed AS IS,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied.
14 * See the License for the specific language governing rights
15 * and limitations under the License.
16 *
17 * The Original Code was created by Nickolay Samofatov
18 * for the Firebird Open Source RDBMS project.
19 *
20 * Copyright (c) 2004 Nickolay Samofatov <[email protected]>
21 * and all contributors signed below.
22 *
23 * All Rights Reserved.
24 * Contributor(s): ______________________________________.
25 *
26 */
27
28 #include "firebird.h"
29 #include <windows.h>
30 #include "../platform.h"
31 #include "../common/classes/fb_tls.h"
32
33 TLS_DECLARE(char*, error_string);
34
35 const char* get_error_string()
36 {
37 return TLS_GET(error_string);
38 }
39
40 void set_error_string(const char* str)
41 {
42 char* org_str = TLS_GET(error_string);
43 if (org_str)
44 {
45 LocalFree(org_str);
46 TLS_SET(error_string, NULL);
47 }
48
49 if (str)
50 {
51 const size_t size = strlen(str) + 1;
52 char* new_str = (char*) LocalAlloc(LMEM_FIXED, size);
53 if (new_str)
54 {
55 memcpy(new_str, str, size);
56 TLS_SET(error_string, new_str);
57 }
58 }
59 }
60
61 SLONG get_process_id()
62 {
63 return GetCurrentProcessId();
64 }
65
66
67 BOOL WINAPI DllMain(HINSTANCE /*hinstDLL*/, DWORD fdwReason, LPVOID /*lpvReserved*/)
68 {
69 if (fdwReason == DLL_THREAD_DETACH)
70 {
71 char* str = TLS_GET(error_string);
72 if (str)
73 {
74 LocalFree(str);
75 TLS_SET(error_string, NULL);
76 }
77 }
78 return TRUE;
79 }