fixed potentiali unsafe usage of TCHAR in ODBC driver
[public/netxms.git] / src / libnetxms / main.cpp
CommitLineData
5039dede
AK
1/* $Id$ */
2/*
3** NetXMS - Network Management System
4** Utility Library
5** Copyright (C) 2003, 2004, 2005, 2006, 2007 Victor Kirhenshtein
6**
7** This program is free software; you can redistribute it and/or modify
8** it under the terms of the GNU General Public License as published by
9** the Free Software Foundation; either version 2 of the License, or
10** (at your option) any later version.
11**
12** This program is distributed in the hope that it will be useful,
13** but WITHOUT ANY WARRANTY; without even the implied warranty of
14** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15** GNU General Public License for more details.
16**
17** You should have received a copy of the GNU General Public License
18** along with this program; if not, write to the Free Software
19** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20**
21** File: main.cpp
22**
23**/
24
25#include "libnetxms.h"
26
27
28//
29// Swap byte order in 64-bit integer
30//
31
32#if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
33
34QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal)
35{
36 QWORD qwResult;
37 BYTE *sptr = (BYTE *)&qwVal;
38 BYTE *dptr = (BYTE *)&qwResult + 7;
39 int i;
40
41 for(i = 0; i < 8; i++, sptr++, dptr--)
42 *dptr = *sptr;
43
44 return qwResult;
45}
46
47#endif
48
49
50//
51// Swap bytes in double
52//
53
54double LIBNETXMS_EXPORTABLE __bswap_double(double dVal)
55{
56 double dResult;
57 BYTE *sptr = (BYTE *)&dVal;
58 BYTE *dptr = (BYTE *)&dResult + 7;
59 int i;
60
61 for(i = 0; i < 8; i++, sptr++, dptr--)
62 *dptr = *sptr;
63
64 return dResult;
65}
66
67
68//
69// Swap bytes in wide string (UCS-2)
70//
71
72void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr)
73{
74 UCS2CHAR *pch;
75
76 for(pch = pStr; *pch != 0; pch++)
77 *pch = htons(*pch);
78}
79
80
81//
82// strupr() implementation for non-windows platforms
83//
84
85#if !defined(_WIN32) && !defined(_NETWARE)
86
87void LIBNETXMS_EXPORTABLE strupr(char *in)
88{
89 char *p = in;
90
91 if (in == NULL)
92 {
93 return;
94 }
95
96 for (; *p != 0; p++)
97 {
98 // TODO: check/set locale
99 *p = toupper(*p);
100 }
101}
102
103#if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
104
105void LIBNETXMS_EXPORTABLE wcsupr(WCHAR *in)
106{
107 WCHAR *p = in;
108
109 if (in == NULL)
110 {
111 return;
112 }
113
114 for (; *p != 0; p++)
115 {
116 // TODO: check/set locale
117#if HAVE_TOWUPPER
118 *p = towupper(*p);
119#else
120 if (*p < 256)
121 {
122 *p = (WCHAR)toupper(*p);
123 }
124#endif
125 }
126}
127
128#endif
129
130#endif
131
132
133//
134// DLL entry point
135//
136
137#ifdef _WIN32
138
139#ifndef UNDER_CE // FIXME
140BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
141{
142 if (dwReason == DLL_PROCESS_ATTACH)
143 {
144 DisableThreadLibraryCalls(hInstance);
145 SEHInit();
146 }
147 return TRUE;
148}
149#endif // UNDER_CE
150
151#endif /* _WIN32 */
152
153
154//
155// NetWare library entry point
156//
157
158#ifdef _NETWARE
159
160int _init(void)
161{
162 return 0;
163}
164
165int _fini(void)
166{
167 return 0;
168}
169
170#endif