Changelog update
[public/netxms.git] / src / libnetxms / main.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Utility Library
4 ** Copyright (C) 2003-2012 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published
8 ** by the Free Software Foundation; either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 ** File: main.cpp
21 **
22 **/
23
24 #include "libnetxms.h"
25
26 /**
27 * Wrappers for byte swap functions for C code linking
28 */
29 #if !(HAVE_DECL_BSWAP_16)
30 extern "C" UINT16 LIBNETXMS_EXPORTABLE __bswap_16(UINT16 val)
31 {
32 return bswap_16(val);
33 }
34 #endif
35
36 #if !(HAVE_DECL_BSWAP_32)
37 extern "C" UINT32 LIBNETXMS_EXPORTABLE __bswap_32(UINT32 val)
38 {
39 return bswap_32(val);
40 }
41 #endif
42
43 #if !(HAVE_DECL_BSWAP_64)
44 extern "C" UINT64 LIBNETXMS_EXPORTABLE __bswap_64(UINT64 val)
45 {
46 return bswap_64(val);
47 }
48 #endif
49
50 /**
51 * Swap bytes in INT16 array or UCS-2 string
52 * Length -1 causes stop at first 0 value
53 */
54 void LIBNETXMS_EXPORTABLE bswap_array_16(UINT16 *v, int len)
55 {
56 if (len < 0)
57 {
58 for(UINT16 *p = v; *p != 0; p++)
59 *p = bswap_16(*p);
60 }
61 else
62 {
63 int count = 0;
64 for(UINT16 *p = v; count < len; p++, count++)
65 *p = bswap_16(*p);
66 }
67 }
68
69 /**
70 * Swap bytes in INT32 array or UCS-4 string
71 * Length -1 causes stop at first 0 value
72 */
73 void LIBNETXMS_EXPORTABLE bswap_array_32(UINT32 *v, int len)
74 {
75 if (len < 0)
76 {
77 for(UINT32 *p = v; *p != 0; p++)
78 *p = bswap_32(*p);
79 }
80 else
81 {
82 int count = 0;
83 for(UINT32 *p = v; count < len; p++, count++)
84 *p = bswap_32(*p);
85 }
86 }
87
88 #if !defined(_WIN32) && !defined(_NETWARE)
89
90 /**
91 * strupr() implementation for non-windows platforms
92 */
93 void LIBNETXMS_EXPORTABLE __strupr(char *in)
94 {
95 char *p = in;
96
97 if (in == NULL)
98 {
99 return;
100 }
101
102 for (; *p != 0; p++)
103 {
104 // TODO: check/set locale
105 *p = toupper(*p);
106 }
107 }
108
109 #if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
110
111 /**
112 * wcsupr() implementation for non-windows platforms
113 */
114 void LIBNETXMS_EXPORTABLE __wcsupr(WCHAR *in)
115 {
116 WCHAR *p = in;
117
118 if (in == NULL)
119 {
120 return;
121 }
122
123 for (; *p != 0; p++)
124 {
125 // TODO: check/set locale
126 #if HAVE_TOWUPPER
127 *p = towupper(*p);
128 #else
129 if (*p < 256)
130 {
131 *p = (WCHAR)toupper(*p);
132 }
133 #endif
134 }
135 }
136
137 #endif
138
139 #endif
140
141 #ifdef _WIN32
142
143 /**
144 * DLL entry point
145 */
146 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
147 {
148 if (dwReason == DLL_PROCESS_ATTACH)
149 {
150 DisableThreadLibraryCalls(hInstance);
151 SEHInit();
152 }
153 return TRUE;
154 }
155
156 #endif /* _WIN32 */