platform.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #ifndef _PLATFORM_H_
  15. #define _PLATFORM_H_
  16. #define _TESTING // this should remain set for the near future
  17. // **** START OF X-PLATFORM SECTION ****
  18. #if defined(_M_X64) || defined ( __x86_64) || __WORDSIZE==64
  19. #define __64BIT__
  20. #endif
  21. #ifdef _FILE_OFFSET_BITS
  22. //#error PLATFORM.H must be included first
  23. #endif
  24. #define _FILE_OFFSET_BITS 64
  25. #ifndef _LARGEFILE64_SOURCE
  26. #define _LARGEFILE64_SOURCE 1
  27. #endif
  28. #if defined(__linux__)
  29. #ifndef _GNU_SOURCE
  30. #define _GNU_SOURCE
  31. #endif
  32. #include <endian.h>
  33. #endif
  34. #ifndef __LITTLE_ENDIAN
  35. #define __LITTLE_ENDIAN 1
  36. #endif
  37. #ifndef __BIG_ENDIAN
  38. #define __BIG_ENDIAN 2
  39. #endif
  40. #define __BYTE_ORDER __LITTLE_ENDIAN
  41. typedef unsigned size32_t;
  42. #if (defined (__linux__) || defined (__FreeBSD__) || defined (__APPLE__))
  43. typedef __SIZE_TYPE__ memsize_t;
  44. #else
  45. typedef size_t memsize_t;
  46. #endif
  47. typedef memsize_t rowsize_t;
  48. #define count_t __int64
  49. #define kcount_t size32_t
  50. #define CF I64F
  51. #define KCF "d"
  52. #ifdef _WIN32
  53. #define I64C(n) n##i64
  54. #else
  55. #define I64C(n) n##LL
  56. #endif
  57. // **** END OF X-PLATFORM SECTION ****
  58. #if defined(_WIN32)
  59. #if (_MSC_VER>=1300)
  60. #pragma warning(disable:4996)
  61. #endif
  62. // **** START OF WIN32 SPECIFIC SECTION ****
  63. #ifndef ALL_WINDOWS
  64. #define WIN32_LEAN_AND_MEAN
  65. #endif
  66. #ifdef _DEBUG
  67. #ifndef USING_MPATROL //using mpatrol memory leak tool
  68. #define _CRTDBG_MAP_ALLOC
  69. #endif
  70. #endif
  71. #define NOMINMAX
  72. #include <windows.h>
  73. #include <stdlib.h>
  74. #include <io.h>
  75. #include <fcntl.h>
  76. #include <malloc.h>
  77. #include <sys/stat.h>
  78. #include <winioctl.h>
  79. #include <direct.h>
  80. #if (_MSC_VER>=1300)
  81. #include <string>
  82. #include <fstream>
  83. #endif
  84. //#ifdef USING_SCM_WITH_STL //before #define of "debug" new
  85. #ifdef _MSC_VER
  86. #include <new>
  87. #include <memory>
  88. #define __attribute__(param) /* do nothing */
  89. #endif
  90. #ifdef _DEBUG
  91. #ifndef USING_MPATROL //using mpatrol memory leak tool
  92. #ifndef _INC_CRTDBG
  93. #include <crtdbg.h>
  94. #undef new
  95. #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
  96. #endif
  97. #endif
  98. #endif
  99. #define ThreadId DWORD
  100. #define MutexId HANDLE
  101. #define sleep(X) Sleep(X*1000)
  102. #define I64F "I64"
  103. #define PATHSEPCHAR '\\'
  104. #define PATHSEPSTR "\\"
  105. #define TEXT_TRANS "t"
  106. #define LLC(NUM) NUM
  107. #define ENVSEPCHAR ';'
  108. #define SEPARATE_LIB_DLL_FILES
  109. #define SharedObjectPrefix ""
  110. #define SharedObjectExtension ".dll"
  111. #define LibraryExtension ".lib"
  112. #define ProcessExtension ".exe"
  113. #define GetSharedProcedure(h,name) GetProcAddress(h,(char *)name)
  114. #define LoadSucceeded(h) ((unsigned)h >= 32)
  115. #define GetSharedObjectError() GetLastError()
  116. #define strtok_r(a,b,c) j_strtok_r(a,b,c)
  117. typedef unsigned __int64 off64_t;
  118. typedef int socklen_t;
  119. typedef int ssize_t; // correct return to type for unix read/write/pread etc.
  120. #define fpos_ht fpos_t
  121. typedef long double LDouble;
  122. typedef unsigned long MaxCard;
  123. /* Floating point constants */
  124. #define MaxValidExp +308
  125. #define MinValidExp -330
  126. #define MaxRealMant 1.7
  127. #define MinRealMant 2.33
  128. #define MaxRealValue 1.7E+308
  129. #define S_IXUSR 0x40 // Execute by owner
  130. #define S_IWUSR 0x80 // Write by owner
  131. #define S_IRUSR 0x100 // Read by owner
  132. #define S_IXGRP 0x200 // Execute by group
  133. #define S_IWGRP 0x400 // Write by group
  134. #define S_IRGRP 0x800 // Read by group
  135. #define S_IXOTH 0x1000 // Execute by other
  136. #define S_IWOTH 0x2000 // Write by other
  137. #define S_IROTH 0x4000 // Read by other
  138. #define S_IRWXU (S_IXGRP|S_IWGRP|S_IRGRP)
  139. #define S_IRWXG (S_IXGRP|S_IWGRP|S_IRGRP)
  140. #define S_IRWXO (S_IXGRP|S_IWGRP|S_IRGRP)
  141. // MSVC 2008 in debug (perhaps other versions too) will throw exception if negative passed (see bug: #32013)
  142. #if (_MSC_VER>=1400) // >=vs2005
  143. #define strictmsvc_isalpha(c) isalpha(c)
  144. #define isalpha(c) isalpha((const unsigned char)(c))
  145. #define strictmsvc_isupper(c) isupper(c)
  146. #define isupper(c) isupper((const unsigned char)(c))
  147. #define strictmsvc_islower(c) islower(c)
  148. #define islower(c) islower((const unsigned char)(c))
  149. #define strictmsvc_isdigit(c) isdigit(c)
  150. #define isdigit(c) isdigit((const unsigned char)(c))
  151. #define strictmsvc_isxdigit(c) isxdigit(c)
  152. #define isxdigit(c) isxdigit((const unsigned char)(c))
  153. #define strictmsvc_isspace(c) isspace(c)
  154. #define isspace(c) isspace((const unsigned char)(c))
  155. #define strictmsvc_ispunct(c) ispunct(c)
  156. #define ispunct(c) ispunct((const unsigned char)(c))
  157. #define strictmsvc_isalnum(c) isalnum(c)
  158. #define isalnum(c) isalnum((const unsigned char)(c))
  159. #define strictmsvc_isprint(c) isprint(c)
  160. #define isprint(c) isprint((const unsigned char)(c))
  161. #define strictmsvc_isgraph(c) isgraph(c)
  162. #define isgraph(c) isgraph((const unsigned char)(c))
  163. #define strictmsvc_iscntrl(c) iscntrl(c)
  164. #define iscntrl(c) iscntrl((const unsigned char)(c))
  165. #define strictmsvc_tolower(c) tolower(c)
  166. #define tolower(c) tolower((const unsigned char)(c))
  167. #define strictmsvc_toupper(c) toupper(c)
  168. #define toupper(c) toupper((const unsigned char)(c))
  169. #endif // (_MSC_VER>=1400)
  170. // **** END OF WIN32 SPECIFIC SECTION ****
  171. #else
  172. // **** START OF UNIX GENERAL SECTION ****
  173. #define _stdcall
  174. #define __stdcall
  175. #define _fastcall
  176. #define __fastcall
  177. #define _fastcall
  178. #define __cdecl
  179. #if defined(__linux__) || defined (__FreeBSD__) || defined (__APPLE__)
  180. // **** START OF LINUX SPECIFIC SECTION ****
  181. #include <aio.h>
  182. #define __BYTE_ORDER __LITTLE_ENDIAN
  183. #define _atoi64 atoll
  184. #define _lseek lseek
  185. #define _llseek ::lseek
  186. #define _lseeki64 ::lseek
  187. #define _vsnprintf vsnprintf
  188. #define strnicmp strncasecmp
  189. #define INFINITE 0xFFFFFFFF
  190. #ifdef _LARGEFILE64_SOURCE
  191. // needed by <sys/types.h>
  192. #ifndef __USE_LARGEFILE64
  193. #define __USE_LARGEFILE64
  194. #endif
  195. #ifndef __USE_FILE_OFFSET64
  196. #define __USE_FILE_OFFSET64
  197. #endif
  198. #endif
  199. // **** END OF LINUX SPECIFIC SECTION ****
  200. #else
  201. #undef __BYTE_ORDER
  202. #define __BYTE_ORDER __BIG_ENDIAN // e.g. Solaris
  203. #endif
  204. #if defined(__SVR4)
  205. typedef int socklen_t;
  206. #endif
  207. #include <stdlib.h>
  208. #include <sys/types.h>
  209. #include <unistd.h>
  210. #include <fcntl.h>
  211. #include <string.h>
  212. #include <ctype.h>
  213. #include <limits.h>
  214. #include <unistd.h>
  215. #include <stdio.h>
  216. #include <stdarg.h>
  217. #include <errno.h>
  218. #include <sys/socket.h>
  219. #include <netinet/in.h>
  220. #include <arpa/inet.h>
  221. #include <netdb.h>
  222. #include <signal.h>
  223. #define PASCAL
  224. #define __declspec(dllexport)
  225. #define __int32 int
  226. #define __int16 short
  227. #define __int8 char
  228. #define __int64 long long
  229. #ifndef __TIMESTAMP__
  230. #define __TIMESTAMP__ "<__TIMESTAMP__ unsupported>"
  231. #endif
  232. #define ENVSEPCHAR ':'
  233. #define PATHSEPCHAR '/'
  234. #define PATHSEPSTR "/"
  235. #define TEXT_TRANS
  236. #define LLC(NUM) NUM ## LL
  237. #define wsprintf sprintf
  238. #define _lread _read
  239. #define _lclose _close
  240. #define _lwrite _write
  241. #define _lopen _open
  242. #define DeleteFile(name) (unlink(name)==0)
  243. #define wvsprintf vsprintf
  244. #define _close ::close
  245. #define _stat stat
  246. #define _fstat ::fstat
  247. #define _dup ::dup
  248. #define _chdir ::chdir
  249. #define _setmode(a,b)
  250. #define TRUE 1
  251. #define FALSE 0
  252. //#define false FALSE
  253. //#define true TRUE
  254. #define HFILE int
  255. //#define bool unsigned char
  256. #define BOOL bool
  257. #define UINT unsigned int
  258. #define CHAR char
  259. #define DWORD unsigned long
  260. #define VOID void
  261. #define LPBYTE char *
  262. #define LPSTR char *
  263. #define LPTSTR char *
  264. #define LPVOID
  265. #define FAR
  266. #define WINAPI
  267. #define fpos_ht off_t
  268. #define handle_t void *
  269. #define HINSTANCE void *
  270. #define HANDLE int
  271. #define HMODULE void *
  272. #define _MAX_PATH PATH_MAX
  273. #define HFILE_ERROR -1
  274. #define OF_READWRITE O_RDWR, S_IRUSR | S_IWUSR
  275. #define OF_READ O_RDONLY, S_IRUSR | S_IWUSR
  276. #define _O_RDWR O_RDWR
  277. #define _O_RDONLY O_RDONLY
  278. #define _O_CREAT O_CREAT
  279. #define _O_TRUNC O_TRUNC
  280. #define _O_APPEND O_APPEND
  281. #define _O_BINARY 0
  282. #define _O_SEQUENTIAL 0
  283. #define _O_TEXT 0
  284. #define _O_RDONLY O_RDONLY
  285. #define _O_WRONLY O_WRONLY
  286. #define _O_RANDOM 0
  287. #define _S_IREAD S_IRUSR | S_IRGRP | S_IROTH
  288. #define _S_IWRITE S_IWUSR | S_IWGRP | S_IWOTH
  289. #define _S_IEXEC S_IXUSR | S_IXGRP | S_IXOTH
  290. #define _S_IFDIR S_IFDIR
  291. #define FILE_CURRENT SEEK_CUR
  292. #define FILE_END SEEK_END
  293. #define FILE_BEGIN SEEK_SET
  294. #define SOCKET int
  295. #define SOCKET_ERROR -1
  296. #define INVALID_SOCKET -1
  297. #define SOCKADDR_IN struct sockaddr_in
  298. #define SOCKADDR struct sockaddr
  299. #define PSOCKADDR SOCKADDR *
  300. #define closesocket close
  301. #define ioctlsocket ioctl
  302. #define WSAGetLastError() 0
  303. #define GetCurrentDirectory(size, buf) getcwd(buf, size)
  304. #define SetCurrentDirectory(path) chdir(path)
  305. #define CreateDirectory(path,X) (_mkdir(path)==0)
  306. #define GetTempPath(size, buff) strncpy(buff, P_tmpdir, size); // return value not valid
  307. #define GetLastError() errno
  308. #define memicmp j_memicmp
  309. #define I64F "ll"
  310. #ifndef stricmp
  311. #define stricmp strcasecmp
  312. #endif
  313. #ifndef __FreeBSD__
  314. #ifndef __APPLE__
  315. #include <malloc.h>
  316. #include <alloca.h>
  317. #endif
  318. #endif
  319. #include <dlfcn.h>
  320. #include <pthread.h>
  321. #include <sys/stat.h>
  322. #include <sys/time.h>
  323. #include <sys/errno.h>
  324. #include <sys/utsname.h>
  325. #if defined (__FreeBSD__) || defined (__APPLE__)
  326. #define MAP_ANONYMOUS MAP_ANON
  327. #endif
  328. #if defined(__FreeBSD__) || defined(__linux__) || defined(__CYGWIN__) || defined (__APPLE__)
  329. #include <sys/ioctl.h>
  330. #else
  331. #include <sys/filio.h>
  332. #include <stropts.h>
  333. #include <sys/asynch.h>
  334. #define _llseek ::llseek
  335. #define _lseeki64 ::llseek
  336. #endif
  337. #define _write ::write
  338. #define _read ::read
  339. #define _open ::open
  340. #define _mkdir(P1) mkdir(P1, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH)
  341. #define GetCurrentThreadId pthread_self
  342. #define GetCurrentProcessId getpid
  343. #define _stdcall
  344. // #define inline
  345. #define SharedObjectPrefix "lib"
  346. #define SharedObjectExtension ".so"
  347. #define LibraryExtension ".so"
  348. #define ProcessExtension ""
  349. #define GetSharedProcedure(h,name) dlsym(h,(char *)name)
  350. #define LoadSucceeded(h) (h != NULL)
  351. #define GetSharedObjectError() errno
  352. #define ThreadId pthread_t
  353. #define MutexId pthread_mutex_t
  354. // **** END OF UNIX SPECIFIC SECTION ****
  355. #endif
  356. #define FLOAT_SIG_DIGITS 7
  357. #define DOUBLE_SIG_DIGITS 16
  358. #define MAX_DECIMAL_LEADING 32 // Maximum number of leading digits in a decimal field
  359. #define MAX_DECIMAL_PRECISION 32 // Maximum digits in a decimal field
  360. #define MAX_DECIMAL_DIGITS (MAX_DECIMAL_LEADING+MAX_DECIMAL_PRECISION)
  361. #define strtok(a,b) j_strtok_deprecated(a,b) // will disappear at some point
  362. typedef unsigned __int64 __uint64;
  363. typedef __uint64 offset_t;
  364. typedef unsigned char byte;
  365. // BUILD_TAG not needed here anymore - defined in build_tag.h
  366. //#define BUILD_TAG "build_0000" // Will get substituted during pre-build
  367. #endif