Debian Codegraph @

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

raw
1 /*
2 * PROGRAM: SQL Trace plugin
3 * MODULE: platform.cpp
4 * DESCRIPTION: Platform specifics (posix)
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 "../platform.h"
30 #include "../common/classes/fb_tls.h"
31 #include <sys/types.h>
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
35 #include <stdlib.h>
36
37 #define TEST
38 //#undef TEST
39
40 #ifndef TEST
41 class MallocClear
42 {
43 public:
44 static void clear(char* error_string)
45 {
46 free(error_string);
47 }
48 };
49
50 Firebird::TlsValue<char*, MallocClear> error_value;
51
52 const char* get_error_string()
53 {
54 return error_value.get();
55 }
56
57 void set_error_string(const char* str)
58 {
59 char* org_str = error_value.get();
60 if (org_str)
61 {
62 free(org_str);
63 error_value.set(NULL);
64 }
65 if (str)
66 {
67 const size_t size = strlen(str) + 1;
68 char* new_str = (char*) malloc(size);
69 if (new_str)
70 {
71 memcpy(new_str, str, size);
72 error_value.set(new_str);
73 }
74 }
75 }
76 #else
77 TLS_DECLARE(char*, error_string);
78
79 const char* get_error_string()
80 {
81 return TLS_GET(error_string);
82 }
83
84 void set_error_string(const char* str)
85 {
86 char* org_str = TLS_GET(error_string);
87 if (org_str)
88 {
89 free(org_str);
90 TLS_SET(error_string, NULL);
91 }
92 if (str)
93 {
94 const size_t size = strlen(str) + 1;
95 char* new_str = (char*) malloc(size);
96 if (new_str)
97 {
98 memcpy(new_str, str, size);
99 TLS_SET(error_string, new_str);
100 }
101 }
102 }
103 #endif
104
105 SLONG get_process_id()
106 {
107 return getpid();
108 }