my_global.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. /* Copyright (C) 2000-2003 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  13. /* This is the include file that should be included 'first' in every C file. */
  14. #ifndef _global_h
  15. #define _global_h
  16. #ifndef EMBEDDED_LIBRARY
  17. #define HAVE_REPLICATION
  18. #define HAVE_EXTERNAL_CLIENT
  19. #endif
  20. #if defined( __EMX__) && !defined( MYSQL_SERVER)
  21. /* moved here to use below VOID macro redefinition */
  22. #define INCL_BASE
  23. #define INCL_NOPMAPI
  24. #include <os2.h>
  25. #endif /* __EMX__ */
  26. #ifdef __CYGWIN__
  27. /* We use a Unix API, so pretend it's not Windows */
  28. #undef WIN
  29. #undef WIN32
  30. #undef _WIN
  31. #undef _WIN32
  32. #undef _WIN64
  33. #undef __WIN__
  34. #undef __WIN32__
  35. #define HAVE_ERRNO_AS_DEFINE
  36. #endif /* __CYGWIN__ */
  37. /* to make command line shorter we'll define USE_PRAGMA_INTERFACE here */
  38. #ifdef USE_PRAGMA_IMPLEMENTATION
  39. #define USE_PRAGMA_INTERFACE
  40. #endif
  41. #if defined(i386) && !defined(__i386__)
  42. #define __i386__
  43. #endif
  44. /* Macros to make switching between C and C++ mode easier */
  45. #ifdef __cplusplus
  46. #define C_MODE_START extern "C" {
  47. #define C_MODE_END }
  48. #else
  49. #define C_MODE_START
  50. #define C_MODE_END
  51. #endif
  52. #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
  53. #include <config-win.h>
  54. #elif defined(OS2)
  55. #include <config-os2.h>
  56. #elif defined(__NETWARE__)
  57. #include <my_config.h>
  58. #include <config-netware.h>
  59. #if defined(__cplusplus) && defined(inline)
  60. #undef inline /* fix configure problem */
  61. #endif
  62. #else
  63. #include <my_config.h>
  64. #if defined(__cplusplus) && defined(inline)
  65. #undef inline /* fix configure problem */
  66. #endif
  67. #endif /* _WIN32... */
  68. /* Some defines to avoid ifdefs in the code */
  69. #ifndef NETWARE_YIELD
  70. #define NETWARE_YIELD
  71. #define NETWARE_SET_SCREEN_MODE(A)
  72. #endif
  73. /*
  74. The macros below are borrowed from include/linux/compiler.h in the
  75. Linux kernel. Use them to indicate the likelyhood of the truthfulness
  76. of a condition. This serves two purposes - newer versions of gcc will be
  77. able to optimize for branch predication, which could yield siginficant
  78. performance gains in frequently executed sections of the code, and the
  79. other reason to use them is for documentation
  80. */
  81. #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
  82. #define __builtin_expect(x, expected_value) (x)
  83. #endif
  84. #define likely(x) __builtin_expect((x),1)
  85. #define unlikely(x) __builtin_expect((x),0)
  86. /* Fix problem with S_ISLNK() on Linux */
  87. #if defined(TARGET_OS_LINUX)
  88. #undef _GNU_SOURCE
  89. #define _GNU_SOURCE 1
  90. #endif
  91. /*
  92. Temporary solution to solve bug#7156. Include "sys/types.h" before
  93. the thread headers, else the function madvise() will not be defined
  94. */
  95. #if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
  96. #include <sys/types.h>
  97. #endif
  98. /* The client defines this to avoid all thread code */
  99. #if defined(UNDEF_THREADS_HACK)
  100. #undef THREAD
  101. #undef HAVE_mit_thread
  102. #undef HAVE_LINUXTHREADS
  103. #undef HAVE_NPTL
  104. #undef HAVE_UNIXWARE7_THREADS
  105. #endif
  106. #ifdef HAVE_THREADS_WITHOUT_SOCKETS
  107. /* MIT pthreads does not work with unix sockets */
  108. #undef HAVE_SYS_UN_H
  109. #endif
  110. #define __EXTENSIONS__ 1 /* We want some extension */
  111. #ifndef __STDC_EXT__
  112. #define __STDC_EXT__ 1 /* To get large file support on hpux */
  113. #endif
  114. /*
  115. Solaris 9 include file <sys/feature_tests.h> refers to X/Open document
  116. System Interfaces and Headers, Issue 5
  117. saying we should define _XOPEN_SOURCE=500 to get POSIX.1c prototypes,
  118. but apparently other systems (namely FreeBSD) don't agree.
  119. On a newer Solaris 10, the above file recognizes also _XOPEN_SOURCE=600.
  120. Furthermore, it tests that if a program requires older standard
  121. (_XOPEN_SOURCE<600 or _POSIX_C_SOURCE<200112L) it cannot be
  122. run on a new compiler (that defines _STDC_C99) and issues an #error.
  123. It's also an #error if a program requires new standard (_XOPEN_SOURCE=600
  124. or _POSIX_C_SOURCE=200112L) and a compiler does not define _STDC_C99.
  125. To add more to this mess, Sun Studio C compiler defines _STDC_C99 while
  126. C++ compiler does not!
  127. So, in a desperate attempt to get correct prototypes for both
  128. C and C++ code, we define either _XOPEN_SOURCE=600 or _XOPEN_SOURCE=500
  129. depending on the compiler's announced C standard support.
  130. Cleaner solutions are welcome.
  131. */
  132. #ifdef __sun
  133. #if __STDC_VERSION__ - 0 >= 199901L
  134. #define _XOPEN_SOURCE 600
  135. #else
  136. #define _XOPEN_SOURCE 500
  137. #endif
  138. #endif
  139. #if defined(THREAD) && !defined(__WIN__) && !defined(OS2)
  140. #ifndef _POSIX_PTHREAD_SEMANTICS
  141. #define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
  142. #endif
  143. #if !defined(SCO)
  144. #define _REENTRANT 1 /* Some thread libraries require this */
  145. #endif
  146. #if !defined(_THREAD_SAFE) && !defined(_AIX)
  147. #define _THREAD_SAFE /* Required for OSF1 */
  148. #endif
  149. #ifndef HAVE_mit_thread
  150. #ifdef HAVE_UNIXWARE7_THREADS
  151. #include <thread.h>
  152. #else
  153. #if defined(HPUX10) || defined(HPUX11)
  154. C_MODE_START /* HPUX needs this, signal.h bug */
  155. #include <pthread.h>
  156. C_MODE_END
  157. #else
  158. #include <pthread.h> /* AIX must have this included first */
  159. #endif
  160. #endif /* HAVE_UNIXWARE7_THREADS */
  161. #endif /* HAVE_mit_thread */
  162. #if !defined(SCO) && !defined(_REENTRANT)
  163. #define _REENTRANT 1 /* Threads requires reentrant code */
  164. #endif
  165. #endif /* THREAD */
  166. /* Go around some bugs in different OS and compilers */
  167. #ifdef _AIX /* By soren@t.dk */
  168. #define _H_STRINGS
  169. #define _SYS_STREAM_H
  170. /* #define _AIX32_CURSES */ /* XXX: this breaks AIX 4.3.3 (others?). */
  171. #define ulonglong2double(A) my_ulonglong2double(A)
  172. #define my_off_t2double(A) my_ulonglong2double(A)
  173. C_MODE_START
  174. double my_ulonglong2double(unsigned long long A);
  175. C_MODE_END
  176. #endif /* _AIX */
  177. #ifdef HAVE_BROKEN_SNPRINTF /* HPUX 10.20 don't have this defined */
  178. #undef HAVE_SNPRINTF
  179. #endif
  180. #ifdef HAVE_BROKEN_PREAD
  181. /*
  182. pread()/pwrite() are not 64 bit safe on HP-UX 11.0 without
  183. installing the kernel patch PHKL_20349 or greater
  184. */
  185. #undef HAVE_PREAD
  186. #undef HAVE_PWRITE
  187. #endif
  188. #if defined(HAVE_BROKEN_INLINE) && !defined(__cplusplus)
  189. #undef inline
  190. #define inline
  191. #endif
  192. #ifdef UNDEF_HAVE_GETHOSTBYNAME_R /* For OSF4.x */
  193. #undef HAVE_GETHOSTBYNAME_R
  194. #endif
  195. #ifdef UNDEF_HAVE_INITGROUPS /* For AIX 4.3 */
  196. #undef HAVE_INITGROUPS
  197. #endif
  198. /* gcc/egcs issues */
  199. #if defined(__GNUC) && defined(__EXCEPTIONS)
  200. #error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
  201. #endif
  202. /* Fix a bug in gcc 2.8.0 on IRIX 6.2 */
  203. #if SIZEOF_LONG == 4 && defined(__LONG_MAX__) && (__GNUC__ == 2 && __GNUC_MINOR__ == 8)
  204. #undef __LONG_MAX__ /* Is a longlong value in gcc 2.8.0 ??? */
  205. #define __LONG_MAX__ 2147483647
  206. #endif
  207. /* egcs 1.1.2 has a problem with memcpy on Alpha */
  208. #if defined(__GNUC__) && defined(__alpha__) && ! (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
  209. #define BAD_MEMCPY
  210. #endif
  211. #if defined(_lint) && !defined(lint)
  212. #define lint
  213. #endif
  214. #if SIZEOF_LONG_LONG > 4 && !defined(_LONG_LONG)
  215. #define _LONG_LONG 1 /* For AIX string library */
  216. #endif
  217. #ifndef stdin
  218. #include <stdio.h>
  219. #endif
  220. #ifdef HAVE_STDLIB_H
  221. #include <stdlib.h>
  222. #endif
  223. #ifdef HAVE_STDDEF_H
  224. #include <stddef.h>
  225. #endif
  226. #include <math.h>
  227. #ifdef HAVE_LIMITS_H
  228. #include <limits.h>
  229. #endif
  230. #ifdef HAVE_FLOAT_H
  231. #include <float.h>
  232. #endif
  233. #ifdef HAVE_SYS_TYPES_H
  234. #include <sys/types.h>
  235. #endif
  236. #ifdef HAVE_FCNTL_H
  237. #include <fcntl.h>
  238. #endif
  239. #ifdef HAVE_SYS_TIMEB_H
  240. #include <sys/timeb.h> /* Avoid warnings on SCO */
  241. #endif
  242. #if TIME_WITH_SYS_TIME
  243. # include <sys/time.h>
  244. # include <time.h>
  245. #else
  246. # if HAVE_SYS_TIME_H
  247. # include <sys/time.h>
  248. # else
  249. # include <time.h>
  250. # endif
  251. #endif /* TIME_WITH_SYS_TIME */
  252. #ifdef HAVE_UNISTD_H
  253. #include <unistd.h>
  254. #endif
  255. #if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
  256. #undef HAVE_ALLOCA
  257. #undef HAVE_ALLOCA_H
  258. #endif
  259. #ifdef HAVE_ALLOCA_H
  260. #include <alloca.h>
  261. #endif
  262. #ifdef HAVE_ATOMIC_ADD
  263. #define new my_arg_new
  264. #define need_to_restore_new 1
  265. C_MODE_START
  266. #include <asm/atomic.h>
  267. C_MODE_END
  268. #ifdef need_to_restore_new /* probably safer than #ifdef new */
  269. #undef new
  270. #undef need_to_restore_new
  271. #endif
  272. #endif
  273. #include <errno.h> /* Recommended by debian */
  274. /* We need the following to go around a problem with openssl on solaris */
  275. #if defined(HAVE_CRYPT_H)
  276. #include <crypt.h>
  277. #endif
  278. /*
  279. A lot of our programs uses asserts, so better to always include it
  280. This also fixes a problem when people uses DBUG_ASSERT without including
  281. assert.h
  282. */
  283. #include <assert.h>
  284. /* Go around some bugs in different OS and compilers */
  285. #if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H)
  286. #include <sys/stream.h> /* HPUX 10.20 defines ulong here. UGLY !!! */
  287. #define HAVE_ULONG
  288. #endif
  289. #ifdef DONT_USE_FINITE /* HPUX 11.x has is_finite() */
  290. #undef HAVE_FINITE
  291. #endif
  292. #if defined(HPUX10) && defined(_LARGEFILE64_SOURCE) && defined(THREAD)
  293. /* Fix bug in setrlimit */
  294. #undef setrlimit
  295. #define setrlimit cma_setrlimit64
  296. #endif
  297. /* Declare madvise where it is not declared for C++, like Solaris */
  298. #if HAVE_MADVISE && !HAVE_DECL_MADVISE && defined(__cplusplus)
  299. extern "C" int madvise(void *addr, size_t len, int behav);
  300. #endif
  301. #ifdef __QNXNTO__
  302. /* This has to be after include limits.h */
  303. #define HAVE_ERRNO_AS_DEFINE
  304. #define HAVE_FCNTL_LOCK
  305. #undef HAVE_FINITE
  306. #undef LONGLONG_MIN /* These get wrongly defined in QNX 6.2 */
  307. #undef LONGLONG_MAX /* standard system library 'limits.h' */
  308. #ifdef __cplusplus
  309. #ifndef HAVE_RINT
  310. #define HAVE_RINT
  311. #endif /* rint() and isnan() functions are not */
  312. #define rint(a) std::rint(a) /* visible in C++ scope due to an error */
  313. #define isnan(a) std::isnan(a) /* in the usr/include/math.h on QNX */
  314. #endif
  315. #endif
  316. /* We can not live without the following defines */
  317. #define USE_MYFUNC 1 /* Must use syscall indirection */
  318. #define MASTER 1 /* Compile without unireg */
  319. #define ENGLISH 1 /* Messages in English */
  320. #define POSIX_MISTAKE 1 /* regexp: Fix stupid spec error */
  321. #define USE_REGEX 1 /* We want the use the regex library */
  322. /* Do not define for ultra sparcs */
  323. #ifndef OS2
  324. #define USE_BMOVE512 1 /* Use this unless system bmove is faster */
  325. #endif
  326. #define QUOTE_ARG(x) #x /* Quote argument (before cpp) */
  327. #define STRINGIFY_ARG(x) QUOTE_ARG(x) /* Quote argument, after cpp */
  328. /* Paranoid settings. Define I_AM_PARANOID if you are paranoid */
  329. #ifdef I_AM_PARANOID
  330. #define DONT_ALLOW_USER_CHANGE 1
  331. #define DONT_USE_MYSQL_PWD 1
  332. #endif
  333. /* Does the system remember a signal handler after a signal ? */
  334. #ifndef HAVE_BSD_SIGNALS
  335. #define DONT_REMEMBER_SIGNAL
  336. #endif
  337. /* Define void to stop lint from generating "null effekt" comments */
  338. #ifndef DONT_DEFINE_VOID
  339. #ifdef _lint
  340. int __void__;
  341. #define VOID(X) (__void__ = (int) (X))
  342. #else
  343. #undef VOID
  344. #define VOID(X) (X)
  345. #endif
  346. #endif /* DONT_DEFINE_VOID */
  347. #if defined(_lint) || defined(FORCE_INIT_OF_VARS)
  348. #define LINT_INIT(var) var=0 /* No uninitialize-warning */
  349. #else
  350. #define LINT_INIT(var)
  351. #endif
  352. #if defined(_lint) || defined(FORCE_INIT_OF_VARS) || defined(HAVE_purify)
  353. #define PURIFY_OR_LINT_INIT(var) var=0
  354. #else
  355. #define PURIFY_OR_LINT_INIT(var)
  356. #endif
  357. /* Define some useful general macros */
  358. #if !defined(max)
  359. #define max(a, b) ((a) > (b) ? (a) : (b))
  360. #define min(a, b) ((a) < (b) ? (a) : (b))
  361. #endif
  362. #if defined(__EMX__) || !defined(HAVE_UINT)
  363. #undef HAVE_UINT
  364. #define HAVE_UINT
  365. typedef unsigned int uint;
  366. typedef unsigned short ushort;
  367. #endif
  368. #define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
  369. #define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
  370. #define swap_variables(t, a, b) { register t dummy; dummy= a; a= b; b= dummy; }
  371. #define test(a) ((a) ? 1 : 0)
  372. #define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
  373. #define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
  374. #define test_all_bits(a,b) (((a) & (b)) == (b))
  375. #define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
  376. #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
  377. #ifndef HAVE_RINT
  378. #define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
  379. #endif
  380. /* Define some general constants */
  381. #ifndef TRUE
  382. #define TRUE (1) /* Logical true */
  383. #define FALSE (0) /* Logical false */
  384. #endif
  385. #if defined(__GNUC__)
  386. #define function_volatile volatile
  387. #define my_reinterpret_cast(A) reinterpret_cast<A>
  388. #define my_const_cast(A) const_cast<A>
  389. #elif !defined(my_reinterpret_cast)
  390. #define my_reinterpret_cast(A) (A)
  391. #define my_const_cast(A) (A)
  392. #endif
  393. #if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
  394. #define __attribute__(A)
  395. #endif
  396. /* From old s-system.h */
  397. /*
  398. Support macros for non ansi & other old compilers. Since such
  399. things are no longer supported we do nothing. We keep then since
  400. some of our code may still be needed to upgrade old customers.
  401. */
  402. #define _VARARGS(X) X
  403. #define _STATIC_VARARGS(X) X
  404. #define _PC(X) X
  405. #if defined(DBUG_ON) && defined(DBUG_OFF)
  406. #undef DBUG_OFF
  407. #endif
  408. #if defined(_lint) && !defined(DBUG_OFF)
  409. #define DBUG_OFF
  410. #endif
  411. #include <my_dbug.h>
  412. #define MIN_ARRAY_SIZE 0 /* Zero or One. Gcc allows zero*/
  413. #define ASCII_BITS_USED 8 /* Bit char used */
  414. #define NEAR_F /* No near function handling */
  415. /* Some types that is different between systems */
  416. typedef int File; /* File descriptor */
  417. #ifndef Socket_defined
  418. typedef int my_socket; /* File descriptor for sockets */
  419. #define INVALID_SOCKET -1
  420. #endif
  421. /* Type for fuctions that handles signals */
  422. #define sig_handler RETSIGTYPE
  423. C_MODE_START
  424. typedef void (*sig_return)();/* Returns type from signal */
  425. C_MODE_END
  426. #if defined(__GNUC__) && !defined(_lint)
  427. typedef char pchar; /* Mixed prototypes can take char */
  428. typedef char puchar; /* Mixed prototypes can take char */
  429. typedef char pbool; /* Mixed prototypes can take char */
  430. typedef short pshort; /* Mixed prototypes can take short int */
  431. typedef float pfloat; /* Mixed prototypes can take float */
  432. #else
  433. //These types already exist in WinNT systems...
  434. //...but what do we do about Win9X ones? [Skotlex]
  435. //typedef int pchar; /* Mixed prototypes can't take char */
  436. //typedef uint puchar; /* Mixed prototypes can't take char */
  437. typedef int pbool; /* Mixed prototypes can't take char */
  438. typedef int pshort; /* Mixed prototypes can't take short int */
  439. typedef double pfloat; /* Mixed prototypes can't take float */
  440. #endif
  441. C_MODE_START
  442. typedef int (*qsort_cmp)(const void *,const void *);
  443. typedef int (*qsort_cmp2)(void*, const void *,const void *);
  444. C_MODE_END
  445. #ifdef HAVE_mit_thread
  446. #define qsort_t void
  447. #undef QSORT_TYPE_IS_VOID
  448. #define QSORT_TYPE_IS_VOID
  449. #else
  450. #define qsort_t RETQSORTTYPE /* Broken GCC cant handle typedef !!!! */
  451. #endif
  452. #ifdef HAVE_mit_thread
  453. #define size_socket socklen_t /* Type of last arg to accept */
  454. #else
  455. #ifdef HAVE_SYS_SOCKET_H
  456. #include <sys/socket.h>
  457. #endif
  458. typedef SOCKET_SIZE_TYPE size_socket;
  459. #endif
  460. #ifndef SOCKOPT_OPTLEN_TYPE
  461. #define SOCKOPT_OPTLEN_TYPE size_socket
  462. #endif
  463. /* file create flags */
  464. #ifndef O_SHARE /* Probably not windows */
  465. #define O_SHARE 0 /* Flag to my_open for shared files */
  466. #ifndef O_BINARY
  467. #define O_BINARY 0 /* Flag to my_open for binary files */
  468. #endif
  469. #ifndef FILE_BINARY
  470. #define FILE_BINARY O_BINARY /* Flag to my_fopen for binary streams */
  471. #endif
  472. #ifdef HAVE_FCNTL
  473. #define HAVE_FCNTL_LOCK
  474. #define F_TO_EOF 0L /* Param to lockf() to lock rest of file */
  475. #endif
  476. #endif /* O_SHARE */
  477. #ifndef O_TEMPORARY
  478. #define O_TEMPORARY 0
  479. #endif
  480. #ifndef O_SHORT_LIVED
  481. #define O_SHORT_LIVED 0
  482. #endif
  483. #ifndef O_NOFOLLOW
  484. #define O_NOFOLLOW 0
  485. #endif
  486. /* additional file share flags for win32 */
  487. #ifdef __WIN__
  488. #define _SH_DENYRWD 0x110 /* deny read/write mode & delete */
  489. #define _SH_DENYWRD 0x120 /* deny write mode & delete */
  490. #define _SH_DENYRDD 0x130 /* deny read mode & delete */
  491. #define _SH_DENYDEL 0x140 /* deny delete only */
  492. #endif /* __WIN__ */
  493. /* #define USE_RECORD_LOCK */
  494. /* Unsigned types supported by the compiler */
  495. #define UNSINT8 /* unsigned int8 (char) */
  496. #define UNSINT16 /* unsigned int16 */
  497. #define UNSINT32 /* unsigned int32 */
  498. /* General constants */
  499. #define SC_MAXWIDTH 256 /* Max width of screen (for error messages) */
  500. #define FN_LEN 256 /* Max file name len */
  501. #define FN_HEADLEN 253 /* Max length of filepart of file name */
  502. #define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */
  503. #ifdef PATH_MAX
  504. #define FN_REFLEN PATH_MAX/* Max length of full path-name */
  505. #else
  506. #define FN_REFLEN 512 /* Max length of full path-name */
  507. #endif
  508. #define FN_EXTCHAR '.'
  509. #define FN_HOMELIB '~' /* ~/ is used as abbrev for home dir */
  510. #define FN_CURLIB '.' /* ./ is used as abbrev for current dir */
  511. #define FN_PARENTDIR ".." /* Parent directory; Must be a string */
  512. #define FN_DEVCHAR ':'
  513. #ifndef FN_LIBCHAR
  514. #ifdef __EMX__
  515. #define FN_LIBCHAR '\\'
  516. #define FN_ROOTDIR "\\"
  517. #else
  518. #define FN_LIBCHAR '/'
  519. #define FN_ROOTDIR "/"
  520. #endif
  521. #endif
  522. #define MY_NFILE 64 /* This is only used to save filenames */
  523. #ifndef OS_FILE_LIMIT
  524. #define OS_FILE_LIMIT 65535
  525. #endif
  526. /* #define EXT_IN_LIBNAME */
  527. /* #define FN_NO_CASE_SENCE */
  528. /* #define FN_UPPER_CASE TRUE */
  529. /*
  530. Io buffer size; Must be a power of 2 and a multiple of 512. May be
  531. smaller what the disk page size. This influences the speed of the
  532. isam btree library. eg to big to slow.
  533. */
  534. #define IO_SIZE 4096
  535. /*
  536. How much overhead does malloc have. The code often allocates
  537. something like 1024-MALLOC_OVERHEAD bytes
  538. */
  539. #ifdef SAFEMALLOC
  540. #define MALLOC_OVERHEAD (8+24+4)
  541. #else
  542. #define MALLOC_OVERHEAD 8
  543. #endif
  544. /* get memory in huncs */
  545. #define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD)
  546. /* Typical record cash */
  547. #define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD)
  548. /* Typical key cash */
  549. #define KEY_CACHE_SIZE (uint) (8*1024*1024-MALLOC_OVERHEAD)
  550. /* Default size of a key cache block */
  551. #define KEY_CACHE_BLOCK_SIZE (uint) 1024
  552. /* Some things that this system doesn't have */
  553. #define NO_HASH /* Not needed anymore */
  554. #ifdef __WIN__
  555. #define NO_DIR_LIBRARY /* Not standar dir-library */
  556. #define USE_MY_STAT_STRUCT /* For my_lib */
  557. #endif
  558. /* Some defines of functions for portability */
  559. #undef remove /* Crashes MySQL on SCO 5.0.0 */
  560. #ifndef __WIN__
  561. #ifdef OS2
  562. #define closesocket(A) soclose(A)
  563. #else
  564. #define closesocket(A) close(A)
  565. #endif
  566. #ifndef ulonglong2double
  567. #define ulonglong2double(A) ((double) (ulonglong) (A))
  568. #define my_off_t2double(A) ((double) (my_off_t) (A))
  569. #endif
  570. #endif
  571. #ifndef offsetof
  572. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  573. #endif
  574. #define ulong_to_double(X) ((double) (ulong) (X))
  575. #define SET_STACK_SIZE(X) /* Not needed on real machines */
  576. #if !defined(HAVE_mit_thread) && !defined(HAVE_STRTOK_R)
  577. #define strtok_r(A,B,C) strtok((A),(B))
  578. #endif
  579. /* Remove some things that mit_thread break or doesn't support */
  580. #if defined(HAVE_mit_thread) && defined(THREAD)
  581. #undef HAVE_PREAD
  582. #undef HAVE_REALPATH
  583. #undef HAVE_MLOCK
  584. #undef HAVE_TEMPNAM /* Use ours */
  585. #undef HAVE_PTHREAD_SETPRIO
  586. #undef HAVE_FTRUNCATE
  587. #undef HAVE_READLINK
  588. #endif
  589. /* This is from the old m-machine.h file */
  590. #if SIZEOF_LONG_LONG > 4
  591. #define HAVE_LONG_LONG 1
  592. #endif
  593. /*
  594. Some pre-ANSI-C99 systems like AIX 5.1 and Linux/GCC 2.95 define
  595. ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined.
  596. Also on Windows we define these constants by hand in config-win.h.
  597. */
  598. #if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
  599. #define LONGLONG_MIN ((long long) 0x8000000000000000LL)
  600. #define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL)
  601. #endif
  602. #if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
  603. /* First check for ANSI C99 definition: */
  604. #ifdef ULLONG_MAX
  605. #define ULONGLONG_MAX ULLONG_MAX
  606. #else
  607. #define ULONGLONG_MAX ((unsigned long long)(~0ULL))
  608. #endif
  609. #endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/
  610. #define INT_MIN32 (~0x7FFFFFFFL)
  611. #define INT_MAX32 0x7FFFFFFFL
  612. #define UINT_MAX32 0xFFFFFFFFL
  613. #define INT_MIN24 (~0x007FFFFF)
  614. #define INT_MAX24 0x007FFFFF
  615. #define UINT_MAX24 0x00FFFFFF
  616. #define INT_MIN16 (~0x7FFF)
  617. #define INT_MAX16 0x7FFF
  618. #define UINT_MAX16 0xFFFF
  619. #define INT_MIN8 (~0x7F)
  620. #define INT_MAX8 0x7F
  621. #define UINT_MAX8 0xFF
  622. /* From limits.h instead */
  623. #ifndef DBL_MIN
  624. #define DBL_MIN 4.94065645841246544e-324
  625. #define FLT_MIN ((float)1.40129846432481707e-45)
  626. #endif
  627. #ifndef DBL_MAX
  628. #define DBL_MAX 1.79769313486231470e+308
  629. #define FLT_MAX ((float)3.40282346638528860e+38)
  630. #endif
  631. #if !defined(HAVE_ISINF) && !defined(isinf)
  632. #define isinf(X) 0
  633. #endif
  634. /* Define missing math constants. */
  635. #ifndef M_PI
  636. #define M_PI 3.14159265358979323846
  637. #endif
  638. #ifndef M_E
  639. #define M_E 2.7182818284590452354
  640. #endif
  641. #ifndef M_LN2
  642. #define M_LN2 0.69314718055994530942
  643. #endif
  644. /*
  645. Max size that must be added to a so that we know Size to make
  646. adressable obj.
  647. */
  648. #if SIZEOF_CHARP == 4
  649. typedef long my_ptrdiff_t;
  650. #else
  651. typedef long long my_ptrdiff_t;
  652. #endif
  653. #define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
  654. #define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
  655. /* Size to make adressable obj. */
  656. #define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
  657. /* Offset of field f in structure t */
  658. #define OFFSET(t, f) ((size_t)(char *)&((t *)0)->f)
  659. #define ADD_TO_PTR(ptr,size,type) (type) ((byte*) (ptr)+size)
  660. #define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((byte*) (A) - (byte*) (B))
  661. #define NullS (char *) 0
  662. /* Nowdays we do not support MessyDos */
  663. #ifndef NEAR
  664. #define NEAR /* Who needs segments ? */
  665. #define FAR /* On a good machine */
  666. #ifndef HUGE_PTR
  667. #define HUGE_PTR
  668. #endif
  669. #endif
  670. #if defined(__IBMC__) || defined(__IBMCPP__)
  671. /* This was _System _Export but caused a lot of warnings on _AIX43 */
  672. #define STDCALL
  673. #elif !defined( STDCALL)
  674. #define STDCALL
  675. #endif
  676. /* Typdefs for easyier portability */
  677. #if defined(VOIDTYPE)
  678. typedef void *gptr; /* Generic pointer */
  679. #else
  680. typedef char *gptr; /* Generic pointer */
  681. #endif
  682. #ifndef HAVE_INT_8_16_32
  683. typedef signed char int8; /* Signed integer >= 8 bits */
  684. typedef short int16; /* Signed integer >= 16 bits */
  685. #endif
  686. #ifndef HAVE_UCHAR
  687. typedef unsigned char uchar; /* Short for unsigned char */
  688. #endif
  689. typedef unsigned char uint8; /* Short for unsigned integer >= 8 bits */
  690. typedef unsigned short uint16; /* Short for unsigned integer >= 16 bits */
  691. #if SIZEOF_INT == 4
  692. #ifndef HAVE_INT_8_16_32
  693. typedef int int32;
  694. #endif
  695. typedef unsigned int uint32; /* Short for unsigned integer >= 32 bits */
  696. #elif SIZEOF_LONG == 4
  697. #ifndef HAVE_INT_8_16_32
  698. typedef long int32;
  699. #endif
  700. typedef unsigned long uint32; /* Short for unsigned integer >= 32 bits */
  701. #else
  702. #error "Neither int or long is of 4 bytes width"
  703. #endif
  704. #if !defined(HAVE_ULONG) && !defined(TARGET_OS_LINUX) && !defined(__USE_MISC)
  705. typedef unsigned long ulong; /* Short for unsigned long */
  706. #endif
  707. #ifndef longlong_defined
  708. #if defined(HAVE_LONG_LONG) && SIZEOF_LONG != 8
  709. typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
  710. typedef long long int longlong;
  711. #else
  712. typedef unsigned long ulonglong; /* ulong or unsigned long long */
  713. typedef long longlong;
  714. #endif
  715. #endif
  716. #if defined(NO_CLIENT_LONG_LONG)
  717. typedef unsigned long my_ulonglong;
  718. #elif defined (__WIN__)
  719. typedef unsigned __int64 my_ulonglong;
  720. #else
  721. typedef unsigned long long my_ulonglong;
  722. #endif
  723. #ifdef USE_RAID
  724. /*
  725. The following is done with a if to not get problems with pre-processors
  726. with late define evaluation
  727. */
  728. #if SIZEOF_OFF_T == 4
  729. #define SYSTEM_SIZEOF_OFF_T 4
  730. #else
  731. #define SYSTEM_SIZEOF_OFF_T 8
  732. #endif
  733. #undef SIZEOF_OFF_T
  734. #define SIZEOF_OFF_T 8
  735. #else
  736. #define SYSTEM_SIZEOF_OFF_T SIZEOF_OFF_T
  737. #endif /* USE_RAID */
  738. #if SIZEOF_OFF_T > 4
  739. typedef ulonglong my_off_t;
  740. #else
  741. typedef unsigned long my_off_t;
  742. #endif
  743. #define MY_FILEPOS_ERROR (~(my_off_t) 0)
  744. #if !defined(__WIN__) && !defined(OS2)
  745. typedef off_t os_off_t;
  746. #endif
  747. #if defined(__WIN__)
  748. #define socket_errno WSAGetLastError()
  749. #define SOCKET_EINTR WSAEINTR
  750. #define SOCKET_EAGAIN WSAEINPROGRESS
  751. #define SOCKET_ETIMEDOUT WSAETIMEDOUT
  752. #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
  753. #define SOCKET_ENFILE ENFILE
  754. #define SOCKET_EMFILE EMFILE
  755. #elif defined(OS2)
  756. #define socket_errno sock_errno()
  757. #define SOCKET_EINTR SOCEINTR
  758. #define SOCKET_EAGAIN SOCEINPROGRESS
  759. #define SOCKET_ETIMEDOUT SOCKET_EINTR
  760. #define SOCKET_EWOULDBLOCK SOCEWOULDBLOCK
  761. #define SOCKET_ENFILE SOCENFILE
  762. #define SOCKET_EMFILE SOCEMFILE
  763. #define closesocket(A) soclose(A)
  764. #else /* Unix */
  765. #define socket_errno errno
  766. #define closesocket(A) close(A)
  767. #define SOCKET_EINTR EINTR
  768. #define SOCKET_EAGAIN EAGAIN
  769. #define SOCKET_ETIMEDOUT SOCKET_EINTR
  770. #define SOCKET_EWOULDBLOCK EWOULDBLOCK
  771. #define SOCKET_ENFILE ENFILE
  772. #define SOCKET_EMFILE EMFILE
  773. #endif
  774. typedef uint8 int7; /* Most effective integer 0 <= x <= 127 */
  775. typedef short int15; /* Most effective integer 0 <= x <= 32767 */
  776. typedef char *my_string; /* String of characters */
  777. typedef unsigned long size_s; /* Size of strings (In string-funcs) */
  778. typedef int myf; /* Type of MyFlags in my_funcs */
  779. #ifndef byte_defined
  780. typedef char byte; /* Smallest addressable unit */
  781. #endif
  782. typedef char my_bool; /* Small bool */
  783. #if !defined(bool) && !defined(bool_defined) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
  784. typedef char bool; /* Ordinary boolean values 0 1 */
  785. #endif
  786. /* Macros for converting *constants* to the right type */
  787. #define INT8(v) (int8) (v)
  788. #define INT16(v) (int16) (v)
  789. #define INT32(v) (int32) (v)
  790. #define MYF(v) (myf) (v)
  791. #ifndef LL
  792. #ifdef HAVE_LONG_LONG
  793. #define LL(A) A ## LL
  794. #else
  795. #define LL(A) A ## L
  796. #endif
  797. #endif
  798. #ifndef ULL
  799. #ifdef HAVE_LONG_LONG
  800. #define ULL(A) A ## ULL
  801. #else
  802. #define ULL(A) A ## UL
  803. #endif
  804. #endif
  805. /*
  806. Defines to make it possible to prioritize register assignments. No
  807. longer that important with modern compilers.
  808. */
  809. #ifndef USING_X
  810. #define reg1 register
  811. #define reg2 register
  812. #define reg3 register
  813. #define reg4 register
  814. #define reg5 register
  815. #define reg6 register
  816. #define reg7 register
  817. #define reg8 register
  818. #define reg9 register
  819. #define reg10 register
  820. #define reg11 register
  821. #define reg12 register
  822. #define reg13 register
  823. #define reg14 register
  824. #define reg15 register
  825. #define reg16 register
  826. #endif
  827. /*
  828. Sometimes we want to make sure that the variable is not put into
  829. a register in debugging mode so we can see its value in the core
  830. */
  831. #ifndef DBUG_OFF
  832. #define dbug_volatile volatile
  833. #else
  834. #define dbug_volatile
  835. #endif
  836. /* Defines for time function */
  837. #define SCALE_SEC 100
  838. #define SCALE_USEC 10000
  839. #define MY_HOW_OFTEN_TO_ALARM 2 /* How often we want info on screen */
  840. #define MY_HOW_OFTEN_TO_WRITE 1000 /* How often we want info on screen */
  841. #ifdef HAVE_TIMESPEC_TS_SEC
  842. #ifndef set_timespec
  843. #define set_timespec(ABSTIME,SEC) \
  844. { \
  845. (ABSTIME).ts_sec=time(0) + (time_t) (SEC); \
  846. (ABSTIME).ts_nsec=0; \
  847. }
  848. #endif /* !set_timespec */
  849. #ifndef set_timespec_nsec
  850. #define set_timespec_nsec(ABSTIME,NSEC) \
  851. { \
  852. ulonglong now= my_getsystime() + (NSEC/100); \
  853. (ABSTIME).ts_sec= (now / ULL(10000000)); \
  854. (ABSTIME).ts_nsec= (now % ULL(10000000) * 100 + ((NSEC) % 100)); \
  855. }
  856. #endif /* !set_timespec_nsec */
  857. #else
  858. #ifndef set_timespec
  859. #define set_timespec(ABSTIME,SEC) \
  860. {\
  861. struct timeval tv;\
  862. gettimeofday(&tv,0);\
  863. (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\
  864. (ABSTIME).tv_nsec=tv.tv_usec*1000;\
  865. }
  866. #endif /* !set_timespec */
  867. #ifndef set_timespec_nsec
  868. #define set_timespec_nsec(ABSTIME,NSEC) \
  869. {\
  870. ulonglong now= my_getsystime() + (NSEC/100); \
  871. (ABSTIME).tv_sec= (now / ULL(10000000)); \
  872. (ABSTIME).tv_nsec= (now % ULL(10000000) * 100 + ((NSEC) % 100)); \
  873. }
  874. #endif /* !set_timespec_nsec */
  875. #endif /* HAVE_TIMESPEC_TS_SEC */
  876. /*
  877. Define-funktions for reading and storing in machine independent format
  878. (low byte first)
  879. */
  880. /* Optimized store functions for Intel x86 */
  881. #if defined(__i386__) && !defined(_WIN64)
  882. #define sint2korr(A) (*((int16 *) (A)))
  883. #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
  884. (((uint32) 255L << 24) | \
  885. (((uint32) (uchar) (A)[2]) << 16) |\
  886. (((uint32) (uchar) (A)[1]) << 8) | \
  887. ((uint32) (uchar) (A)[0])) : \
  888. (((uint32) (uchar) (A)[2]) << 16) |\
  889. (((uint32) (uchar) (A)[1]) << 8) | \
  890. ((uint32) (uchar) (A)[0])))
  891. #define sint4korr(A) (*((long *) (A)))
  892. #define uint2korr(A) (*((uint16 *) (A)))
  893. #ifdef HAVE_purify
  894. #define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
  895. (((uint32) ((uchar) (A)[1])) << 8) +\
  896. (((uint32) ((uchar) (A)[2])) << 16))
  897. #else
  898. /*
  899. ATTENTION !
  900. Please, note, uint3korr reads 4 bytes (not 3) !
  901. It means, that you have to provide enough allocated space !
  902. */
  903. #define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF)
  904. #endif
  905. #define uint4korr(A) (*((unsigned long *) (A)))
  906. #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  907. (((uint32) ((uchar) (A)[1])) << 8) +\
  908. (((uint32) ((uchar) (A)[2])) << 16) +\
  909. (((uint32) ((uchar) (A)[3])) << 24)) +\
  910. (((ulonglong) ((uchar) (A)[4])) << 32))
  911. #define uint8korr(A) (*((ulonglong *) (A)))
  912. #define sint8korr(A) (*((longlong *) (A)))
  913. #define int2store(T,A) *((uint16*) (T))= (uint16) (A)
  914. #define int3store(T,A) do { *(T)= (uchar) ((A));\
  915. *(T+1)=(uchar) (((uint) (A) >> 8));\
  916. *(T+2)=(uchar) (((A) >> 16)); } while (0)
  917. #define int4store(T,A) *((long *) (T))= (long) (A)
  918. #define int5store(T,A) do { *(T)= (uchar)((A));\
  919. *((T)+1)=(uchar) (((A) >> 8));\
  920. *((T)+2)=(uchar) (((A) >> 16));\
  921. *((T)+3)=(uchar) (((A) >> 24)); \
  922. *((T)+4)=(uchar) (((A) >> 32)); } while(0)
  923. #define int8store(T,A) *((ulonglong *) (T))= (ulonglong) (A)
  924. typedef union {
  925. double v;
  926. long m[2];
  927. } doubleget_union;
  928. #define doubleget(V,M) \
  929. do { doubleget_union _tmp; \
  930. _tmp.m[0] = *((long*)(M)); \
  931. _tmp.m[1] = *(((long*) (M))+1); \
  932. (V) = _tmp.v; } while(0)
  933. #define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
  934. *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
  935. } while (0)
  936. #define float4get(V,M) do { *((long *) &(V)) = *((long*) (M)); } while(0)
  937. #define float8get(V,M) doubleget((V),(M))
  938. #define float4store(V,M) memcpy((byte*) V,(byte*) (&M),sizeof(float))
  939. #define floatstore(T,V) memcpy((byte*)(T), (byte*)(&V),sizeof(float))
  940. #define floatget(V,M) memcpy((byte*) &V,(byte*) (M),sizeof(float))
  941. #define float8store(V,M) doublestore((V),(M))
  942. #endif /* __i386__ */
  943. #ifndef sint2korr
  944. /*
  945. We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
  946. were done before)
  947. */
  948. #define sint2korr(A) (int16) (((int16) ((uchar) (A)[0])) +\
  949. ((int16) ((int16) (A)[1]) << 8))
  950. #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
  951. (((uint32) 255L << 24) | \
  952. (((uint32) (uchar) (A)[2]) << 16) |\
  953. (((uint32) (uchar) (A)[1]) << 8) | \
  954. ((uint32) (uchar) (A)[0])) : \
  955. (((uint32) (uchar) (A)[2]) << 16) |\
  956. (((uint32) (uchar) (A)[1]) << 8) | \
  957. ((uint32) (uchar) (A)[0])))
  958. #define sint4korr(A) (int32) (((int32) ((uchar) (A)[0])) +\
  959. (((int32) ((uchar) (A)[1]) << 8)) +\
  960. (((int32) ((uchar) (A)[2]) << 16)) +\
  961. (((int32) ((int16) (A)[3]) << 24)))
  962. #define sint8korr(A) (longlong) uint8korr(A)
  963. #define uint2korr(A) (uint16) (((uint16) ((uchar) (A)[0])) +\
  964. ((uint16) ((uchar) (A)[1]) << 8))
  965. #define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
  966. (((uint32) ((uchar) (A)[1])) << 8) +\
  967. (((uint32) ((uchar) (A)[2])) << 16))
  968. #define uint4korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
  969. (((uint32) ((uchar) (A)[1])) << 8) +\
  970. (((uint32) ((uchar) (A)[2])) << 16) +\
  971. (((uint32) ((uchar) (A)[3])) << 24))
  972. #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  973. (((uint32) ((uchar) (A)[1])) << 8) +\
  974. (((uint32) ((uchar) (A)[2])) << 16) +\
  975. (((uint32) ((uchar) (A)[3])) << 24)) +\
  976. (((ulonglong) ((uchar) (A)[4])) << 32))
  977. #define uint8korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  978. (((uint32) ((uchar) (A)[1])) << 8) +\
  979. (((uint32) ((uchar) (A)[2])) << 16) +\
  980. (((uint32) ((uchar) (A)[3])) << 24)) +\
  981. (((ulonglong) (((uint32) ((uchar) (A)[4])) +\
  982. (((uint32) ((uchar) (A)[5])) << 8) +\
  983. (((uint32) ((uchar) (A)[6])) << 16) +\
  984. (((uint32) ((uchar) (A)[7])) << 24))) <<\
  985. 32))
  986. #define int2store(T,A) do { uint def_temp= (uint) (A) ;\
  987. *((uchar*) (T))= (uchar)(def_temp); \
  988. *((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \
  989. } while(0)
  990. #define int3store(T,A) do { /*lint -save -e734 */\
  991. *((uchar*)(T))=(uchar) ((A));\
  992. *((uchar*) (T)+1)=(uchar) (((A) >> 8));\
  993. *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \
  994. /*lint -restore */} while(0)
  995. #define int4store(T,A) do { *((char *)(T))=(char) ((A));\
  996. *(((char *)(T))+1)=(char) (((A) >> 8));\
  997. *(((char *)(T))+2)=(char) (((A) >> 16));\
  998. *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
  999. #define int5store(T,A) do { *((char *)(T))=((A));\
  1000. *(((char *)(T))+1)=(((A) >> 8));\
  1001. *(((char *)(T))+2)=(((A) >> 16));\
  1002. *(((char *)(T))+3)=(((A) >> 24)); \
  1003. *(((char *)(T))+4)=(((A) >> 32)); } while(0)
  1004. #define int8store(T,A) do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \
  1005. int4store((T),def_temp); \
  1006. int4store((T+4),def_temp2); } while(0)
  1007. #ifdef WORDS_BIGENDIAN
  1008. #define float4store(T,A) do { *(T)= ((byte *) &A)[3];\
  1009. *((T)+1)=(char) ((byte *) &A)[2];\
  1010. *((T)+2)=(char) ((byte *) &A)[1];\
  1011. *((T)+3)=(char) ((byte *) &A)[0]; } while(0)
  1012. #define float4get(V,M) do { float def_temp;\
  1013. ((byte*) &def_temp)[0]=(M)[3];\
  1014. ((byte*) &def_temp)[1]=(M)[2];\
  1015. ((byte*) &def_temp)[2]=(M)[1];\
  1016. ((byte*) &def_temp)[3]=(M)[0];\
  1017. (V)=def_temp; } while(0)
  1018. #define float8store(T,V) do { *(T)= ((byte *) &V)[7];\
  1019. *((T)+1)=(char) ((byte *) &V)[6];\
  1020. *((T)+2)=(char) ((byte *) &V)[5];\
  1021. *((T)+3)=(char) ((byte *) &V)[4];\
  1022. *((T)+4)=(char) ((byte *) &V)[3];\
  1023. *((T)+5)=(char) ((byte *) &V)[2];\
  1024. *((T)+6)=(char) ((byte *) &V)[1];\
  1025. *((T)+7)=(char) ((byte *) &V)[0]; } while(0)
  1026. #define float8get(V,M) do { double def_temp;\
  1027. ((byte*) &def_temp)[0]=(M)[7];\
  1028. ((byte*) &def_temp)[1]=(M)[6];\
  1029. ((byte*) &def_temp)[2]=(M)[5];\
  1030. ((byte*) &def_temp)[3]=(M)[4];\
  1031. ((byte*) &def_temp)[4]=(M)[3];\
  1032. ((byte*) &def_temp)[5]=(M)[2];\
  1033. ((byte*) &def_temp)[6]=(M)[1];\
  1034. ((byte*) &def_temp)[7]=(M)[0];\
  1035. (V) = def_temp; } while(0)
  1036. #else
  1037. #define float4get(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(float))
  1038. #define float4store(V,M) memcpy_fixed((byte*) V,(byte*) (&M),sizeof(float))
  1039. #if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
  1040. #define doublestore(T,V) do { *(((char*)T)+0)=(char) ((byte *) &V)[4];\
  1041. *(((char*)T)+1)=(char) ((byte *) &V)[5];\
  1042. *(((char*)T)+2)=(char) ((byte *) &V)[6];\
  1043. *(((char*)T)+3)=(char) ((byte *) &V)[7];\
  1044. *(((char*)T)+4)=(char) ((byte *) &V)[0];\
  1045. *(((char*)T)+5)=(char) ((byte *) &V)[1];\
  1046. *(((char*)T)+6)=(char) ((byte *) &V)[2];\
  1047. *(((char*)T)+7)=(char) ((byte *) &V)[3]; }\
  1048. while(0)
  1049. #define doubleget(V,M) do { double def_temp;\
  1050. ((byte*) &def_temp)[0]=(M)[4];\
  1051. ((byte*) &def_temp)[1]=(M)[5];\
  1052. ((byte*) &def_temp)[2]=(M)[6];\
  1053. ((byte*) &def_temp)[3]=(M)[7];\
  1054. ((byte*) &def_temp)[4]=(M)[0];\
  1055. ((byte*) &def_temp)[5]=(M)[1];\
  1056. ((byte*) &def_temp)[6]=(M)[2];\
  1057. ((byte*) &def_temp)[7]=(M)[3];\
  1058. (V) = def_temp; } while(0)
  1059. #endif /* __FLOAT_WORD_ORDER */
  1060. #define float8get(V,M) doubleget((V),(M))
  1061. #define float8store(V,M) doublestore((V),(M))
  1062. #endif /* WORDS_BIGENDIAN */
  1063. #endif /* sint2korr */
  1064. /*
  1065. Macro for reading 32-bit integer from network byte order (big-endian)
  1066. from unaligned memory location.
  1067. */
  1068. #define int4net(A) (int32) (((uint32) ((uchar) (A)[3])) |\
  1069. (((uint32) ((uchar) (A)[2])) << 8) |\
  1070. (((uint32) ((uchar) (A)[1])) << 16) |\
  1071. (((uint32) ((uchar) (A)[0])) << 24))
  1072. /*
  1073. Define-funktions for reading and storing in machine format from/to
  1074. short/long to/from some place in memory V should be a (not
  1075. register) variable, M is a pointer to byte
  1076. */
  1077. #ifdef WORDS_BIGENDIAN
  1078. #define ushortget(V,M) do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\
  1079. ((uint16) ((uint16) (M)[0]) << 8)); } while(0)
  1080. #define shortget(V,M) do { V = (short) (((short) ((uchar) (M)[1]))+\
  1081. ((short) ((short) (M)[0]) << 8)); } while(0)
  1082. #define longget(V,M) do { int32 def_temp;\
  1083. ((byte*) &def_temp)[0]=(M)[0];\
  1084. ((byte*) &def_temp)[1]=(M)[1];\
  1085. ((byte*) &def_temp)[2]=(M)[2];\
  1086. ((byte*) &def_temp)[3]=(M)[3];\
  1087. (V)=def_temp; } while(0)
  1088. #define ulongget(V,M) do { uint32 def_temp;\
  1089. ((byte*) &def_temp)[0]=(M)[0];\
  1090. ((byte*) &def_temp)[1]=(M)[1];\
  1091. ((byte*) &def_temp)[2]=(M)[2];\
  1092. ((byte*) &def_temp)[3]=(M)[3];\
  1093. (V)=def_temp; } while(0)
  1094. #define shortstore(T,A) do { uint def_temp=(uint) (A) ;\
  1095. *(((char*)T)+1)=(char)(def_temp); \
  1096. *(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
  1097. #define longstore(T,A) do { *(((char*)T)+3)=((A));\
  1098. *(((char*)T)+2)=(((A) >> 8));\
  1099. *(((char*)T)+1)=(((A) >> 16));\
  1100. *(((char*)T)+0)=(((A) >> 24)); } while(0)
  1101. #define floatget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(float))
  1102. #define floatstore(T,V) memcpy_fixed((byte*) (T),(byte*)(&V),sizeof(float))
  1103. #define doubleget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(double))
  1104. #define doublestore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(double))
  1105. #define longlongget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(ulonglong))
  1106. #define longlongstore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(ulonglong))
  1107. #else
  1108. #define ushortget(V,M) do { V = uint2korr(M); } while(0)
  1109. #define shortget(V,M) do { V = sint2korr(M); } while(0)
  1110. #define longget(V,M) do { V = sint4korr(M); } while(0)
  1111. #define ulongget(V,M) do { V = uint4korr(M); } while(0)
  1112. #define shortstore(T,V) int2store(T,V)
  1113. #define longstore(T,V) int4store(T,V)
  1114. #ifndef floatstore
  1115. #define floatstore(T,V) memcpy_fixed((byte*) (T),(byte*) (&V),sizeof(float))
  1116. #define floatget(V,M) memcpy_fixed((byte*) &V, (byte*) (M), sizeof(float))
  1117. #endif
  1118. #ifndef doubleget
  1119. #define doubleget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(double))
  1120. #define doublestore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(double))
  1121. #endif /* doubleget */
  1122. #define longlongget(V,M) memcpy_fixed((byte*) &V,(byte*) (M),sizeof(ulonglong))
  1123. #define longlongstore(T,V) memcpy_fixed((byte*) (T),(byte*) &V,sizeof(ulonglong))
  1124. #endif /* WORDS_BIGENDIAN */
  1125. /* sprintf does not always return the number of bytes :- */
  1126. #ifdef SPRINTF_RETURNS_INT
  1127. #define my_sprintf(buff,args) sprintf args
  1128. #else
  1129. #ifdef SPRINTF_RETURNS_PTR
  1130. #define my_sprintf(buff,args) ((int)(sprintf args - buff))
  1131. #else
  1132. #define my_sprintf(buff,args) ((ulong) sprintf args, (ulong) strlen(buff))
  1133. #endif
  1134. #endif
  1135. #ifndef THREAD
  1136. #define thread_safe_increment(V,L) (V)++
  1137. #define thread_safe_add(V,C,L) (V)+=(C)
  1138. #define thread_safe_sub(V,C,L) (V)-=(C)
  1139. #define statistic_increment(V,L) (V)++
  1140. #define statistic_add(V,C,L) (V)+=(C)
  1141. #endif
  1142. #ifdef HAVE_CHARSET_utf8
  1143. #define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8"
  1144. #else
  1145. #define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
  1146. #endif
  1147. #if defined(EMBEDDED_LIBRARY) && !defined(HAVE_EMBEDDED_PRIVILEGE_CONTROL)
  1148. #define NO_EMBEDDED_ACCESS_CHECKS
  1149. #endif
  1150. #endif /* my_global_h */