fix for Windows build (free is NULL safe on Windows)
[public/netxms.git] / include / nms_common.h
CommitLineData
08f16c05 1/*
7ac71e60 2** NetXMS - Network Management System
120bfcdf 3** Copyright (C) 2003-2014 Victor Kirhenshtein
cbcaf8c8
VK
4**
5** This program is free software; you can redistribute it and/or modify
68f384ea
VK
6** it under the terms of the GNU Lesser General Public License as published by
7** the Free Software Foundation; either version 3 of the License, or
cbcaf8c8
VK
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
68f384ea 15** You should have received a copy of the GNU Lesser General Public License
cbcaf8c8
VK
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
28c329e2 19** File: nms_common.h
cbcaf8c8
VK
20**
21**/
22
23#ifndef _nms_common_h_
24#define _nms_common_h_
25
a1cb335b
VK
26#ifdef WIN32
27#ifndef _WIN32
28#define _WIN32
29#endif
30#endif
31
b40371d4 32#if !defined(_WIN32) && !defined(UNDER_CE)
e647245b 33
f62b7eab 34#include <config.h>
9c3bf7f4 35#if defined(WITH_OPENSSL) || defined(WITH_COMMONCRYPTO)
779c2678
VK
36#define _WITH_ENCRYPTION 1
37#endif
e647245b 38
15cf5acc 39#else /* _WIN32 */
e647245b 40
2c12edfc 41#ifndef UNDER_CE
15cf5acc 42#define _WITH_ENCRYPTION 1
3c15eedb 43#define WITH_OPENSSL 1
6c352bb5 44#define WITH_LDAP 1
f00612ba 45#if !defined(WINDOWS_ONLY) && !defined(_CRT_SECURE_NO_DEPRECATE)
be460d82 46#define _CRT_SECURE_NO_DEPRECATE
2c12edfc 47#endif
f00612ba 48#endif
e647245b 49
879855b3
VK
50// prevent defining min and max macros in Windows headers
51#ifndef NOMINMAX
52#define NOMINMAX
53#endif
54
f5fb7a0f
VK
55// prevent defining ETIMEDOUT, ECONNRESET, etc. to wrong values
56#define _CRT_NO_POSIX_ERROR_CODES
57
82b4c558 58#endif /* _WIN32 */
e647245b 59
f92a016a
VK
60#if HAVE_JEMALLOC_JEMALLOC_H
61#include <jemalloc/jemalloc.h>
62#endif
63
6b42b6f1 64#ifdef HAVE_STDARG_H
e647245b 65#include <stdarg.h>
6b42b6f1
AK
66#endif
67
f2fdf1b5 68#include <unicode.h>
e647245b 69
f2fdf1b5
VK
70#include <stdio.h>
71#include <string.h>
b50f1100 72#include <limits.h>
93b18807 73
b900a78b 74#include <netxms-version.h>
8606bcf9 75
5a82ecc7 76#if HAVE_WIDEC_H
5c0258d5 77#include <widec.h>
82b4c558 78#endif /* HAVE_WIDEC */
9068a8c6 79
bde67a1f
VK
80/**
81 * Define __64BIT__ if compiling for 64bit platform with Visual C++
82 */
c3561262 83#if defined(_M_X64) || defined(_M_IA64) || defined(__LP64__) || defined(__PPC64__) || defined(__x86_64__)
a731ec52
VK
84#ifndef __64BIT__
85#define __64BIT__
86#endif
87#endif
88
0cdf79a3
VK
89/**
90 * Wrappers for 64-bit integer constants
91 */
3a5657b9 92#if defined(__GNUC__) || defined(__HP_aCC) || defined(__IBMC__) || defined(__IBMCPP__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
c61f5190
VK
93#define _LL(x) (x ## LL)
94#define _ULL(x) (x ## ULL)
7946bd7c
VK
95#elif defined(_MSC_VER)
96#define _LL(x) (x ## i64)
97#define _ULL(x) (x ## ui64)
c61f5190
VK
98#else
99#define _LL(x) (x)
100#define _ULL(x) (x)
101#endif
102
480e036b
VK
103/**
104 * Common constants
105 */
fb52d37d 106#define MAX_SECRET_LENGTH 64
a7d07192 107#define MAX_DB_STRING 256
999812c7 108#define MAX_PARAM_NAME 256
2589cc10 109#define MAX_CONFIG_VALUE 2000
cc8ce218 110#define MAX_COLUMN_NAME 64
5ad2167d 111#define MAX_DNS_NAME 256
d41268ba 112#define MAX_HELPDESK_REF_LEN 64
f33d5471 113#define MAX_PASSWORD 256
241541f4
VK
114#define MAX_SSH_LOGIN_LEN 64
115#define MAX_SSH_PASSWORD_LEN 64
967893bb 116#define GROUP_FLAG ((UINT32)0x80000000)
e44ac467 117
d772d0dd 118#define NETXMS_MAX_CIPHERS 6
15cf5acc 119#define NETXMS_RSA_KEYLEN 2048
fb52d37d 120
b50f1100 121#ifndef LLONG_MAX
c61f5190 122#define LLONG_MAX _LL(9223372036854775807)
b50f1100
VK
123#endif
124
125#ifndef LLONG_MIN
126#define LLONG_MIN (-LLONG_MAX - 1)
127#endif
128
129#ifndef ULLONG_MAX
c61f5190 130#define ULLONG_MAX _ULL(18446744073709551615)
b50f1100
VK
131#endif
132
05f256fe 133#ifndef EVENTLOG_DEBUG_TYPE
ccc34207
VK
134#define EVENTLOG_DEBUG_TYPE 0x0080
135#endif
136
e647245b
VK
137#define INVALID_INDEX 0xFFFFFFFF
138#define MD5_DIGEST_SIZE 16
139#define SHA1_DIGEST_SIZE 20
1718cc2a 140#define SHA256_DIGEST_SIZE 32
e647245b 141
9fa031cd 142#define FILE_BUFFER_SIZE 32768
143
664b42a4
VK
144/**
145 * Compatibility defines for C sources
146 */
07a7e06b 147#if !defined(__cplusplus) && !defined(CORTEX) && !HAVE_BOOL
ccc34207 148typedef int bool;
05f256fe
VK
149#endif
150
bde67a1f
VK
151/**
152 * Oracle Pro*C compatibility
153 */
909c0624 154#ifdef ORA_PROC
bde67a1f 155#undef BYTE
50456b1f 156#undef DWORD
bde67a1f
VK
157#endif
158
1de39d9e
VK
159/**
160 * Java class path separator character
161 */
162#ifdef _WIN32
163#define JAVA_CLASSPATH_SEPARATOR _T(';')
164#else
165#define JAVA_CLASSPATH_SEPARATOR _T(':')
166#endif
167
fb52d37d 168
bde67a1f 169/***** Platform dependent includes and defines *****/
fb52d37d 170
018fda4d 171#if defined(_WIN32) || defined(UNDER_CE)
076a55c4
VK
172
173/********** WINDOWS ********************/
e9246d26 174
96772780
VK
175#ifdef _MSC_FULL_VER
176#define __BUILD_VERSION_STRING(s,v) s v
177#define __STR_NX(x) #x
178#define __STR(x) __STR_NX(x)
179#define CPP_COMPILER_VERSION __STR(__BUILD_VERSION_STRING(Microsoft C/C++ Optimizing Compiler Version,_MSC_FULL_VER))
180#endif
181
f5fb7a0f
VK
182// Disable some warnings:
183// 4577 - 'noexcept' used with no exception handling mode specified
184#pragma warning(disable: 4577)
185
e17fe9ab 186#ifndef _WIN32_WINNT
e4590ef2 187#define _WIN32_WINNT 0x0501
e17fe9ab 188#endif
f33479c8 189
36e44abe
VK
190#define WITH_IPV6 1
191
807c0ccc 192#define USE_BUNDLED_LIBTRE 1
df9812a9 193#define USE_BUNDLED_GETOPT 1
807c0ccc 194
3bf0df9f
VK
195#define SAFE_FGETWS_WITH_POPEN 1
196
c35aa503
VK
197#define FREE_IS_NULL_SAFE 1
198
c6491611 199#define FS_PATH_SEPARATOR _T("\\")
b07c50cc
VK
200#define FS_PATH_SEPARATOR_A "\\"
201#define FS_PATH_SEPARATOR_W L"\\"
c6491611
VK
202#define FS_PATH_SEPARATOR_CHAR _T('\\')
203
b79e8fed
VK
204#define WEXITSTATUS(x) (x)
205
a9bad162 206#if _MSC_VER >= 1310
c6491611
VK
207#define HAVE_SCPRINTF 1
208#define HAVE_VSCPRINTF 1
209#define HAVE_SCWPRINTF 1
210#define HAVE_VSCWPRINTF 1
2385d5d0 211#endif
f70fc197 212
a9bad162
VK
213#if _MSC_VER >= 1800
214#define HAVE_STRTOLL 1
215#define HAVE_STRTOULL 1
216#define HAVE_WCSTOLL 1
217#define HAVE_WCSTOULL 1
218#endif
219
342a701d
VK
220#define HAVE_SNPRINTF 1
221#define HAVE_VSNPRINTF 1
222
ecdf8898
VK
223#define HAVE_GETADDRINFO 1
224
d63aad11
VK
225#define HAVE_STDARG_H 1
226
8d4bb054
VK
227#define HAVE_ALLOCA 1
228
7768852d
VK
229#define HAVE_WCSLEN 1
230#define HAVE_WCSNCPY 1
669fcb92 231#define HAVE_WCSDUP 1
7b45b90d 232#define HAVE_WUTIME 1
7768852d 233
74540dab
VK
234#define HAVE_LIBCURL 1
235
c7850580
VK
236#define HAVE_DIRENT_D_TYPE 1
237
9caddb3c 238#include <winsock2.h>
510dd9c4 239#include <windows.h>
36e44abe 240#include <ws2tcpip.h>
d454fb4c 241#include <stdlib.h>
1ddf3f0c 242#include <malloc.h>
1dd2715c 243
a9bad162
VK
244#include <stdarg.h>
245#ifndef va_copy
246#define va_copy(x,y) (x = y)
247#endif
248#define HAVE_DECL_VA_COPY 1
249
018fda4d 250#ifndef UNDER_CE
a8d4cdee 251#include <sys/stat.h>
7b45b90d 252#include <sys/utime.h>
a8d4cdee 253#include <process.h>
1dd2715c 254#include <io.h>
3d1cb7d6 255#include <fcntl.h>
a23d8e0d 256#include <direct.h>
018fda4d 257#endif
91ab8f0a 258
37d62364
AK
259#ifndef S_IRUSR
260# define S_IRUSR 0400
261#endif
262#ifndef S_IWUSR
263# define S_IWUSR 0200
264#endif
1dd2715c 265
34576b56
VK
266#define snprintf _snprintf
267#define vsnprintf _vsnprintf
f83a0c3a
VK
268#define snwprintf _snwprintf
269#define vsnwprintf _vsnwprintf
c6491611
VK
270#define scprintf _scprintf
271#define vscprintf _vscprintf
272#define scwprintf _scwprintf
273#define vscwprintf _vscwprintf
34576b56
VK
274#define popen _popen
275#define pclose _pclose
34576b56
VK
276#define stricmp _stricmp
277#define strnicmp _strnicmp
c90ea787
VK
278#define wcsicmp _wcsicmp
279#define wcsnicmp _wcsnicmp
3da622d4 280#define strlwr(s) _strlwr(s)
34576b56 281#define strupr(s) _strupr(s)
70af47c2 282#define putenv(s) _putenv(s)
34576b56
VK
283#define fileno(f) _fileno(f)
284#define chdir(p) _chdir(p)
285#define mkdir(p,m) _mkdir(p,m)
ccc34207 286#define lseek(f,o,w) _lseek(f,o,w)
34576b56 287#define unlink(x) _unlink(x)
d4c266b6 288
967893bb 289typedef UINT64 QWORD; // for compatibility
670c7f3d 290typedef int socklen_t;
1edb2dab 291typedef long pid_t;
734e79a8
VK
292typedef LONG ssize_t;
293
294typedef signed __int8 int8_t;
295typedef signed __int16 int16_t;
296typedef signed __int32 int32_t;
297typedef signed __int64 int64_t;
298typedef unsigned __int8 uint8_t;
299typedef unsigned __int16 uint16_t;
300typedef unsigned __int32 uint32_t;
08f16c05 301typedef unsigned __int64 uint64_t;
e9246d26 302
8b1fedb2 303#define INT64_FMT _T("%I64d")
dda7c270 304#define INT64_FMTA "%I64d"
511bea22 305#define INT64_FMTW L"%I64d"
8b1fedb2 306#define UINT64_FMT _T("%I64u")
dda7c270 307#define UINT64_FMTA "%I64u"
511bea22 308#define UINT64_FMTW L"%I64u"
8b1fedb2 309#define UINT64X_FMT(m) _T("%") m _T("I64X")
0b514e86 310#if defined(__64BIT__) || (_MSC_VER > 1300)
34576b56 311#define TIME_T_FMT _T("%I64u")
967893bb 312#define TIME_T_FCAST(x) ((UINT64)(x))
1094818a 313#else
34576b56 314#define TIME_T_FMT _T("%u")
967893bb 315#define TIME_T_FCAST(x) ((UINT32)(x))
1094818a 316#endif
cb53cb15 317
64a055a2
VK
318#ifndef __clang__
319
3c15eedb
VK
320#define HAVE_DECL_BSWAP_16 1
321#define HAVE_DECL_BSWAP_32 1
322#define HAVE_DECL_BSWAP_64 1
323
98a314d9
VK
324#define bswap_16(n) _byteswap_ushort(n)
325#define bswap_32(n) _byteswap_ulong(n)
326#define bswap_64(n) _byteswap_uint64(n)
3c15eedb 327
64a055a2
VK
328#endif
329
8f7e2482
VK
330// Socket compatibility
331#define SHUT_RD 0
332#define SHUT_WR 1
333#define SHUT_RDWR 2
334
1ddf3f0c
VK
335#define SetSocketReuseFlag(s) { \
336 BOOL val = TRUE; \
337 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(BOOL)); \
338}
339#define SetSocketExclusiveAddrUse(s) { \
340 BOOL val = TRUE; \
341 setsockopt(s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *)&val, sizeof(BOOL)); \
342}
a3c76aba 343#define SELECT_NFDS(x) ((int)(x))
19121a38
VK
344#define SetSocketNonBlocking(s) { \
345 u_long one = 1; \
346 ioctlsocket(s, FIONBIO, &one); \
347}
734e79a8
VK
348#define SetSocketBlocking(s) { \
349 u_long zero = 0; \
350 ioctlsocket(s, FIONBIO, &zero); \
351}
4a36d30c
VK
352#define SetSocketNoDelay(s) { \
353 BOOL val = TRUE; \
354 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(BOOL)); \
355}
08f16c05 356#define SetSocketBroadcast(s) { \
357 BOOL val = TRUE; \
358 setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&val, sizeof(BOOL)); \
359}
be45f318 360
55b33d4c
VK
361#ifdef UNDER_CE
362#define O_RDONLY 0x0004
363#define O_WRONLY 0x0001
364#define O_RDWR 0x0002
365#define O_CREAT 0x0100
366#define O_EXCL 0x0200
367#define O_TRUNC 0x0800
368#endif
369
3973f74b 370#if !defined(UNDER_CE)
c1099678 371#define HAVE_LIBEXPAT 1
1bb6b449
VK
372#endif
373
058bf6fc
VK
374#define XMPP_SUPPORTED 1
375
c1099678
VK
376#define HAVE_LOCALE_H 1
377#define HAVE_SETLOCALE 1
378
8ff13508
VK
379// Use Win32 API instead of msvcrt for memory allocation
380#ifdef USE_WIN32_HEAP
381
382#define malloc(n) HeapAlloc(GetProcessHeap(), 0, n)
383#define realloc(p, n) (((p) == NULL) ? HeapAlloc(GetProcessHeap(), 0, n) : HeapReAlloc(GetProcessHeap(), 0, p, n))
384#define free(p) HeapFree(GetProcessHeap(), 0, p)
a65409fe 385#define _tcsdup(s) nx__tcsdup(s)
8ff13508
VK
386#define wcsdup(s) nx_wcsdup(s)
387
388#undef _tcsdup
389#ifdef UNICODE
390#define _tcsdup nx_wcsdup
391#else
392#define _tcsdup nx_strdup
393#endif
394
395#else
396
397#define strdup _strdup
398#define wcsdup _wcsdup
399
400#endif
401
82b4c558 402#else /* not _WIN32 */
076a55c4
VK
403
404/*********** UNIX *********************/
cbcaf8c8 405
28c329e2 406#ifndef PREFIX
124528cc
VK
407#ifdef UNICODE
408#define PREFIX L"/usr/local"
409#else
28c329e2 410#define PREFIX "/usr/local"
124528cc 411#endif
28c329e2
VK
412#warning Installation prefix not defined, defaulting to /usr/local
413#endif
414
5456cd6d
VK
415#if HAVE_STDBOOL_H
416#include <stdbool.h>
417#endif
418
ccfe2ba0
VK
419#if HAVE_ALLOCA_H
420#include <alloca.h>
421#endif
422
3e39fcde
VK
423#if HAVE_WCHAR_H
424#include <wchar.h>
425#endif
3e39fcde 426
8b86c5dc
VK
427#if HAVE_WCTYPE_H
428#include <wctype.h>
429#endif
430
e2e3ce85
VK
431// Fix for wcs* functions visibility in Solaris 11
432#if defined(__sun) && (__cplusplus >= 199711L)
433#if HAVE_WCSDUP
434using std::wcsdup;
435#endif
436#if HAVE_WCSCASECMP
437using std::wcscasecmp;
438#endif
439#if HAVE_WCSNCASECMP
440using std::wcsncasecmp;
441#endif
442#endif
443
5bdbe3df
VK
444#include <errno.h>
445
636da5f3 446#define FS_PATH_SEPARATOR _T("/")
b07c50cc
VK
447#define FS_PATH_SEPARATOR_A "/"
448#define FS_PATH_SEPARATOR_W L"/"
636da5f3 449#define FS_PATH_SEPARATOR_CHAR _T('/')
f70fc197 450
e31784c0 451#if HAVE_UNISTD_H
62d8cc27 452#include <unistd.h>
e31784c0
VK
453#endif
454
455#if HAVE_STDLIB_H
62d8cc27 456#include <stdlib.h>
e31784c0
VK
457#endif
458
459#if HAVE_SYS_TYPES_H
7e679c4b 460#include <sys/types.h>
e31784c0
VK
461#endif
462
7b45b90d 463#if HAVE_UTIME_H
464#include <utime.h>
465#endif
466
521d90e7
VK
467#if HAVE_SYS_INT_TYPES_H
468#include <sys/int_types.h>
469#endif
470
cc4c6659
VK
471#if HAVE_SYS_STAT_H
472#include <sys/stat.h>
473#endif
474
e31784c0 475#if HAVE_SYS_SOCKET_H
62d8cc27 476#include <sys/socket.h>
e31784c0
VK
477#endif
478
479#if HAVE_SYS_SELECT_H
62d8cc27 480#include <sys/select.h>
e31784c0
VK
481#endif
482
483#if HAVE_NETINET_IN_H
7e679c4b 484#include <netinet/in.h>
e31784c0
VK
485#endif
486
e9c8eb1d
VK
487#if HAVE_NETINET_TCP_H
488#include <netinet/tcp.h>
489#endif
490
ca6ad6bb
VK
491#if HAVE_NET_NH_H
492#include <net/nh.h>
493#endif
494
e31784c0 495#if HAVE_ARPA_INET_H
62d8cc27 496#include <arpa/inet.h>
e31784c0
VK
497#endif
498
499#if HAVE_NETDB_H
93e601e5 500#include <netdb.h>
e31784c0 501#endif
7e679c4b 502
cc4c6659 503#if HAVE_FCNTL_H
4507063f 504#include <fcntl.h>
cc4c6659
VK
505#endif
506
507#include <dirent.h>
d6a35a77 508
cd4c8ca3
VK
509#if _USE_GNU_PTH
510#include <pth.h>
0c78603d
VK
511#else
512#include <pthread.h>
cd4c8ca3
VK
513#endif
514
efdaffe4
VK
515#ifdef __IBMCPP__
516#include <builtins.h>
517#endif
518
ef8a3c32
VK
519#ifdef __minix
520#undef HAVE_ITOA /* Minix has non-compatible itoa() */
521#undef HAVE_GETHOSTBYNAME2_R
522#endif
523
0f8cd7ae
VK
524#include <sys/socket.h>
525#include <sys/un.h>
526
eefe7d68 527typedef int BOOL;
678de2bc 528#if (SIZEOF_LONG == 4)
efdaffe4
VK
529#if (SIZEOF_INT == 4)
530typedef int INT32;
531typedef unsigned int UINT32;
532#else
967893bb
VK
533typedef long INT32;
534typedef unsigned long UINT32;
efdaffe4 535#endif
3c3d2729 536#undef __64BIT__
678de2bc 537#else
967893bb
VK
538typedef int INT32;
539typedef unsigned int UINT32;
3c3d2729
VK
540#ifndef __64BIT__
541#define __64BIT__
542#endif
678de2bc 543#endif
967893bb
VK
544typedef unsigned short UINT16;
545typedef short INT16;
cbcaf8c8 546typedef unsigned char BYTE;
967893bb 547typedef INT32 LONG; // for compatibility
50456b1f 548typedef UINT32 DWORD; // for compatibility
967893bb 549typedef UINT16 WORD; // for compatibility
cbcaf8c8 550typedef void * HANDLE;
3cf35ea6 551typedef void * HMODULE;
521d90e7 552
8b86c5dc
VK
553#if !HAVE_MODE_T
554typedef int mode_t;
555#endif
556
628013e1
VK
557// We have to use long as INT64 on HP-UX - otherwise
558// there will be compilation errors because of type redefinition in
559// system includes
560#ifdef _HPUX
561
562#ifdef __LP64__
563typedef long INT64;
564typedef unsigned long UINT64;
565#else
566typedef long long INT64;
567typedef unsigned long long UINT64;
568#endif
569
570#else /* _HPUX */
571
6e383343 572#if HAVE_LONG_LONG && (SIZEOF_LONG_LONG == 8)
51128b42
VK
573typedef long long INT64;
574#elif HAVE_INT64_T
7e679c4b 575typedef int64_t INT64;
6e383343
VK
576#elif SIZEOF_LONG == 8
577typedef long INT64;
521d90e7
VK
578#else
579#error Target system does not have signed 64bit integer type
580#endif
581
6e383343 582#if HAVE_UNSIGNED_LONG_LONG && (SIZEOF_LONG_LONG == 8)
967893bb 583typedef unsigned long long UINT64;
51128b42 584#elif HAVE_UINT64_T
967893bb 585typedef uint64_t UINT64;
521d90e7 586#elif HAVE_U_INT64_T
967893bb 587typedef u_int64_t UINT64;
6e383343
VK
588#elif SIZEOF_LONG == 8
589typedef unsigned long UINT64;
521d90e7
VK
590#else
591#error Target system does not have unsigned 64bit integer type
592#endif
628013e1
VK
593
594#endif /* _HPUX */
595
967893bb 596typedef UINT64 QWORD; // for compatibility
7e679c4b 597
8b1fedb2 598#define INT64_FMT _T("%lld")
dda7c270
VK
599#define INT64_FMTW L"%lld"
600#define INT64_FMTA "%lld"
8b1fedb2 601#define UINT64_FMT _T("%llu")
dda7c270
VK
602#define UINT64_FMTW L"%llu"
603#define UINT64_FMTA "%llu"
8b1fedb2 604#define UINT64X_FMT(m) _T("%") m _T("llX")
1094818a 605#ifdef __64BIT__
8b1fedb2 606#define TIME_T_FMT _T("%llu")
967893bb 607#define TIME_T_FCAST(x) ((UINT64)(x))
1094818a 608#else
8b1fedb2 609#define TIME_T_FMT _T("%u")
967893bb 610#define TIME_T_FCAST(x) ((UINT32)(x))
1094818a 611#endif
cbcaf8c8 612
cd4c8ca3 613#ifndef TRUE
cbcaf8c8 614#define TRUE 1
cd4c8ca3
VK
615#endif
616#ifndef FALSE
cbcaf8c8 617#define FALSE 0
cd4c8ca3 618#endif
cbcaf8c8 619
efc49272
VK
620// Some systems may define true and false which may break overloaded functions
621#ifdef __cplusplus
622#undef true
623#undef false
624#endif
625
a5de3def 626#ifndef MAX_PATH
120bfcdf
VK
627#ifdef PATH_MAX
628#define MAX_PATH PATH_MAX
629#else
630#define MAX_PATH 1024
631#endif
a5de3def
VK
632#endif
633
c90ea787
VK
634// Windows compatibility layer for standard C I/O functions
635#ifdef __cplusplus
636
637inline int _access(const char *pathname, int mode) { return ::access(pathname, mode); }
638inline int _open(const char *pathname, int flags) { return ::open(pathname, flags); }
639inline int _open(const char *pathname, int flags, mode_t mode) { return ::open(pathname, flags, mode); }
640inline ssize_t _read(int fd, void *buf, size_t count) { return ::read(fd, buf, count); }
641inline ssize_t _write(int fd, const void *buf, size_t count) { return ::write(fd, buf, count); }
642inline int _close(int fd) { return ::close(fd); }
643
644#else
645
646#define _access(p, m) access((p), (m))
ee088bd0
VK
647#define _open open
648#define _close(f) close(f)
649#define _read(f, b, l) read((f), (b), (l))
c90ea787
VK
650#define _write(f, b, l) write((f), (b), (l))
651#define _close(f) close(f)
652
653#endif
ee088bd0 654
77312b6f 655// Socket compatibility
7e679c4b
AK
656typedef int SOCKET;
657
eae56922 658#define closesocket(x) _close(x)
77312b6f
VK
659#define WSAGetLastError() (errno)
660
f0ce9811 661#define WSAEINTR EINTR
a7a0c5cc 662#define WSAEWOULDBLOCK EWOULDBLOCK
1743a67a 663#define WSAEINPROGRESS EINPROGRESS
a2069340 664#define WSAESHUTDOWN ESHUTDOWN
f0ce9811 665#define INVALID_SOCKET (-1)
62d8cc27 666
be45f318
VK
667#define SetSocketReuseFlag(sd) { \
668 int nVal = 1; \
669 setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (const void *)&nVal, \
670 (socklen_t)sizeof(nVal)); \
671}
672
1ddf3f0c
VK
673#define SetSocketExclusiveAddrUse(s)
674
19121a38
VK
675#define SetSocketNonBlocking(s) { \
676 int f = fcntl(s, F_GETFL); \
677 if (f != -1) fcntl(s, F_SETFL, f | O_NONBLOCK); \
678}
679
4a36d30c
VK
680#define SetSocketNoDelay(s) { \
681 int val = 1; \
682 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const void *)&val, sizeof(int)); \
683}
684
08f16c05 685#define SetSocketBroadcast(s) { \
686 int val = 1; \
687 setsockopt(s, SOL_SOCKET, SO_BROADCAST, (const void *)&val, sizeof(int)); \
688}
689
a3c76aba
VK
690#define SELECT_NFDS(x) (x)
691
cd4c8ca3 692#if !(HAVE_SOCKLEN_T) && !defined(_USE_GNU_PTH)
8ecf30ab 693typedef unsigned int socklen_t;
3c2bbe5f
VK
694#endif
695
0f8cd7ae
VK
696#ifndef SUN_LEN
697#define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
698#endif
699
17d715ba 700// Shared library suffix
2b479c92 701#ifndef SHLIB_SUFFIX
17d715ba 702#if defined(_HPUX) && !defined(__64BIT__)
2b479c92 703#define SHLIB_SUFFIX _T(".sl")
17d715ba 704#else
2b479c92 705#define SHLIB_SUFFIX _T(".so")
17d715ba
VK
706#endif
707#endif
708
4383fcad
AK
709typedef struct hostent HOSTENT;
710
ce7565e7
VK
711#if HAVE_DECL___VA_COPY && !HAVE_DECL_VA_COPY
712#define HAVE_DECL_VA_COPY 1
713#define va_copy(d,s) __va_copy(d,s)
714#endif
715
8d9f0998
VK
716#endif /* _WIN32 */
717
90d8fac8
VK
718/**
719 * Value used to indicate invalid pointer where NULL is not appropriate
720 */
a731ec52
VK
721#ifdef __64BIT__
722#define INVALID_POINTER_VALUE ((void *)_ULL(0xFFFFFFFFFFFFFFFF))
723#else
724#define INVALID_POINTER_VALUE ((void *)0xFFFFFFFF)
725#endif
726
90d8fac8
VK
727/**
728 * Casting between pointer and 32-bit integer
729 */
c88a8bc1 730#ifdef __64BIT__
967893bb
VK
731#define CAST_FROM_POINTER(p, t) ((t)((UINT64)(p)))
732#define CAST_TO_POINTER(v, t) ((t)((UINT64)(v)))
c88a8bc1 733#else
a23d8e0d
VK
734#define CAST_FROM_POINTER(p, t) ((t)(p))
735#define CAST_TO_POINTER(v, t) ((t)(v))
c88a8bc1
VK
736#endif
737
bde67a1f 738/**
bde67a1f
VK
739 * open() flags compatibility
740 */
8d9f0998
VK
741#ifndef O_BINARY
742#define O_BINARY 0
cbcaf8c8
VK
743#endif
744
bde67a1f
VK
745/**
746 * Windows-specific structures for non-Windows platforms
08f16c05 747 */
1d410d50
VK
748#ifndef _WIN32
749
750typedef struct tagPOINT
751{
752 int x;
753 int y;
754} POINT;
755
756#endif
757
bde67a1f
VK
758/**
759 * Event log severity codes
760 */
9c02b362 761#ifndef _WIN32
ccc34207
VK
762#define EVENTLOG_SUCCESS 0x0000
763#define EVENTLOG_ERROR_TYPE 0x0001
764#define EVENTLOG_WARNING_TYPE 0x0002
765#define EVENTLOG_INFORMATION_TYPE 0x0004
766#define EVENTLOG_AUDIT_SUCCESS 0x0008
767#define EVENTLOG_AUDIT_FAILURE 0x0010
9c02b362
VK
768#endif /* _WIN32 */
769
203e9d8a
VK
770#define NXLOG_DEBUG EVENTLOG_DEBUG_TYPE
771#define NXLOG_INFO EVENTLOG_INFORMATION_TYPE
772#define NXLOG_WARNING EVENTLOG_WARNING_TYPE
773#define NXLOG_ERROR EVENTLOG_ERROR_TYPE
774
bde67a1f
VK
775/**
776 * Interface types
777 */
020559de
VK
778#define IFTYPE_OTHER 1
779#define IFTYPE_REGULAR1822 2
780#define IFTYPE_HDH1822 3
781#define IFTYPE_DDN_X25 4
782#define IFTYPE_RFC877_X25 5
783#define IFTYPE_ETHERNET_CSMACD 6
784#define IFTYPE_ISO88023_CSMACD 7
785#define IFTYPE_ISO88024_TOKENBUS 8
786#define IFTYPE_ISO88025_TOKENRING 9
787#define IFTYPE_ISO88026_MAN 10
788#define IFTYPE_STARLAN 11
789#define IFTYPE_PROTEON_10MBIT 12
790#define IFTYPE_PROTEON_80MBIT 13
791#define IFTYPE_HYPERCHANNEL 14
792#define IFTYPE_FDDI 15
793#define IFTYPE_LAPB 16
794#define IFTYPE_SDLC 17
795#define IFTYPE_DS1 18
796#define IFTYPE_E1 19
797#define IFTYPE_BASIC_ISDN 20
798#define IFTYPE_PRIMARY_ISDN 21
799#define IFTYPE_PROP_PTP_SERIAL 22
800#define IFTYPE_PPP 23
801#define IFTYPE_SOFTWARE_LOOPBACK 24
802#define IFTYPE_EON 25
803#define IFTYPE_ETHERNET_3MBIT 26
804#define IFTYPE_NSIP 27
805#define IFTYPE_SLIP 28
806#define IFTYPE_ULTRA 29
807#define IFTYPE_DS3 30
808#define IFTYPE_SMDS 31
809#define IFTYPE_FRAME_RELAY 32
810#define IFTYPE_RS232 33
811#define IFTYPE_PARA 34
812#define IFTYPE_ARCNET 35
813#define IFTYPE_ARCNET_PLUS 36
814#define IFTYPE_ATM 37
815#define IFTYPE_MIOX25 38
816#define IFTYPE_SONET 39
817#define IFTYPE_X25PLE 40
818#define IFTYPE_ISO88022LLC 41
819#define IFTYPE_LOCALTALK 42
820#define IFTYPE_SMDS_DXI 43
821#define IFTYPE_FRAME_RELAY_SERVICE 44
822#define IFTYPE_V35 45
823#define IFTYPE_HSSI 46
824#define IFTYPE_HIPPI 47
825#define IFTYPE_MODEM 48
826#define IFTYPE_AAL5 49
827#define IFTYPE_SONET_PATH 50
828#define IFTYPE_SONET_VT 51
829#define IFTYPE_SMDS_ICIP 52
830#define IFTYPE_PROP_VIRTUAL 53
831#define IFTYPE_PROP_MULTIPLEXOR 54
832#define IFTYPE_IEEE80212 55
833#define IFTYPE_FIBRECHANNEL 56
834#define IFTYPE_HIPPIINTERFACE 57
835#define IFTYPE_FRAME_RELAY_INTERCONNECT 58
836#define IFTYPE_AFLANE8023 59
837#define IFTYPE_AFLANE8025 60
838#define IFTYPE_CCTEMUL 61
839#define IFTYPE_FAST_ETHERNET 62
840#define IFTYPE_ISDN 63
841#define IFTYPE_V11 64
842#define IFTYPE_V36 65
843#define IFTYPE_G703_AT64K 66
844#define IFTYPE_G703_AT2MB 67
845#define IFTYPE_QLLC 68
846#define IFTYPE_FASTETHERFX 69
847#define IFTYPE_CHANNEL 70
848#define IFTYPE_IEEE80211 71
849#define IFTYPE_IBM370_PARCHAN 72
850#define IFTYPE_ESCON 73
851#define IFTYPE_DLSW 74
852#define IFTYPE_ISDNS 75
853#define IFTYPE_ISDNU 76
854#define IFTYPE_LAPD 77
855#define IFTYPE_IPSWITCH 78
856#define IFTYPE_RSRB 79
857#define IFTYPE_ATMLOGICAL 80
858#define IFTYPE_DS0 81
859#define IFTYPE_DS0_BUNDLE 82
860#define IFTYPE_BSC 83
861#define IFTYPE_ASYNC 84
862#define IFTYPE_CNR 85
863#define IFTYPE_ISO88025DTR 86
864#define IFTYPE_EPLRS 87
865#define IFTYPE_ARAP 88
866#define IFTYPE_PROPCNLS 89
867#define IFTYPE_HOSTPAD 90
868#define IFTYPE_TERMPAD 91
869#define IFTYPE_FRAME_RELAY_MPI 92
870#define IFTYPE_X213 93
871#define IFTYPE_ADSL 94
872#define IFTYPE_RADSL 95
873#define IFTYPE_SDSL 96
874#define IFTYPE_VDSL 97
875#define IFTYPE_ISO88025CRFPINT 98
876#define IFTYPE_MYRINET 99
877#define IFTYPE_VOICEEM 100
878#define IFTYPE_VOICEFXO 101
879#define IFTYPE_VOICEFXS 102
880#define IFTYPE_VOICEENCAP 103
881#define IFTYPE_VOICEOVERIP 104
882#define IFTYPE_ATMDXI 105
883#define IFTYPE_ATMFUNI 106
884#define IFTYPE_ATMIMA 107
885#define IFTYPE_PPPMULTILINKBUNDLE 108
886#define IFTYPE_IPOVERCDLC 109
887#define IFTYPE_IPOVERCLAW 110
888#define IFTYPE_STACKTOSTACK 111
889#define IFTYPE_VIRTUAL_IP_ADDRESS 112
890#define IFTYPE_MPC 113
891#define IFTYPE_IPOVERATM 114
892#define IFTYPE_ISO88025FIBER 115
893#define IFTYPE_TDLC 116
894#define IFTYPE_GIGABIT_ETHERNET 117
895#define IFTYPE_HDLC 118
896#define IFTYPE_LAPF 119
897#define IFTYPE_V37 120
898#define IFTYPE_X25MLP 121
899#define IFTYPE_X25_HUNT_GROUP 122
900#define IFTYPE_TRANSPHDLC 123
901#define IFTYPE_INTERLEAVE 124
902#define IFTYPE_FAST 125
903#define IFTYPE_IP 126
904#define IFTYPE_DOCSCABLE_MACLAYER 127
905#define IFTYPE_DOCSCABLE_DOWNSTREAM 128
906#define IFTYPE_DOCSCABLE_UPSTREAM 129
907#define IFTYPE_A12MPPSWITCH 130
908#define IFTYPE_TUNNEL 131
909#define IFTYPE_COFFEE 132
910#define IFTYPE_CES 133
911#define IFTYPE_ATM_SUBINTERFACE 134
912#define IFTYPE_L2VLAN 135
913#define IFTYPE_L3IPVLAN 136
914#define IFTYPE_L3IPXVLAN 137
915#define IFTYPE_DIGITAL_POWERLINE 138
916#define IFTYPE_MEDIAMAIL_OVER_IP 139
917#define IFTYPE_DTM 140
918#define IFTYPE_DCN 141
919#define IFTYPE_IPFORWARD 142
920#define IFTYPE_MSDSL 143
921#define IFTYPE_IEEE1394 144
922#define IFTYPE_GSN 145
923#define IFTYPE_DVBRCC_MACLAYER 146
924#define IFTYPE_DVBRCC_DOWNSTREAM 147
925#define IFTYPE_DVBRCC_UPSTREAM 148
926#define IFTYPE_ATM_VIRTUAL 149
927#define IFTYPE_MPLS_TUNNEL 150
928#define IFTYPE_SRP 151
929#define IFTYPE_VOICE_OVER_ATM 152
930#define IFTYPE_VOICE_OVER_FRAME_RELAY 153
931#define IFTYPE_IDSL 154
932#define IFTYPE_COMPOSITE_LINK 155
933#define IFTYPE_SS7_SIGLINK 156
934#define IFTYPE_PROPWIRELESSP2P 157
935#define IFTYPE_FRFORWARD 158
936#define IFTYPE_RFC1483 159
937#define IFTYPE_USB 160
938#define IFTYPE_IEEE8023ADLAG 161
939#define IFTYPE_BGP_POLICY_ACCOUNTING 162
940#define IFTYPE_FRF16MFR_BUNDLE 163
941#define IFTYPE_H323_GATEKEEPER 164
942#define IFTYPE_H323_PROXY 165
943#define IFTYPE_MPLS 166
944#define IFTYPE_MFSIGLINK 167
945#define IFTYPE_HDSL2 168
946#define IFTYPE_SHDSL 169
947#define IFTYPE_DS1FDL 170
948#define IFTYPE_POS 171
949#define IFTYPE_DVBASI_IN 172
950#define IFTYPE_DVBASI_OUT 173
951#define IFTYPE_PLC 174
952#define IFTYPE_NFAS 175
953#define IFTYPE_TR008 176
954#define IFTYPE_GR303RDT 177
955#define IFTYPE_GR303IDT 178
956#define IFTYPE_ISUP 179
957#define IFTYPE_PROPDOCSWIRELESSMACLAYER 180
958#define IFTYPE_PROPDOCSWIRELESSDOWNSTREAM 181
959#define IFTYPE_PROPDOCSWIRELESSUPSTREAM 182
960#define IFTYPE_HIPERLAN2 183
961#define IFTYPE_PROPBWAP2MP 184
962#define IFTYPE_SONET_OVERHEAD_CHANNEL 185
963#define IFTYPE_DW_OVERHEAD_CHANNEL 186
964#define IFTYPE_AAL2 187
965#define IFTYPE_RADIOMAC 188
966#define IFTYPE_ATMRADIO 189
967#define IFTYPE_IMT 190
968#define IFTYPE_MVL 191
969#define IFTYPE_REACHDSL 192
970#define IFTYPE_FRDLCIENDPT 193
971#define IFTYPE_ATMVCIENDPT 194
972#define IFTYPE_OPTICAL_CHANNEL 195
973#define IFTYPE_OPTICAL_TRANSPORT 196
974#define IFTYPE_PROPATM 197
975#define IFTYPE_VOICE_OVER_CABLE 198
976#define IFTYPE_INFINIBAND 199
977#define IFTYPE_TELINK 200
978#define IFTYPE_Q2931 201
979#define IFTYPE_VIRTUALTG 202
980#define IFTYPE_SIPTG 203
981#define IFTYPE_SIPSIG 204
982#define IFTYPE_DOCSCABLEUPSTREAMCHANNEL 205
983#define IFTYPE_ECONET 206
984#define IFTYPE_PON155 207
985#define IFTYPE_PON622 208
986#define IFTYPE_BRIDGE 209
987#define IFTYPE_LINEGROUP 210
988#define IFTYPE_VOICEEMFGD 211
989#define IFTYPE_VOICEFGDEANA 212
990#define IFTYPE_VOICEDID 213
991#define IFTYPE_MPEG_TRANSPORT 214
992#define IFTYPE_SIXTOFOUR 215
993#define IFTYPE_GTP 216
994#define IFTYPE_PDNETHERLOOP1 217
995#define IFTYPE_PDNETHERLOOP2 218
996#define IFTYPE_OPTICAL_CHANNEL_GROUP 219
997#define IFTYPE_HOMEPNA 220
998#define IFTYPE_GFP 221
999#define IFTYPE_CISCO_ISL_VLAN 222
1000#define IFTYPE_ACTELIS_METALOOP 223
1001#define IFTYPE_FCIPLINK 224
1002#define IFTYPE_RPR 225
1003#define IFTYPE_QAM 226
1004#define IFTYPE_LMP 227
1005#define IFTYPE_CBLVECTASTAR 228
1006#define IFTYPE_DOCSCABLEMCMTSDOWNSTREAM 229
1007#define IFTYPE_ADSL2 230
1008#define IFTYPE_MACSECCONTROLLEDIF 231
1009#define IFTYPE_MACSECUNCONTROLLEDIF 232
1010#define IFTYPE_AVICIOPTICALETHER 233
1011#define IFTYPE_ATM_BOND 234
1012#define IFTYPE_VOICEFGDOS 235
1013#define IFTYPE_MOCA_VERSION1 236
1014#define IFTYPE_IEEE80216WMAN 237
1015#define IFTYPE_ADSL2PLUS 238
1016#define IFTYPE_DVBRCSMACLAYER 239
1017#define IFTYPE_DVBTDM 240
1018#define IFTYPE_DVBRCSTDMA 241
1019#define IFTYPE_X86LAPS 242
1020#define IFTYPE_WWANPP 243
1021#define IFTYPE_WWANPP2 244
1022#define IFTYPE_VOICEEBS 245
1023#define IFTYPE_IFPWTYPE 246
1024#define IFTYPE_ILAN 247
1025#define IFTYPE_PIP 248
1026#define IFTYPE_ALUELP 249
1027#define IFTYPE_GPON 250
1028#define IFTYPE_VDSL2 251
1029#define IFTYPE_CAPWAP_DOT11_PROFILE 252
1030#define IFTYPE_CAPWAP_DOT11_BSS 253
1031#define IFTYPE_CAPWAP_WTP_VIRTUAL_RADIO 254
1032#define IFTYPE_BITS 255
1033#define IFTYPE_DOCSCABLEUPSTREAMRFPORT 256
1034#define IFTYPE_CABLEDOWNSTREAMRFPORT 257
1035#define IFTYPE_VMWARE_VIRTUAL_NIC 258
1036#define IFTYPE_IEEE802154 259
1037#define IFTYPE_OTNODU 260
1038#define IFTYPE_OTNOTU 261
1039#define IFTYPE_IFVFITYPE 262
1040#define IFTYPE_G9981 263
1041#define IFTYPE_G9982 264
1042#define IFTYPE_G9983 265
1043#define IFTYPE_ALUEPON 266
1044#define IFTYPE_ALUEPONONU 267
1045#define IFTYPE_ALUEPONPHYSICALUNI 268
1046#define IFTYPE_ALUEPONLOGICALLINK 269
1047#define IFTYPE_ALUGPONONU 270
1048#define IFTYPE_ALUGPONPHYSICALUNI 271
1049#define IFTYPE_VMWARE_NIC_TEAM 272
840a1a6a 1050
674164eb
VK
1051/**
1052 * IP Header -- RFC 791
1053 */
798f373a
VK
1054typedef struct tagIPHDR
1055{
1056 BYTE m_cVIHL; // Version and IHL
1057 BYTE m_cTOS; // Type Of Service
1058 WORD m_wLen; // Total Length
1059 WORD m_wId; // Identification
1060 WORD m_wFlagOff; // Flags and Fragment Offset
1061 BYTE m_cTTL; // Time To Live
1062 BYTE m_cProtocol; // Protocol
1063 WORD m_wChecksum; // Checksum
1064 struct in_addr m_iaSrc; // Internet Address - Source
1065 struct in_addr m_iaDst; // Internet Address - Destination
1066} IPHDR;
1067
674164eb
VK
1068/**
1069 * ICMP Header - RFC 792
1070 */
798f373a
VK
1071typedef struct tagICMPHDR
1072{
1073 BYTE m_cType; // Type
1074 BYTE m_cCode; // Code
1075 WORD m_wChecksum; // Checksum
1076 WORD m_wId; // Identification
1077 WORD m_wSeq; // Sequence
798f373a
VK
1078} ICMPHDR;
1079
674164eb
VK
1080/**
1081 * INADDR_NONE can be undefined on some systems
1082 */
696fc54f
VK
1083#ifndef INADDR_NONE
1084#define INADDR_NONE (0xFFFFFFFF)
1085#endif
1086
674164eb 1087/**
674164eb
VK
1088 * Check if given string is NULL and always return valid pointer
1089 */
7da71731
VK
1090#define CHECK_NULL(x) ((x) == NULL ? _T("(null)") : (x))
1091#define CHECK_NULL_A(x) ((x) == NULL ? "(null)" : (x))
1092#define CHECK_NULL_EX(x) ((x) == NULL ? _T("") : (x))
1093#define CHECK_NULL_EX_A(x) ((x) == NULL ? "" : (x))
ef44d5ea 1094
674164eb
VK
1095/**
1096 * Free memory block if it isn't NULL
1097 */
2f64a076
VK
1098#if FREE_IS_NULL_SAFE
1099#define safe_free(x) free(x);
1100#define safe_free_and_null(x) { free(x); x = NULL; }
1101#else
b6a77d6d 1102#define safe_free(x) { if ((x) != NULL) free(x); }
de2c1214 1103#define safe_free_and_null(x) { if ((x) != NULL) { free(x); x = NULL; } }
2f64a076
VK
1104#endif
1105
1106/**
1107 * free() wrapper if it isn't NULL safe
1108 */
1109#if defined(__cplusplus) && !FREE_IS_NULL_SAFE
1110inline void nx_free(void *p)
1111{
1112 if (p != NULL)
1113 free(p);
1114}
1115#define free nx_free
1116#endif
b6a77d6d 1117
674164eb
VK
1118/**
1119 * delete object and nullify pointer
1120 */
cd890184
VK
1121#define delete_and_null(x) { delete x; x = NULL; }
1122
674164eb
VK
1123/**
1124 * Convert half-byte's value to hex digit and vice versa
1125 */
4075c782
VK
1126#define bin2hex(x) ((x) < 10 ? ((x) + _T('0')) : ((x) + (_T('A') - 10)))
1127#ifdef UNICODE
1128#define hex2bin(x) ((((x) >= _T('0')) && ((x) <= _T('9'))) ? ((x) - _T('0')) : \
1129 (((towupper(x) >= _T('A')) && (towupper(x) <= _T('F'))) ? (towupper(x) - _T('A') + 10) : 0))
1130#else
93b18807
VK
1131#define hex2bin(x) ((((x) >= '0') && ((x) <= '9')) ? ((x) - '0') : \
1132 (((toupper(x) >= 'A') && (toupper(x) <= 'F')) ? (toupper(x) - 'A' + 10) : 0))
4075c782 1133#endif
fe49ce0b 1134
674164eb 1135/**
78032263 1136 * Define MIN() and MAX()
674164eb 1137 */
78032263 1138#undef MIN
b9792835 1139#define MIN(a, b) ((a) < (b) ? (a) : (b))
78032263 1140#undef MAX
b9792835 1141#define MAX(a, b) ((a) > (b) ? (a) : (b))
7e679c4b 1142
674164eb
VK
1143/**
1144 * Define _tcsicmp() for non-windows
1145 */
daf35c51 1146#ifndef _WIN32
90ce1516
VK
1147#define stricmp strcasecmp
1148#define strnicmp strncasecmp
8b86c5dc
VK
1149#define wcsicmp wcscasecmp
1150#define wcsnicmp wcsncasecmp
daf35c51
VK
1151#endif
1152
674164eb
VK
1153/**
1154 * Compare two numbers and return -1, 0, or 1
1155 */
4c7a83e5
VK
1156#define COMPARE_NUMBERS(n1,n2) (((n1) < (n2)) ? -1 : (((n1) > (n2)) ? 1 : 0))
1157
674164eb
VK
1158/**
1159 * Increment pointer for given number of bytes
1160 */
9f20696e
VK
1161#define inc_ptr(ptr, step, ptype) ptr = (ptype *)(((char *)ptr) + step)
1162
674164eb
VK
1163/**
1164 * Validate numerical value
1165 */
52996299
VK
1166#define VALIDATE_VALUE(var,x,y,z) { if ((var < x) || (var > y)) var = z; }
1167
674164eb
VK
1168/**
1169 * DCI (data collection item) data types
1170 */
a72a1fb1
VK
1171#define DCI_DT_INT 0
1172#define DCI_DT_UINT 1
1173#define DCI_DT_INT64 2
1174#define DCI_DT_UINT64 3
1175#define DCI_DT_STRING 4
1176#define DCI_DT_FLOAT 5
20aaa307 1177#define DCI_DT_NULL 6
8f9299d1 1178#define DCI_DT_DEPRECATED 255 /* used internally by agent */
a72a1fb1 1179
674164eb
VK
1180/**
1181 * Insert parameter as string
1182 */
9493e563
VK
1183#ifdef UNICODE
1184#define STRING(x) L#x
1185#else
1186#define STRING(x) #x
1187#endif
1188
674164eb 1189/**
6be0a20b
VK
1190 * Pipe handle
1191 */
1192#ifdef _WIN32
1193#define HPIPE HANDLE
1194#define INVALID_PIPE_HANDLE INVALID_HANDLE_VALUE
1195#else
1196#define HPIPE int
1197#define INVALID_PIPE_HANDLE (-1)
1198#endif
1199
34b9a3e7
VK
1200#ifdef __cplusplus
1201
b9792835
VK
1202#include <algorithm>
1203
34b9a3e7
VK
1204/**
1205 * Session enumeration callback return codes
1206 */
1207enum EnumerationCallbackResult
1208{
1209 _STOP = 0,
1210 _CONTINUE = 1
1211};
1212
ab7a30e6
VK
1213/**
1214 * Disable copy constructor if compiler supports it
1215 */
1216#if CAN_DELETE_COPY_CTOR
1217#define DISABLE_COPY_CTOR(c) c (const c &s) = delete;
1218#else
1219#define DISABLE_COPY_CTOR(c)
1220#endif
1221
34b9a3e7
VK
1222#endif
1223
cbcaf8c8 1224#endif /* _nms_common_h_ */