byte swap functions refactored; added helper functions for swapping bytes in arrays
[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 * Swap bytes in INT16 array or UCS-2 string
28 * Length -1 causes stop at first 0 value
29 */
30 void LIBNETXMS_EXPORTABLE bswap_array_16(UINT16 *v, int len)
31 {
32 if (len < 0)
33 {
34 for(UINT16 *p = v; *p != 0; p++)
35 *p = bswap_16(*p);
36 }
37 else
38 {
39 int count = 0;
40 for(UINT16 *p = v; count < len; p++, count++)
41 *p = bswap_16(*p);
42 }
43 }
44
45 /**
46 * Swap bytes in INT32 array or UCS-4 string
47 * Length -1 causes stop at first 0 value
48 */
49 void LIBNETXMS_EXPORTABLE bswap_array_32(UINT32 *v, int len)
50 {
51 if (len < 0)
52 {
53 for(UINT32 *p = v; *p != 0; p++)
54 *p = bswap_32(*p);
55 }
56 else
57 {
58 int count = 0;
59 for(UINT32 *p = v; count < len; p++, count++)
60 *p = bswap_32(*p);
61 }
62 }
63
64 #if !defined(_WIN32) && !defined(_NETWARE)
65
66 /**
67 * strupr() implementation for non-windows platforms
68 */
69 void LIBNETXMS_EXPORTABLE __strupr(char *in)
70 {
71 char *p = in;
72
73 if (in == NULL)
74 {
75 return;
76 }
77
78 for (; *p != 0; p++)
79 {
80 // TODO: check/set locale
81 *p = toupper(*p);
82 }
83 }
84
85 #if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
86
87 /**
88 * wcsupr() implementation for non-windows platforms
89 */
90 void LIBNETXMS_EXPORTABLE __wcsupr(WCHAR *in)
91 {
92 WCHAR *p = in;
93
94 if (in == NULL)
95 {
96 return;
97 }
98
99 for (; *p != 0; p++)
100 {
101 // TODO: check/set locale
102 #if HAVE_TOWUPPER
103 *p = towupper(*p);
104 #else
105 if (*p < 256)
106 {
107 *p = (WCHAR)toupper(*p);
108 }
109 #endif
110 }
111 }
112
113 #endif
114
115 #endif
116
117 #ifdef _WIN32
118
119 /**
120 * DLL entry point
121 */
122 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
123 {
124 if (dwReason == DLL_PROCESS_ATTACH)
125 {
126 DisableThreadLibraryCalls(hInstance);
127 SEHInit();
128 }
129 return TRUE;
130 }
131
132 #endif /* _WIN32 */