fixed Windows build errors
[public/netxms.git] / src / libnetxms / main.cpp
CommitLineData
5039dede
AK
1/*
2** NetXMS - Network Management System
3** Utility Library
b1e9b6b3 4** Copyright (C) 2003-2012 Victor Kirhenshtein
5039dede
AK
5**
6** This program is free software; you can redistribute it and/or modify
68f384ea
VK
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
5039dede
AK
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**
68f384ea 16** You should have received a copy of the GNU Lesser General Public License
5039dede
AK
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
b1e9b6b3 26/**
96772780
VK
27 * Wrappers for byte swap functions for C code linking
28 */
29#if !(HAVE_DECL_BSWAP_16)
30extern "C" UINT16 LIBNETXMS_EXPORTABLE __bswap_16(UINT16 val)
31{
32 return bswap_16(val);
33}
34#endif
35
36#if !(HAVE_DECL_BSWAP_32)
37extern "C" UINT32 LIBNETXMS_EXPORTABLE __bswap_32(UINT32 val)
38{
39 return bswap_32(val);
40}
41#endif
42
43#if !(HAVE_DECL_BSWAP_64)
44extern "C" UINT64 LIBNETXMS_EXPORTABLE __bswap_64(UINT64 val)
45{
46 return bswap_64(val);
47}
48#endif
49
50/**
c62d158b
VK
51 * Swap bytes in INT16 array or UCS-2 string
52 * Length -1 causes stop at first 0 value
b1e9b6b3 53 */
c62d158b 54void LIBNETXMS_EXPORTABLE bswap_array_16(UINT16 *v, int len)
5039dede 55{
c62d158b
VK
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 }
5039dede
AK
67}
68
76fcb995 69/**
c62d158b
VK
70 * Swap bytes in INT32 array or UCS-4 string
71 * Length -1 causes stop at first 0 value
76fcb995 72 */
c62d158b 73void LIBNETXMS_EXPORTABLE bswap_array_32(UINT32 *v, int len)
5039dede 74{
c62d158b
VK
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 }
5039dede
AK
86}
87
5039dede
AK
88#if !defined(_WIN32) && !defined(_NETWARE)
89
76fcb995
VK
90/**
91 * strupr() implementation for non-windows platforms
92 */
735bac5c 93void LIBNETXMS_EXPORTABLE __strupr(char *in)
5039dede
AK
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
76fcb995
VK
111/**
112 * wcsupr() implementation for non-windows platforms
113 */
735bac5c 114void LIBNETXMS_EXPORTABLE __wcsupr(WCHAR *in)
5039dede
AK
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
5039dede
AK
141#ifdef _WIN32
142
359784de
VK
143/**
144 * DLL entry point
145 */
5039dede
AK
146BOOL 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}
5039dede
AK
155
156#endif /* _WIN32 */