7bfbcef83e20d203a0e5d2b203fd357117c81410
[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 byte order in 64-bit integer
28 */
29 #if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
30
31 QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal)
32 {
33 QWORD qwResult;
34 BYTE *sptr = (BYTE *)&qwVal;
35 BYTE *dptr = (BYTE *)&qwResult + 7;
36 int i;
37
38 for(i = 0; i < 8; i++, sptr++, dptr--)
39 *dptr = *sptr;
40
41 return qwResult;
42 }
43
44 #endif
45
46 /**
47 * Swap bytes in double
48 */
49 double LIBNETXMS_EXPORTABLE __bswap_double(double dVal)
50 {
51 double dResult;
52 BYTE *sptr = (BYTE *)&dVal;
53 BYTE *dptr = (BYTE *)&dResult + 7;
54 int i;
55
56 for(i = 0; i < 8; i++, sptr++, dptr--)
57 *dptr = *sptr;
58
59 return dResult;
60 }
61
62 /**
63 * Swap bytes in wide string (UCS-2)
64 */
65 void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr)
66 {
67 UCS2CHAR *pch;
68
69 for(pch = pStr; *pch != 0; pch++)
70 *pch = htons(*pch);
71 }
72
73 #if !defined(_WIN32) && !defined(_NETWARE)
74
75 /**
76 * strupr() implementation for non-windows platforms
77 */
78 void LIBNETXMS_EXPORTABLE __strupr(char *in)
79 {
80 char *p = in;
81
82 if (in == NULL)
83 {
84 return;
85 }
86
87 for (; *p != 0; p++)
88 {
89 // TODO: check/set locale
90 *p = toupper(*p);
91 }
92 }
93
94 #if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
95
96 /**
97 * wcsupr() implementation for non-windows platforms
98 */
99 void LIBNETXMS_EXPORTABLE __wcsupr(WCHAR *in)
100 {
101 WCHAR *p = in;
102
103 if (in == NULL)
104 {
105 return;
106 }
107
108 for (; *p != 0; p++)
109 {
110 // TODO: check/set locale
111 #if HAVE_TOWUPPER
112 *p = towupper(*p);
113 #else
114 if (*p < 256)
115 {
116 *p = (WCHAR)toupper(*p);
117 }
118 #endif
119 }
120 }
121
122 #endif
123
124 #endif
125
126 #ifdef _WIN32
127
128 /**
129 * DLL entry point
130 */
131 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
132 {
133 if (dwReason == DLL_PROCESS_ATTACH)
134 {
135 DisableThreadLibraryCalls(hInstance);
136 SEHInit();
137 }
138 return TRUE;
139 }
140
141 #endif /* _WIN32 */