my_global.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  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; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. /* This is the include file that should be included 'first' in every C file. */
  13. #ifndef _global_h
  14. #define _global_h
  15. /*
  16. InnoDB depends on some MySQL internals which other plugins should not
  17. need. This is because of InnoDB's foreign key support, "safe" binlog
  18. truncation, and other similar legacy features.
  19. We define accessors for these internals unconditionally, but do not
  20. expose them in mysql/plugin.h. They are declared in ha_innodb.h for
  21. InnoDB's use.
  22. */
  23. #define INNODB_COMPATIBILITY_HOOKS
  24. #ifdef __CYGWIN__
  25. /* We use a Unix API, so pretend it's not Windows */
  26. #undef WIN
  27. #undef WIN32
  28. #undef _WIN
  29. #undef _WIN32
  30. #undef _WIN64
  31. #undef __WIN__
  32. #undef __WIN32__
  33. #define HAVE_ERRNO_AS_DEFINE
  34. #endif /* __CYGWIN__ */
  35. #if defined(__QNXNTO__) && !defined(FD_SETSIZE)
  36. #define FD_SETSIZE 1024 /* Max number of file descriptor bits in
  37. fd_set, used when calling 'select'
  38. Must be defined before including
  39. "sys/select.h" and "sys/time.h"
  40. */
  41. #endif
  42. /* to make command line shorter we'll define USE_PRAGMA_INTERFACE here */
  43. #ifdef USE_PRAGMA_IMPLEMENTATION
  44. #define USE_PRAGMA_INTERFACE
  45. #endif
  46. #if defined(i386) && !defined(__i386__)
  47. #define __i386__
  48. #endif
  49. /* Macros to make switching between C and C++ mode easier */
  50. #ifdef __cplusplus
  51. #define C_MODE_START extern "C" {
  52. #define C_MODE_END }
  53. #else
  54. #define C_MODE_START
  55. #define C_MODE_END
  56. #endif
  57. #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
  58. #include <config-win.h>
  59. #elif defined(__NETWARE__)
  60. #include <my_config.h>
  61. #include <config-netware.h>
  62. #if defined(__cplusplus) && defined(inline)
  63. #undef inline /* fix configure problem */
  64. #endif
  65. #else
  66. #include <my_config.h>
  67. #if defined(__cplusplus) && defined(inline)
  68. #undef inline /* fix configure problem */
  69. #endif
  70. #endif /* _WIN32... */
  71. /* Make it easier to add conditionl code for windows */
  72. #ifdef __WIN__
  73. #define IF_WIN(A,B) (A)
  74. #else
  75. #define IF_WIN(A,B) (B)
  76. #endif
  77. #ifndef EMBEDDED_LIBRARY
  78. #ifdef WITH_NDB_BINLOG
  79. #define HAVE_NDB_BINLOG 1
  80. #endif
  81. #endif /* !EMBEDDED_LIBRARY */
  82. #ifndef EMBEDDED_LIBRARY
  83. #define HAVE_REPLICATION
  84. #define HAVE_EXTERNAL_CLIENT
  85. #endif
  86. /* Some defines to avoid ifdefs in the code */
  87. #ifndef NETWARE_YIELD
  88. #define NETWARE_YIELD
  89. #define NETWARE_SET_SCREEN_MODE(A)
  90. #endif
  91. /* Workaround for _LARGE_FILES and _LARGE_FILE_API incompatibility on AIX */
  92. #if defined(_AIX) && defined(_LARGE_FILE_API)
  93. #undef _LARGE_FILE_API
  94. #endif
  95. /*
  96. The macros below are used to allow build of Universal/fat binaries of
  97. MySQL and MySQL applications under darwin.
  98. */
  99. #if defined(__APPLE__) && defined(__MACH__)
  100. # undef SIZEOF_CHARP
  101. # undef SIZEOF_SHORT
  102. # undef SIZEOF_INT
  103. # undef SIZEOF_LONG
  104. # undef SIZEOF_LONG_LONG
  105. # undef SIZEOF_OFF_T
  106. # undef WORDS_BIGENDIAN
  107. # define SIZEOF_SHORT 2
  108. # define SIZEOF_INT 4
  109. # define SIZEOF_LONG_LONG 8
  110. # define SIZEOF_OFF_T 8
  111. # if defined(__i386__) || defined(__ppc__)
  112. # define SIZEOF_CHARP 4
  113. # define SIZEOF_LONG 4
  114. # elif defined(__x86_64__) || defined(__ppc64__)
  115. # define SIZEOF_CHARP 8
  116. # define SIZEOF_LONG 8
  117. # else
  118. # error Building FAT binary for an unknown architecture.
  119. # endif
  120. # if defined(__ppc__) || defined(__ppc64__)
  121. # define WORDS_BIGENDIAN
  122. # endif
  123. #endif /* defined(__APPLE__) && defined(__MACH__) */
  124. /*
  125. The macros below are borrowed from include/linux/compiler.h in the
  126. Linux kernel. Use them to indicate the likelyhood of the truthfulness
  127. of a condition. This serves two purposes - newer versions of gcc will be
  128. able to optimize for branch predication, which could yield siginficant
  129. performance gains in frequently executed sections of the code, and the
  130. other reason to use them is for documentation
  131. */
  132. #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
  133. #define __builtin_expect(x, expected_value) (x)
  134. #endif
  135. #define likely(x) __builtin_expect((x),1)
  136. #define unlikely(x) __builtin_expect((x),0)
  137. /*
  138. The macros below are useful in optimising places where it has been
  139. discovered that cache misses stall the process and where a prefetch
  140. of the cache line can improve matters. This is available in GCC 3.1.1
  141. and later versions.
  142. PREFETCH_READ says that addr is going to be used for reading and that
  143. it is to be kept in caches if possible for a while
  144. PREFETCH_WRITE also says that the item to be cached is likely to be
  145. updated.
  146. The *LOCALITY scripts are also available for experimentation purposes
  147. mostly and should only be used if they are verified to improve matters.
  148. For more input see GCC manual (available in GCC 3.1.1 and later)
  149. */
  150. #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
  151. #define PREFETCH_READ(addr) __builtin_prefetch(addr, 0, 3)
  152. #define PREFETCH_WRITE(addr) \
  153. __builtin_prefetch(addr, 1, 3)
  154. #define PREFETCH_READ_LOCALITY(addr, locality) \
  155. __builtin_prefetch(addr, 0, locality)
  156. #define PREFETCH_WRITE_LOCALITY(addr, locality) \
  157. __builtin_prefetch(addr, 1, locality)
  158. #else
  159. #define PREFETCH_READ(addr)
  160. #define PREFETCH_READ_LOCALITY(addr, locality)
  161. #define PREFETCH_WRITE(addr)
  162. #define PREFETCH_WRITE_LOCALITY(addr, locality)
  163. #endif
  164. /*
  165. The following macro is used to ensure that code often used in most
  166. SQL statements and definitely for parts of the SQL processing are
  167. kept in a code segment by itself. This has the advantage that the
  168. risk of common code being overlapping in caches of the CPU is less.
  169. This can be a cause of big performance problems.
  170. Routines should be put in this category with care and when they are
  171. put there one should also strive to make as much of the error handling
  172. as possible (or uncommon code of the routine) to execute in a
  173. separate method to avoid moving to much code to this code segment.
  174. It is very easy to use, simply add HOT_METHOD at the end of the
  175. function declaration.
  176. For more input see GCC manual (available in GCC 2.95 and later)
  177. */
  178. #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
  179. #define HOT_METHOD \
  180. __attribute__ ((section ("hot_code_section")))
  181. #else
  182. #define HOT_METHOD
  183. #endif
  184. /*
  185. The following macro is used to ensure that popular global variables
  186. are located next to each other to avoid that they contend for the
  187. same cache lines.
  188. It is very easy to use, simply add HOT_DATA at the end of the declaration
  189. of the variable, the variable must be initialised because of the way
  190. that linker works so a declaration using HOT_DATA should look like:
  191. uint global_hot_data HOT_DATA = 0;
  192. For more input see GCC manual (available in GCC 2.95 and later)
  193. */
  194. #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
  195. #define HOT_DATA \
  196. __attribute__ ((section ("hot_data_section")))
  197. #else
  198. #define HOT_DATA
  199. #endif
  200. /*
  201. now let's figure out if inline functions are supported
  202. autoconf defines 'inline' to be empty, if not
  203. */
  204. #define inline_test_1(X) X ## 1
  205. #define inline_test_2(X) inline_test_1(X)
  206. #if inline_test_2(inline) != 1
  207. #define HAVE_INLINE
  208. #endif
  209. #undef inline_test_2
  210. #undef inline_test_1
  211. /* helper macro for "instantiating" inline functions */
  212. #define STATIC_INLINE static inline
  213. /*
  214. The following macros are used to control inlining a bit more than
  215. usual. These macros are used to ensure that inlining always or
  216. never occurs (independent of compilation mode).
  217. For more input see GCC manual (available in GCC 3.1.1 and later)
  218. */
  219. #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
  220. #define ALWAYS_INLINE __attribute__ ((always_inline))
  221. #define NEVER_INLINE __attribute__ ((noinline))
  222. #else
  223. #define ALWAYS_INLINE
  224. #define NEVER_INLINE
  225. #endif
  226. /* Fix problem with S_ISLNK() on Linux */
  227. #if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
  228. #undef _GNU_SOURCE
  229. #define _GNU_SOURCE 1
  230. #endif
  231. /*
  232. Temporary solution to solve bug#7156. Include "sys/types.h" before
  233. the thread headers, else the function madvise() will not be defined
  234. */
  235. #if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
  236. #include <sys/types.h>
  237. #endif
  238. /* The client defines this to avoid all thread code */
  239. #if defined(MYSQL_CLIENT_NO_THREADS) || defined(UNDEF_THREADS_HACK)
  240. #undef THREAD
  241. #undef HAVE_LINUXTHREADS
  242. #undef HAVE_NPTL
  243. #endif
  244. #ifdef HAVE_THREADS_WITHOUT_SOCKETS
  245. /* MIT pthreads does not work with unix sockets */
  246. #undef HAVE_SYS_UN_H
  247. #endif
  248. #define __EXTENSIONS__ 1 /* We want some extension */
  249. #ifndef __STDC_EXT__
  250. #define __STDC_EXT__ 1 /* To get large file support on hpux */
  251. #endif
  252. /*
  253. Solaris 9 include file <sys/feature_tests.h> refers to X/Open document
  254. System Interfaces and Headers, Issue 5
  255. saying we should define _XOPEN_SOURCE=500 to get POSIX.1c prototypes,
  256. but apparently other systems (namely FreeBSD) don't agree.
  257. On a newer Solaris 10, the above file recognizes also _XOPEN_SOURCE=600.
  258. Furthermore, it tests that if a program requires older standard
  259. (_XOPEN_SOURCE<600 or _POSIX_C_SOURCE<200112L) it cannot be
  260. run on a new compiler (that defines _STDC_C99) and issues an #error.
  261. It's also an #error if a program requires new standard (_XOPEN_SOURCE=600
  262. or _POSIX_C_SOURCE=200112L) and a compiler does not define _STDC_C99.
  263. To add more to this mess, Sun Studio C compiler defines _STDC_C99 while
  264. C++ compiler does not!
  265. So, in a desperate attempt to get correct prototypes for both
  266. C and C++ code, we define either _XOPEN_SOURCE=600 or _XOPEN_SOURCE=500
  267. depending on the compiler's announced C standard support.
  268. Cleaner solutions are welcome.
  269. */
  270. #ifdef __sun
  271. #if __STDC_VERSION__ - 0 >= 199901L
  272. #define _XOPEN_SOURCE 600
  273. #else
  274. #define _XOPEN_SOURCE 500
  275. #endif
  276. #endif
  277. #if defined(THREAD) && !defined(__WIN__)
  278. #ifndef _POSIX_PTHREAD_SEMANTICS
  279. #define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
  280. #endif
  281. #if !defined(SCO)
  282. #define _REENTRANT 1 /* Some thread libraries require this */
  283. #endif
  284. #if !defined(_THREAD_SAFE) && !defined(_AIX)
  285. #define _THREAD_SAFE /* Required for OSF1 */
  286. #endif
  287. #if defined(HPUX10) || defined(HPUX11)
  288. C_MODE_START /* HPUX needs this, signal.h bug */
  289. #include <pthread.h>
  290. C_MODE_END
  291. #else
  292. #include <pthread.h> /* AIX must have this included first */
  293. #endif
  294. #if !defined(SCO) && !defined(_REENTRANT)
  295. #define _REENTRANT 1 /* Threads requires reentrant code */
  296. #endif
  297. #endif /* THREAD */
  298. /* Go around some bugs in different OS and compilers */
  299. #ifdef _AIX /* By soren@t.dk */
  300. #define _H_STRINGS
  301. #define _SYS_STREAM_H
  302. /* #define _AIX32_CURSES */ /* XXX: this breaks AIX 4.3.3 (others?). */
  303. #define ulonglong2double(A) my_ulonglong2double(A)
  304. #define my_off_t2double(A) my_ulonglong2double(A)
  305. C_MODE_START
  306. double my_ulonglong2double(unsigned long long A);
  307. C_MODE_END
  308. #endif /* _AIX */
  309. #ifdef HAVE_BROKEN_SNPRINTF /* HPUX 10.20 don't have this defined */
  310. #undef HAVE_SNPRINTF
  311. #endif
  312. #ifdef HAVE_BROKEN_PREAD
  313. /*
  314. pread()/pwrite() are not 64 bit safe on HP-UX 11.0 without
  315. installing the kernel patch PHKL_20349 or greater
  316. */
  317. #undef HAVE_PREAD
  318. #undef HAVE_PWRITE
  319. #endif
  320. #if defined(HAVE_BROKEN_INLINE) && !defined(__cplusplus)
  321. #undef inline
  322. #define inline
  323. #endif
  324. #ifdef UNDEF_HAVE_GETHOSTBYNAME_R /* For OSF4.x */
  325. #undef HAVE_GETHOSTBYNAME_R
  326. #endif
  327. #ifdef UNDEF_HAVE_INITGROUPS /* For AIX 4.3 */
  328. #undef HAVE_INITGROUPS
  329. #endif
  330. /* gcc/egcs issues */
  331. #if defined(__GNUC) && defined(__EXCEPTIONS)
  332. #error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
  333. #endif
  334. /* Fix a bug in gcc 2.8.0 on IRIX 6.2 */
  335. #if SIZEOF_LONG == 4 && defined(__LONG_MAX__) && (__GNUC__ == 2 && __GNUC_MINOR__ == 8)
  336. #undef __LONG_MAX__ /* Is a longlong value in gcc 2.8.0 ??? */
  337. #define __LONG_MAX__ 2147483647
  338. #endif
  339. /* egcs 1.1.2 has a problem with memcpy on Alpha */
  340. #if defined(__GNUC__) && defined(__alpha__) && ! (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
  341. #define BAD_MEMCPY
  342. #endif
  343. #if defined(_lint) && !defined(lint)
  344. #define lint
  345. #endif
  346. #if SIZEOF_LONG_LONG > 4 && !defined(_LONG_LONG)
  347. #define _LONG_LONG 1 /* For AIX string library */
  348. #endif
  349. #ifndef stdin
  350. #include <stdio.h>
  351. #endif
  352. #ifdef HAVE_STDLIB_H
  353. #include <stdlib.h>
  354. #endif
  355. #ifdef HAVE_STDDEF_H
  356. #include <stddef.h>
  357. #endif
  358. #include <math.h>
  359. #ifdef HAVE_LIMITS_H
  360. #include <limits.h>
  361. #endif
  362. #ifdef HAVE_FLOAT_H
  363. #include <float.h>
  364. #endif
  365. #ifdef HAVE_FENV_H
  366. #include <fenv.h> /* For fesetround() */
  367. #endif
  368. #ifdef HAVE_SYS_TYPES_H
  369. #include <sys/types.h>
  370. #endif
  371. #ifdef HAVE_FCNTL_H
  372. #include <fcntl.h>
  373. #endif
  374. #ifdef HAVE_SYS_TIMEB_H
  375. #include <sys/timeb.h> /* Avoid warnings on SCO */
  376. #endif
  377. #if TIME_WITH_SYS_TIME
  378. # include <sys/time.h>
  379. # include <time.h>
  380. #else
  381. # if HAVE_SYS_TIME_H
  382. # include <sys/time.h>
  383. # else
  384. # include <time.h>
  385. # endif
  386. #endif /* TIME_WITH_SYS_TIME */
  387. #ifdef HAVE_UNISTD_H
  388. #include <unistd.h>
  389. #endif
  390. #if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
  391. #undef HAVE_ALLOCA
  392. #undef HAVE_ALLOCA_H
  393. #endif
  394. #ifdef HAVE_ALLOCA_H
  395. #include <alloca.h>
  396. #endif
  397. #include <errno.h> /* Recommended by debian */
  398. /* We need the following to go around a problem with openssl on solaris */
  399. #if defined(HAVE_CRYPT_H)
  400. #include <crypt.h>
  401. #endif
  402. /*
  403. A lot of our programs uses asserts, so better to always include it
  404. This also fixes a problem when people uses DBUG_ASSERT without including
  405. assert.h
  406. */
  407. #include <assert.h>
  408. /* an assert that works at compile-time. only for constant expression */
  409. #ifndef __GNUC__
  410. #define compile_time_assert(X) do { } while(0)
  411. #else
  412. #define compile_time_assert(X) \
  413. do \
  414. { \
  415. char compile_time_assert[(X) ? 1 : -1] \
  416. __attribute__ ((unused)); \
  417. } while(0)
  418. #endif
  419. /* Go around some bugs in different OS and compilers */
  420. #if defined (HPUX11) && defined(_LARGEFILE_SOURCE)
  421. #define _LARGEFILE64_SOURCE
  422. #endif
  423. #if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H)
  424. #include <sys/stream.h> /* HPUX 10.20 defines ulong here. UGLY !!! */
  425. #define HAVE_ULONG
  426. #endif
  427. #if defined(HPUX10) && defined(_LARGEFILE64_SOURCE) && defined(THREAD)
  428. /* Fix bug in setrlimit */
  429. #undef setrlimit
  430. #define setrlimit cma_setrlimit64
  431. #endif
  432. /* Declare madvise where it is not declared for C++, like Solaris */
  433. #if HAVE_MADVISE && !HAVE_DECL_MADVISE && defined(__cplusplus)
  434. extern "C" int madvise(void *addr, size_t len, int behav);
  435. #endif
  436. #ifdef __QNXNTO__
  437. /* This has to be after include limits.h */
  438. #define HAVE_ERRNO_AS_DEFINE
  439. #define HAVE_FCNTL_LOCK
  440. #undef HAVE_FINITE
  441. #undef LONGLONG_MIN /* These get wrongly defined in QNX 6.2 */
  442. #undef LONGLONG_MAX /* standard system library 'limits.h' */
  443. #ifdef __cplusplus
  444. #ifndef HAVE_RINT
  445. #define HAVE_RINT
  446. #endif /* rint() and isnan() functions are not */
  447. #define rint(a) std::rint(a) /* visible in C++ scope due to an error */
  448. #define isnan(a) std::isnan(a) /* in the usr/include/math.h on QNX */
  449. #endif
  450. #endif
  451. /* We can not live without the following defines */
  452. #define USE_MYFUNC 1 /* Must use syscall indirection */
  453. #define MASTER 1 /* Compile without unireg */
  454. #define ENGLISH 1 /* Messages in English */
  455. #define POSIX_MISTAKE 1 /* regexp: Fix stupid spec error */
  456. #define USE_REGEX 1 /* We want the use the regex library */
  457. /* Do not define for ultra sparcs */
  458. #define USE_BMOVE512 1 /* Use this unless system bmove is faster */
  459. #define QUOTE_ARG(x) #x /* Quote argument (before cpp) */
  460. #define STRINGIFY_ARG(x) QUOTE_ARG(x) /* Quote argument, after cpp */
  461. /* Paranoid settings. Define I_AM_PARANOID if you are paranoid */
  462. #ifdef I_AM_PARANOID
  463. #define DONT_ALLOW_USER_CHANGE 1
  464. #define DONT_USE_MYSQL_PWD 1
  465. #endif
  466. /* Does the system remember a signal handler after a signal ? */
  467. #ifndef HAVE_BSD_SIGNALS
  468. #define DONT_REMEMBER_SIGNAL
  469. #endif
  470. /* Define void to stop lint from generating "null effekt" comments */
  471. #ifndef DONT_DEFINE_VOID
  472. #ifdef _lint
  473. int __void__;
  474. #define VOID(X) (__void__ = (int) (X))
  475. #else
  476. #undef VOID
  477. #define VOID(X) (X)
  478. #endif
  479. #endif /* DONT_DEFINE_VOID */
  480. #if defined(_lint) || defined(FORCE_INIT_OF_VARS)
  481. #define LINT_INIT(var) var=0 /* No uninitialize-warning */
  482. #else
  483. #define LINT_INIT(var)
  484. #endif
  485. /*
  486. Suppress uninitialized variable warning without generating code.
  487. The _cplusplus is a temporary workaround for C++ code pending a fix
  488. for a g++ bug (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34772).
  489. */
  490. #if defined(_lint) || defined(FORCE_INIT_OF_VARS) || defined(__cplusplus) || \
  491. !defined(__GNUC__)
  492. #define UNINIT_VAR(x) x= 0
  493. #else
  494. #define UNINIT_VAR(x) x= x
  495. #endif
  496. /* Define some useful general macros */
  497. #if !defined(max)
  498. #define max(a, b) ((a) > (b) ? (a) : (b))
  499. #define min(a, b) ((a) < (b) ? (a) : (b))
  500. #endif
  501. #if !defined(HAVE_UINT)
  502. #undef HAVE_UINT
  503. #define HAVE_UINT
  504. typedef unsigned int uint;
  505. typedef unsigned short ushort;
  506. #endif
  507. #define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
  508. #define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
  509. #define swap_variables(t, a, b) { t dummy; dummy= a; a= b; b= dummy; }
  510. #define test(a) ((a) ? 1 : 0)
  511. #define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
  512. #define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
  513. #define test_all_bits(a,b) (((a) & (b)) == (b))
  514. #define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
  515. #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
  516. /* Define some general constants */
  517. #ifndef TRUE
  518. #define TRUE (1) /* Logical true */
  519. #define FALSE (0) /* Logical false */
  520. #endif
  521. #if defined(__GNUC__)
  522. #define function_volatile volatile
  523. #define my_reinterpret_cast(A) reinterpret_cast<A>
  524. #define my_const_cast(A) const_cast<A>
  525. # ifndef GCC_VERSION
  526. # define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
  527. # endif
  528. #elif !defined(my_reinterpret_cast)
  529. #define my_reinterpret_cast(A) (A)
  530. #define my_const_cast(A) (A)
  531. #endif
  532. #include <my_attribute.h>
  533. /*
  534. Wen using the embedded library, users might run into link problems,
  535. duplicate declaration of __cxa_pure_virtual, solved by declaring it a
  536. weak symbol.
  537. */
  538. #if defined(USE_MYSYS_NEW) && ! defined(DONT_DECLARE_CXA_PURE_VIRTUAL)
  539. C_MODE_START
  540. int __cxa_pure_virtual () __attribute__ ((weak));
  541. C_MODE_END
  542. #endif
  543. /* From old s-system.h */
  544. /*
  545. Support macros for non ansi & other old compilers. Since such
  546. things are no longer supported we do nothing. We keep then since
  547. some of our code may still be needed to upgrade old customers.
  548. */
  549. #define _VARARGS(X) X
  550. #define _STATIC_VARARGS(X) X
  551. /* The DBUG_ON flag always takes precedence over default DBUG_OFF */
  552. #if defined(DBUG_ON) && defined(DBUG_OFF)
  553. #undef DBUG_OFF
  554. #endif
  555. /* We might be forced to turn debug off, if not turned off already */
  556. #if (defined(FORCE_DBUG_OFF) || defined(_lint)) && !defined(DBUG_OFF)
  557. # define DBUG_OFF
  558. # ifdef DBUG_ON
  559. # undef DBUG_ON
  560. # endif
  561. #endif
  562. #include <my_dbug.h>
  563. #define MIN_ARRAY_SIZE 0 /* Zero or One. Gcc allows zero*/
  564. #define ASCII_BITS_USED 8 /* Bit char used */
  565. #define NEAR_F /* No near function handling */
  566. /* Some types that is different between systems */
  567. typedef int File; /* File descriptor */
  568. #ifndef Socket_defined
  569. typedef int my_socket; /* File descriptor for sockets */
  570. #define INVALID_SOCKET -1
  571. #endif
  572. /* Type for fuctions that handles signals */
  573. #define sig_handler RETSIGTYPE
  574. C_MODE_START
  575. typedef void (*sig_return)();/* Returns type from signal */
  576. C_MODE_END
  577. #if defined(__GNUC__) && !defined(_lint)
  578. typedef char pchar; /* Mixed prototypes can take char */
  579. typedef char puchar; /* Mixed prototypes can take char */
  580. typedef char pbool; /* Mixed prototypes can take char */
  581. typedef short pshort; /* Mixed prototypes can take short int */
  582. typedef float pfloat; /* Mixed prototypes can take float */
  583. #else
  584. typedef int pchar; /* Mixed prototypes can't take char */
  585. typedef uint puchar; /* Mixed prototypes can't take char */
  586. typedef int pbool; /* Mixed prototypes can't take char */
  587. typedef int pshort; /* Mixed prototypes can't take short int */
  588. typedef double pfloat; /* Mixed prototypes can't take float */
  589. #endif
  590. C_MODE_START
  591. typedef int (*qsort_cmp)(const void *,const void *);
  592. typedef int (*qsort_cmp2)(void*, const void *,const void *);
  593. C_MODE_END
  594. #define qsort_t RETQSORTTYPE /* Broken GCC cant handle typedef !!!! */
  595. #ifdef HAVE_SYS_SOCKET_H
  596. #include <sys/socket.h>
  597. #endif
  598. typedef SOCKET_SIZE_TYPE size_socket;
  599. #ifndef SOCKOPT_OPTLEN_TYPE
  600. #define SOCKOPT_OPTLEN_TYPE size_socket
  601. #endif
  602. /* file create flags */
  603. #ifndef O_SHARE /* Probably not windows */
  604. #define O_SHARE 0 /* Flag to my_open for shared files */
  605. #ifndef O_BINARY
  606. #define O_BINARY 0 /* Flag to my_open for binary files */
  607. #endif
  608. #ifndef FILE_BINARY
  609. #define FILE_BINARY O_BINARY /* Flag to my_fopen for binary streams */
  610. #endif
  611. #ifdef HAVE_FCNTL
  612. #define HAVE_FCNTL_LOCK
  613. #define F_TO_EOF 0L /* Param to lockf() to lock rest of file */
  614. #endif
  615. #endif /* O_SHARE */
  616. #ifndef O_TEMPORARY
  617. #define O_TEMPORARY 0
  618. #endif
  619. #ifndef O_SHORT_LIVED
  620. #define O_SHORT_LIVED 0
  621. #endif
  622. #ifndef O_NOFOLLOW
  623. #define O_NOFOLLOW 0
  624. #endif
  625. /* additional file share flags for win32 */
  626. #ifdef __WIN__
  627. #define _SH_DENYRWD 0x110 /* deny read/write mode & delete */
  628. #define _SH_DENYWRD 0x120 /* deny write mode & delete */
  629. #define _SH_DENYRDD 0x130 /* deny read mode & delete */
  630. #define _SH_DENYDEL 0x140 /* deny delete only */
  631. #endif /* __WIN__ */
  632. /* #define USE_RECORD_LOCK */
  633. /* Unsigned types supported by the compiler */
  634. #define UNSINT8 /* unsigned int8 (char) */
  635. #define UNSINT16 /* unsigned int16 */
  636. #define UNSINT32 /* unsigned int32 */
  637. /* General constants */
  638. #define FN_LEN 256 /* Max file name len */
  639. #define FN_HEADLEN 253 /* Max length of filepart of file name */
  640. #define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */
  641. #define FN_REFLEN 512 /* Max length of full path-name */
  642. #define FN_EXTCHAR '.'
  643. #define FN_HOMELIB '~' /* ~/ is used as abbrev for home dir */
  644. #define FN_CURLIB '.' /* ./ is used as abbrev for current dir */
  645. #define FN_PARENTDIR ".." /* Parent directory; Must be a string */
  646. #ifndef FN_LIBCHAR
  647. #define FN_LIBCHAR '/'
  648. #define FN_ROOTDIR "/"
  649. #endif
  650. #define MY_NFILE 64 /* This is only used to save filenames */
  651. #ifndef OS_FILE_LIMIT
  652. #define OS_FILE_LIMIT 65535
  653. #endif
  654. /* #define EXT_IN_LIBNAME */
  655. /* #define FN_NO_CASE_SENCE */
  656. /* #define FN_UPPER_CASE TRUE */
  657. /*
  658. Io buffer size; Must be a power of 2 and a multiple of 512. May be
  659. smaller what the disk page size. This influences the speed of the
  660. isam btree library. eg to big to slow.
  661. */
  662. #define IO_SIZE 4096
  663. /*
  664. How much overhead does malloc have. The code often allocates
  665. something like 1024-MALLOC_OVERHEAD bytes
  666. */
  667. #ifdef SAFEMALLOC
  668. #define MALLOC_OVERHEAD (8+24+4)
  669. #else
  670. #define MALLOC_OVERHEAD 8
  671. #endif
  672. /* get memory in huncs */
  673. #define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD)
  674. /* Typical record cash */
  675. #define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD)
  676. /* Typical key cash */
  677. #define KEY_CACHE_SIZE (uint) (8*1024*1024-MALLOC_OVERHEAD)
  678. /* Default size of a key cache block */
  679. #define KEY_CACHE_BLOCK_SIZE (uint) 1024
  680. /* Some things that this system doesn't have */
  681. #define NO_HASH /* Not needed anymore */
  682. #ifdef __WIN__
  683. #define NO_DIR_LIBRARY /* Not standar dir-library */
  684. #define USE_MY_STAT_STRUCT /* For my_lib */
  685. #endif
  686. /* Some defines of functions for portability */
  687. #undef remove /* Crashes MySQL on SCO 5.0.0 */
  688. #ifndef __WIN__
  689. #define closesocket(A) close(A)
  690. #ifndef ulonglong2double
  691. #define ulonglong2double(A) ((double) (ulonglong) (A))
  692. #define my_off_t2double(A) ((double) (my_off_t) (A))
  693. #endif
  694. #ifndef double2ulonglong
  695. #define double2ulonglong(A) ((ulonglong) (double) (A))
  696. #endif
  697. #endif
  698. #ifndef offsetof
  699. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  700. #endif
  701. #define ulong_to_double(X) ((double) (ulong) (X))
  702. #define SET_STACK_SIZE(X) /* Not needed on real machines */
  703. #ifndef STACK_DIRECTION
  704. #error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
  705. #endif
  706. #if !defined(HAVE_STRTOK_R)
  707. #define strtok_r(A,B,C) strtok((A),(B))
  708. #endif
  709. /* This is from the old m-machine.h file */
  710. #if SIZEOF_LONG_LONG > 4
  711. #define HAVE_LONG_LONG 1
  712. #endif
  713. /*
  714. Some pre-ANSI-C99 systems like AIX 5.1 and Linux/GCC 2.95 define
  715. ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined.
  716. Also on Windows we define these constants by hand in config-win.h.
  717. */
  718. #if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
  719. #define LONGLONG_MIN ((long long) 0x8000000000000000LL)
  720. #define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL)
  721. #endif
  722. #if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
  723. /* First check for ANSI C99 definition: */
  724. #ifdef ULLONG_MAX
  725. #define ULONGLONG_MAX ULLONG_MAX
  726. #else
  727. #define ULONGLONG_MAX ((unsigned long long)(~0ULL))
  728. #endif
  729. #endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/
  730. #define INT_MIN32 (~0x7FFFFFFFL)
  731. #define INT_MAX32 0x7FFFFFFFL
  732. #define UINT_MAX32 0xFFFFFFFFL
  733. #define INT_MIN24 (~0x007FFFFF)
  734. #define INT_MAX24 0x007FFFFF
  735. #define UINT_MAX24 0x00FFFFFF
  736. #define INT_MIN16 (~0x7FFF)
  737. #define INT_MAX16 0x7FFF
  738. #define UINT_MAX16 0xFFFF
  739. #define INT_MIN8 (~0x7F)
  740. #define INT_MAX8 0x7F
  741. #define UINT_MAX8 0xFF
  742. /* From limits.h instead */
  743. #ifndef DBL_MIN
  744. #define DBL_MIN 4.94065645841246544e-324
  745. #define FLT_MIN ((float)1.40129846432481707e-45)
  746. #endif
  747. #ifndef DBL_MAX
  748. #define DBL_MAX 1.79769313486231470e+308
  749. #define FLT_MAX ((float)3.40282346638528860e+38)
  750. #endif
  751. #ifndef SIZE_T_MAX
  752. #define SIZE_T_MAX (~((size_t) 0))
  753. #endif
  754. #ifndef isfinite
  755. #ifdef HAVE_FINITE
  756. #define isfinite(x) finite(x)
  757. #else
  758. #define finite(x) (1.0 / fabs(x) > 0.0)
  759. #endif /* HAVE_FINITE */
  760. #endif /* isfinite */
  761. #ifndef HAVE_ISNAN
  762. #define isnan(x) ((x) != (x))
  763. #endif
  764. #ifdef HAVE_ISINF
  765. /* Check if C compiler is affected by GCC bug #39228 */
  766. #if !defined(__cplusplus) && defined(HAVE_BROKEN_ISINF)
  767. /* Force store/reload of the argument to/from a 64-bit double */
  768. static inline double my_isinf(double x)
  769. {
  770. volatile double t= x;
  771. return isinf(t);
  772. }
  773. #else
  774. /* System-provided isinf() is available and safe to use */
  775. #define my_isinf(X) isinf(X)
  776. #endif
  777. #else /* !HAVE_ISINF */
  778. #define my_isinf(X) (!finite(X) && !isnan(X))
  779. #endif
  780. /* Define missing math constants. */
  781. #ifndef M_PI
  782. #define M_PI 3.14159265358979323846
  783. #endif
  784. #ifndef M_E
  785. #define M_E 2.7182818284590452354
  786. #endif
  787. #ifndef M_LN2
  788. #define M_LN2 0.69314718055994530942
  789. #endif
  790. /*
  791. Max size that must be added to a so that we know Size to make
  792. adressable obj.
  793. */
  794. #if SIZEOF_CHARP == 4
  795. typedef long my_ptrdiff_t;
  796. #else
  797. typedef long long my_ptrdiff_t;
  798. #endif
  799. #define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
  800. #define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
  801. /* Size to make adressable obj. */
  802. #define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
  803. /* Offset of field f in structure t */
  804. #define OFFSET(t, f) ((size_t)(char *)&((t *)0)->f)
  805. #define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
  806. #define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
  807. #define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
  808. #define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
  809. /*
  810. Custom version of standard offsetof() macro which can be used to get
  811. offsets of members in class for non-POD types (according to the current
  812. version of C++ standard offsetof() macro can't be used in such cases and
  813. attempt to do so causes warnings to be emitted, OTOH in many cases it is
  814. still OK to assume that all instances of the class has the same offsets
  815. for the same members).
  816. This is temporary solution which should be removed once File_parser class
  817. and related routines are refactored.
  818. */
  819. #define my_offsetof(TYPE, MEMBER) \
  820. ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
  821. #define NullS (char *) 0
  822. /* Nowdays we do not support MessyDos */
  823. #ifndef NEAR
  824. #define NEAR /* Who needs segments ? */
  825. #define FAR /* On a good machine */
  826. #ifndef HUGE_PTR
  827. #define HUGE_PTR
  828. #endif
  829. #endif
  830. #if defined(__IBMC__) || defined(__IBMCPP__)
  831. /* This was _System _Export but caused a lot of warnings on _AIX43 */
  832. #define STDCALL
  833. #elif !defined( STDCALL)
  834. #define STDCALL
  835. #endif
  836. /* Typdefs for easyier portability */
  837. #ifndef HAVE_UCHAR
  838. typedef unsigned char uchar; /* Short for unsigned char */
  839. #endif
  840. #ifndef HAVE_INT8
  841. typedef signed char int8; /* Signed integer >= 8 bits */
  842. #endif
  843. #ifndef HAVE_UINT8
  844. typedef unsigned char uint8; /* Unsigned integer >= 8 bits */
  845. #endif
  846. #ifndef HAVE_INT16
  847. typedef short int16;
  848. #endif
  849. #ifndef HAVE_UINT16
  850. typedef unsigned short uint16;
  851. #endif
  852. #if SIZEOF_INT == 4
  853. #ifndef HAVE_INT32
  854. typedef int int32;
  855. #endif
  856. #ifndef HAVE_UINT32
  857. typedef unsigned int uint32;
  858. #endif
  859. #elif SIZEOF_LONG == 4
  860. #ifndef HAVE_INT32
  861. typedef long int32;
  862. #endif
  863. #ifndef HAVE_UINT32
  864. typedef unsigned long uint32;
  865. #endif
  866. #else
  867. #error Neither int or long is of 4 bytes width
  868. #endif
  869. #if !defined(HAVE_ULONG) && !defined(__USE_MISC)
  870. typedef unsigned long ulong; /* Short for unsigned long */
  871. #endif
  872. #ifndef longlong_defined
  873. /*
  874. Using [unsigned] long long is preferable as [u]longlong because we use
  875. [unsigned] long long unconditionally in many places,
  876. for example in constants with [U]LL suffix.
  877. */
  878. #if defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 8
  879. typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
  880. typedef long long int longlong;
  881. #else
  882. typedef unsigned long ulonglong; /* ulong or unsigned long long */
  883. typedef long longlong;
  884. #endif
  885. #endif
  886. #ifndef HAVE_INT64
  887. typedef longlong int64;
  888. #endif
  889. #ifndef HAVE_UINT64
  890. typedef ulonglong uint64;
  891. #endif
  892. #if defined(NO_CLIENT_LONG_LONG)
  893. typedef unsigned long my_ulonglong;
  894. #elif defined (__WIN__)
  895. typedef unsigned __int64 my_ulonglong;
  896. #else
  897. typedef unsigned long long my_ulonglong;
  898. #endif
  899. #if SIZEOF_CHARP == SIZEOF_INT
  900. typedef int intptr;
  901. #elif SIZEOF_CHARP == SIZEOF_LONG
  902. typedef long intptr;
  903. #elif SIZEOF_CHARP == SIZEOF_LONG_LONG
  904. typedef long long intptr;
  905. #else
  906. #error sizeof(void *) is neither sizeof(int) nor sizeof(long) nor sizeof(long long)
  907. #endif
  908. #define MY_ERRPTR ((void*)(intptr)1)
  909. #ifdef USE_RAID
  910. /*
  911. The following is done with a if to not get problems with pre-processors
  912. with late define evaluation
  913. */
  914. #if SIZEOF_OFF_T == 4
  915. #define SYSTEM_SIZEOF_OFF_T 4
  916. #else
  917. #define SYSTEM_SIZEOF_OFF_T 8
  918. #endif
  919. #undef SIZEOF_OFF_T
  920. #define SIZEOF_OFF_T 8
  921. #else
  922. #define SYSTEM_SIZEOF_OFF_T SIZEOF_OFF_T
  923. #endif /* USE_RAID */
  924. #if SIZEOF_OFF_T > 4
  925. typedef ulonglong my_off_t;
  926. #else
  927. typedef unsigned long my_off_t;
  928. #endif
  929. #define MY_FILEPOS_ERROR (~(my_off_t) 0)
  930. #if !defined(__WIN__)
  931. typedef off_t os_off_t;
  932. #endif
  933. #if defined(__WIN__)
  934. #define socket_errno WSAGetLastError()
  935. #define SOCKET_EINTR WSAEINTR
  936. #define SOCKET_EAGAIN WSAEINPROGRESS
  937. #define SOCKET_ETIMEDOUT WSAETIMEDOUT
  938. #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
  939. #define SOCKET_EADDRINUSE WSAEADDRINUSE
  940. #define SOCKET_ENFILE ENFILE
  941. #define SOCKET_EMFILE EMFILE
  942. #else /* Unix */
  943. #define socket_errno errno
  944. #define closesocket(A) close(A)
  945. #define SOCKET_EINTR EINTR
  946. #define SOCKET_EAGAIN EAGAIN
  947. #define SOCKET_ETIMEDOUT SOCKET_EINTR
  948. #define SOCKET_EWOULDBLOCK EWOULDBLOCK
  949. #define SOCKET_EADDRINUSE EADDRINUSE
  950. #define SOCKET_ENFILE ENFILE
  951. #define SOCKET_EMFILE EMFILE
  952. #endif
  953. typedef uint8 int7; /* Most effective integer 0 <= x <= 127 */
  954. typedef short int15; /* Most effective integer 0 <= x <= 32767 */
  955. typedef int myf; /* Type of MyFlags in my_funcs */
  956. typedef char my_bool; /* Small bool */
  957. #if !defined(bool) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
  958. typedef char bool; /* Ordinary boolean values 0 1 */
  959. #endif
  960. /* Macros for converting *constants* to the right type */
  961. #define INT8(v) (int8) (v)
  962. #define INT16(v) (int16) (v)
  963. #define INT32(v) (int32) (v)
  964. #define MYF(v) (myf) (v)
  965. #ifndef LL
  966. #ifdef HAVE_LONG_LONG
  967. #define LL(A) A ## LL
  968. #else
  969. #define LL(A) A ## L
  970. #endif
  971. #endif
  972. #ifndef ULL
  973. #ifdef HAVE_LONG_LONG
  974. #define ULL(A) A ## ULL
  975. #else
  976. #define ULL(A) A ## UL
  977. #endif
  978. #endif
  979. /*
  980. Defines to make it possible to prioritize register assignments. No
  981. longer that important with modern compilers.
  982. */
  983. #ifndef USING_X
  984. #define reg1 register
  985. #define reg2 register
  986. #define reg3 register
  987. #define reg4 register
  988. #define reg5 register
  989. #define reg6 register
  990. #define reg7 register
  991. #define reg8 register
  992. #define reg9 register
  993. #define reg10 register
  994. #define reg11 register
  995. #define reg12 register
  996. #define reg13 register
  997. #define reg14 register
  998. #define reg15 register
  999. #define reg16 register
  1000. #endif
  1001. /*
  1002. Sometimes we want to make sure that the variable is not put into
  1003. a register in debugging mode so we can see its value in the core
  1004. */
  1005. #ifndef DBUG_OFF
  1006. #define dbug_volatile volatile
  1007. #else
  1008. #define dbug_volatile
  1009. #endif
  1010. /* Some helper macros */
  1011. #define YESNO(X) ((X) ? "yes" : "no")
  1012. /* Defines for time function */
  1013. #define SCALE_SEC 100
  1014. #define SCALE_USEC 10000
  1015. #define MY_HOW_OFTEN_TO_ALARM 2 /* How often we want info on screen */
  1016. #define MY_HOW_OFTEN_TO_WRITE 1000 /* How often we want info on screen */
  1017. /*
  1018. Define-funktions for reading and storing in machine independent format
  1019. (low byte first)
  1020. */
  1021. /* Optimized store functions for Intel x86 */
  1022. #if defined(__i386__) || defined(_WIN32)
  1023. #define sint2korr(A) (*((int16 *) (A)))
  1024. #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
  1025. (((uint32) 255L << 24) | \
  1026. (((uint32) (uchar) (A)[2]) << 16) |\
  1027. (((uint32) (uchar) (A)[1]) << 8) | \
  1028. ((uint32) (uchar) (A)[0])) : \
  1029. (((uint32) (uchar) (A)[2]) << 16) |\
  1030. (((uint32) (uchar) (A)[1]) << 8) | \
  1031. ((uint32) (uchar) (A)[0])))
  1032. #define sint4korr(A) (*((long *) (A)))
  1033. #define uint2korr(A) (*((uint16 *) (A)))
  1034. #if defined(HAVE_purify) && !defined(_WIN32)
  1035. #define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
  1036. (((uint32) ((uchar) (A)[1])) << 8) +\
  1037. (((uint32) ((uchar) (A)[2])) << 16))
  1038. #else
  1039. /*
  1040. ATTENTION !
  1041. Please, note, uint3korr reads 4 bytes (not 3) !
  1042. It means, that you have to provide enough allocated space !
  1043. */
  1044. #define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF)
  1045. #endif /* HAVE_purify && !_WIN32 */
  1046. #define uint4korr(A) (*((uint32 *) (A)))
  1047. #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  1048. (((uint32) ((uchar) (A)[1])) << 8) +\
  1049. (((uint32) ((uchar) (A)[2])) << 16) +\
  1050. (((uint32) ((uchar) (A)[3])) << 24)) +\
  1051. (((ulonglong) ((uchar) (A)[4])) << 32))
  1052. #define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) + \
  1053. (((uint32) ((uchar) (A)[1])) << 8) + \
  1054. (((uint32) ((uchar) (A)[2])) << 16) + \
  1055. (((uint32) ((uchar) (A)[3])) << 24)) + \
  1056. (((ulonglong) ((uchar) (A)[4])) << 32) + \
  1057. (((ulonglong) ((uchar) (A)[5])) << 40))
  1058. #define uint8korr(A) (*((ulonglong *) (A)))
  1059. #define sint8korr(A) (*((longlong *) (A)))
  1060. #define int2store(T,A) *((uint16*) (T))= (uint16) (A)
  1061. #define int3store(T,A) do { *(T)= (uchar) ((A));\
  1062. *(T+1)=(uchar) (((uint) (A) >> 8));\
  1063. *(T+2)=(uchar) (((A) >> 16)); } while (0)
  1064. #define int4store(T,A) *((long *) (T))= (long) (A)
  1065. #define int5store(T,A) do { *(T)= (uchar)((A));\
  1066. *((T)+1)=(uchar) (((A) >> 8));\
  1067. *((T)+2)=(uchar) (((A) >> 16));\
  1068. *((T)+3)=(uchar) (((A) >> 24)); \
  1069. *((T)+4)=(uchar) (((A) >> 32)); } while(0)
  1070. #define int6store(T,A) do { *(T)= (uchar)((A)); \
  1071. *((T)+1)=(uchar) (((A) >> 8)); \
  1072. *((T)+2)=(uchar) (((A) >> 16)); \
  1073. *((T)+3)=(uchar) (((A) >> 24)); \
  1074. *((T)+4)=(uchar) (((A) >> 32)); \
  1075. *((T)+5)=(uchar) (((A) >> 40)); } while(0)
  1076. #define int8store(T,A) *((ulonglong *) (T))= (ulonglong) (A)
  1077. typedef union {
  1078. double v;
  1079. long m[2];
  1080. } doubleget_union;
  1081. #define doubleget(V,M) \
  1082. do { doubleget_union _tmp; \
  1083. _tmp.m[0] = *((long*)(M)); \
  1084. _tmp.m[1] = *(((long*) (M))+1); \
  1085. (V) = _tmp.v; } while(0)
  1086. #define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
  1087. *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
  1088. } while (0)
  1089. #define float4get(V,M) do { *((float *) &(V)) = *((float*) (M)); } while(0)
  1090. #define float8get(V,M) doubleget((V),(M))
  1091. #define float4store(V,M) memcpy((uchar*) V,(uchar*) (&M),sizeof(float))
  1092. #define floatstore(T,V) memcpy((uchar*)(T), (uchar*)(&V),sizeof(float))
  1093. #define floatget(V,M) memcpy((uchar*) &V,(uchar*) (M),sizeof(float))
  1094. #define float8store(V,M) doublestore((V),(M))
  1095. #else
  1096. /*
  1097. We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
  1098. were done before)
  1099. */
  1100. #define sint2korr(A) (int16) (((int16) ((uchar) (A)[0])) +\
  1101. ((int16) ((int16) (A)[1]) << 8))
  1102. #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
  1103. (((uint32) 255L << 24) | \
  1104. (((uint32) (uchar) (A)[2]) << 16) |\
  1105. (((uint32) (uchar) (A)[1]) << 8) | \
  1106. ((uint32) (uchar) (A)[0])) : \
  1107. (((uint32) (uchar) (A)[2]) << 16) |\
  1108. (((uint32) (uchar) (A)[1]) << 8) | \
  1109. ((uint32) (uchar) (A)[0])))
  1110. #define sint4korr(A) (int32) (((int32) ((uchar) (A)[0])) +\
  1111. (((int32) ((uchar) (A)[1]) << 8)) +\
  1112. (((int32) ((uchar) (A)[2]) << 16)) +\
  1113. (((int32) ((int16) (A)[3]) << 24)))
  1114. #define sint8korr(A) (longlong) uint8korr(A)
  1115. #define uint2korr(A) (uint16) (((uint16) ((uchar) (A)[0])) +\
  1116. ((uint16) ((uchar) (A)[1]) << 8))
  1117. #define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
  1118. (((uint32) ((uchar) (A)[1])) << 8) +\
  1119. (((uint32) ((uchar) (A)[2])) << 16))
  1120. #define uint4korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
  1121. (((uint32) ((uchar) (A)[1])) << 8) +\
  1122. (((uint32) ((uchar) (A)[2])) << 16) +\
  1123. (((uint32) ((uchar) (A)[3])) << 24))
  1124. #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  1125. (((uint32) ((uchar) (A)[1])) << 8) +\
  1126. (((uint32) ((uchar) (A)[2])) << 16) +\
  1127. (((uint32) ((uchar) (A)[3])) << 24)) +\
  1128. (((ulonglong) ((uchar) (A)[4])) << 32))
  1129. #define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) + \
  1130. (((uint32) ((uchar) (A)[1])) << 8) + \
  1131. (((uint32) ((uchar) (A)[2])) << 16) + \
  1132. (((uint32) ((uchar) (A)[3])) << 24)) + \
  1133. (((ulonglong) ((uchar) (A)[4])) << 32) + \
  1134. (((ulonglong) ((uchar) (A)[5])) << 40))
  1135. #define uint8korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  1136. (((uint32) ((uchar) (A)[1])) << 8) +\
  1137. (((uint32) ((uchar) (A)[2])) << 16) +\
  1138. (((uint32) ((uchar) (A)[3])) << 24)) +\
  1139. (((ulonglong) (((uint32) ((uchar) (A)[4])) +\
  1140. (((uint32) ((uchar) (A)[5])) << 8) +\
  1141. (((uint32) ((uchar) (A)[6])) << 16) +\
  1142. (((uint32) ((uchar) (A)[7])) << 24))) <<\
  1143. 32))
  1144. #define int2store(T,A) do { uint def_temp= (uint) (A) ;\
  1145. *((uchar*) (T))= (uchar)(def_temp); \
  1146. *((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \
  1147. } while(0)
  1148. #define int3store(T,A) do { /*lint -save -e734 */\
  1149. *((uchar*)(T))=(uchar) ((A));\
  1150. *((uchar*) (T)+1)=(uchar) (((A) >> 8));\
  1151. *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \
  1152. /*lint -restore */} while(0)
  1153. #define int4store(T,A) do { *((char *)(T))=(char) ((A));\
  1154. *(((char *)(T))+1)=(char) (((A) >> 8));\
  1155. *(((char *)(T))+2)=(char) (((A) >> 16));\
  1156. *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
  1157. #define int5store(T,A) do { *((char *)(T))= (char)((A)); \
  1158. *(((char *)(T))+1)= (char)(((A) >> 8)); \
  1159. *(((char *)(T))+2)= (char)(((A) >> 16)); \
  1160. *(((char *)(T))+3)= (char)(((A) >> 24)); \
  1161. *(((char *)(T))+4)= (char)(((A) >> 32)); \
  1162. } while(0)
  1163. #define int6store(T,A) do { *((char *)(T))= (char)((A)); \
  1164. *(((char *)(T))+1)= (char)(((A) >> 8)); \
  1165. *(((char *)(T))+2)= (char)(((A) >> 16)); \
  1166. *(((char *)(T))+3)= (char)(((A) >> 24)); \
  1167. *(((char *)(T))+4)= (char)(((A) >> 32)); \
  1168. *(((char *)(T))+5)= (char)(((A) >> 40)); \
  1169. } while(0)
  1170. #define int8store(T,A) do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \
  1171. int4store((T),def_temp); \
  1172. int4store((T+4),def_temp2); } while(0)
  1173. #ifdef WORDS_BIGENDIAN
  1174. #define float4store(T,A) do { *(T)= ((uchar *) &A)[3];\
  1175. *((T)+1)=(char) ((uchar *) &A)[2];\
  1176. *((T)+2)=(char) ((uchar *) &A)[1];\
  1177. *((T)+3)=(char) ((uchar *) &A)[0]; } while(0)
  1178. #define float4get(V,M) do { float def_temp;\
  1179. ((uchar*) &def_temp)[0]=(M)[3];\
  1180. ((uchar*) &def_temp)[1]=(M)[2];\
  1181. ((uchar*) &def_temp)[2]=(M)[1];\
  1182. ((uchar*) &def_temp)[3]=(M)[0];\
  1183. (V)=def_temp; } while(0)
  1184. #define float8store(T,V) do { *(T)= ((uchar *) &V)[7];\
  1185. *((T)+1)=(char) ((uchar *) &V)[6];\
  1186. *((T)+2)=(char) ((uchar *) &V)[5];\
  1187. *((T)+3)=(char) ((uchar *) &V)[4];\
  1188. *((T)+4)=(char) ((uchar *) &V)[3];\
  1189. *((T)+5)=(char) ((uchar *) &V)[2];\
  1190. *((T)+6)=(char) ((uchar *) &V)[1];\
  1191. *((T)+7)=(char) ((uchar *) &V)[0]; } while(0)
  1192. #define float8get(V,M) do { double def_temp;\
  1193. ((uchar*) &def_temp)[0]=(M)[7];\
  1194. ((uchar*) &def_temp)[1]=(M)[6];\
  1195. ((uchar*) &def_temp)[2]=(M)[5];\
  1196. ((uchar*) &def_temp)[3]=(M)[4];\
  1197. ((uchar*) &def_temp)[4]=(M)[3];\
  1198. ((uchar*) &def_temp)[5]=(M)[2];\
  1199. ((uchar*) &def_temp)[6]=(M)[1];\
  1200. ((uchar*) &def_temp)[7]=(M)[0];\
  1201. (V) = def_temp; } while(0)
  1202. #else
  1203. #define float4get(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
  1204. #define float4store(V,M) memcpy_fixed((uchar*) V,(uchar*) (&M),sizeof(float))
  1205. #if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
  1206. #define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\
  1207. *(((char*)T)+1)=(char) ((uchar *) &V)[5];\
  1208. *(((char*)T)+2)=(char) ((uchar *) &V)[6];\
  1209. *(((char*)T)+3)=(char) ((uchar *) &V)[7];\
  1210. *(((char*)T)+4)=(char) ((uchar *) &V)[0];\
  1211. *(((char*)T)+5)=(char) ((uchar *) &V)[1];\
  1212. *(((char*)T)+6)=(char) ((uchar *) &V)[2];\
  1213. *(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\
  1214. while(0)
  1215. #define doubleget(V,M) do { double def_temp;\
  1216. ((uchar*) &def_temp)[0]=(M)[4];\
  1217. ((uchar*) &def_temp)[1]=(M)[5];\
  1218. ((uchar*) &def_temp)[2]=(M)[6];\
  1219. ((uchar*) &def_temp)[3]=(M)[7];\
  1220. ((uchar*) &def_temp)[4]=(M)[0];\
  1221. ((uchar*) &def_temp)[5]=(M)[1];\
  1222. ((uchar*) &def_temp)[6]=(M)[2];\
  1223. ((uchar*) &def_temp)[7]=(M)[3];\
  1224. (V) = def_temp; } while(0)
  1225. #endif /* __FLOAT_WORD_ORDER */
  1226. #define float8get(V,M) doubleget((V),(M))
  1227. #define float8store(V,M) doublestore((V),(M))
  1228. #endif /* WORDS_BIGENDIAN */
  1229. #endif /* __i386__ OR _WIN32 */
  1230. /*
  1231. Macro for reading 32-bit integer from network byte order (big-endian)
  1232. from unaligned memory location.
  1233. */
  1234. #define int4net(A) (int32) (((uint32) ((uchar) (A)[3])) |\
  1235. (((uint32) ((uchar) (A)[2])) << 8) |\
  1236. (((uint32) ((uchar) (A)[1])) << 16) |\
  1237. (((uint32) ((uchar) (A)[0])) << 24))
  1238. /*
  1239. Define-funktions for reading and storing in machine format from/to
  1240. short/long to/from some place in memory V should be a (not
  1241. register) variable, M is a pointer to byte
  1242. */
  1243. #ifdef WORDS_BIGENDIAN
  1244. #define ushortget(V,M) do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\
  1245. ((uint16) ((uint16) (M)[0]) << 8)); } while(0)
  1246. #define shortget(V,M) do { V = (short) (((short) ((uchar) (M)[1]))+\
  1247. ((short) ((short) (M)[0]) << 8)); } while(0)
  1248. #define longget(V,M) do { int32 def_temp;\
  1249. ((uchar*) &def_temp)[0]=(M)[0];\
  1250. ((uchar*) &def_temp)[1]=(M)[1];\
  1251. ((uchar*) &def_temp)[2]=(M)[2];\
  1252. ((uchar*) &def_temp)[3]=(M)[3];\
  1253. (V)=def_temp; } while(0)
  1254. #define ulongget(V,M) do { uint32 def_temp;\
  1255. ((uchar*) &def_temp)[0]=(M)[0];\
  1256. ((uchar*) &def_temp)[1]=(M)[1];\
  1257. ((uchar*) &def_temp)[2]=(M)[2];\
  1258. ((uchar*) &def_temp)[3]=(M)[3];\
  1259. (V)=def_temp; } while(0)
  1260. #define shortstore(T,A) do { uint def_temp=(uint) (A) ;\
  1261. *(((char*)T)+1)=(char)(def_temp); \
  1262. *(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
  1263. #define longstore(T,A) do { *(((char*)T)+3)=((A));\
  1264. *(((char*)T)+2)=(((A) >> 8));\
  1265. *(((char*)T)+1)=(((A) >> 16));\
  1266. *(((char*)T)+0)=(((A) >> 24)); } while(0)
  1267. #define floatget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
  1268. #define floatstore(T,V) memcpy_fixed((uchar*) (T),(uchar*)(&V),sizeof(float))
  1269. #define doubleget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
  1270. #define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
  1271. #define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
  1272. #define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
  1273. #else
  1274. #define ushortget(V,M) do { V = uint2korr(M); } while(0)
  1275. #define shortget(V,M) do { V = sint2korr(M); } while(0)
  1276. #define longget(V,M) do { V = sint4korr(M); } while(0)
  1277. #define ulongget(V,M) do { V = uint4korr(M); } while(0)
  1278. #define shortstore(T,V) int2store(T,V)
  1279. #define longstore(T,V) int4store(T,V)
  1280. #ifndef floatstore
  1281. #define floatstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) (&V),sizeof(float))
  1282. #define floatget(V,M) memcpy_fixed((uchar*) &V, (uchar*) (M), sizeof(float))
  1283. #endif
  1284. #ifndef doubleget
  1285. #define doubleget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
  1286. #define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
  1287. #endif /* doubleget */
  1288. #define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
  1289. #define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
  1290. #endif /* WORDS_BIGENDIAN */
  1291. /* sprintf does not always return the number of bytes :- */
  1292. #ifdef SPRINTF_RETURNS_INT
  1293. #define my_sprintf(buff,args) sprintf args
  1294. #else
  1295. #ifdef SPRINTF_RETURNS_PTR
  1296. #define my_sprintf(buff,args) ((int)(sprintf args - buff))
  1297. #else
  1298. #define my_sprintf(buff,args) ((ulong) sprintf args, (ulong) strlen(buff))
  1299. #endif
  1300. #endif
  1301. #ifndef THREAD
  1302. #define thread_safe_increment(V,L) (V)++
  1303. #define thread_safe_decrement(V,L) (V)--
  1304. #define thread_safe_add(V,C,L) (V)+=(C)
  1305. #define thread_safe_sub(V,C,L) (V)-=(C)
  1306. #define statistic_increment(V,L) (V)++
  1307. #define statistic_decrement(V,L) (V)--
  1308. #define statistic_add(V,C,L) (V)+=(C)
  1309. #define statistic_sub(V,C,L) (V)-=(C)
  1310. #endif
  1311. #ifdef HAVE_CHARSET_utf8
  1312. #define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8"
  1313. #else
  1314. #define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
  1315. #endif
  1316. #if defined(EMBEDDED_LIBRARY) && !defined(HAVE_EMBEDDED_PRIVILEGE_CONTROL)
  1317. #define NO_EMBEDDED_ACCESS_CHECKS
  1318. #endif
  1319. #ifdef HAVE_DLOPEN
  1320. #if defined(__WIN__)
  1321. #define dlsym(lib, name) GetProcAddress((HMODULE)lib, name)
  1322. #define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0)
  1323. #define dlclose(lib) FreeLibrary((HMODULE)lib)
  1324. #elif defined(HAVE_DLFCN_H)
  1325. #include <dlfcn.h>
  1326. #endif
  1327. #endif
  1328. /* FreeBSD 2.2.2 does not define RTLD_NOW) */
  1329. #ifndef RTLD_NOW
  1330. #define RTLD_NOW 1
  1331. #endif
  1332. #ifndef HAVE_DLERROR
  1333. #define dlerror() ""
  1334. #endif
  1335. #ifndef __NETWARE__
  1336. /*
  1337. * Include standard definitions of operator new and delete.
  1338. */
  1339. #ifdef __cplusplus
  1340. #include <new>
  1341. #endif
  1342. #else
  1343. /*
  1344. * Define placement versions of operator new and operator delete since
  1345. * we don't have <new> when building for Netware.
  1346. */
  1347. #ifdef __cplusplus
  1348. inline void *operator new(size_t, void *ptr) { return ptr; }
  1349. inline void *operator new[](size_t, void *ptr) { return ptr; }
  1350. inline void operator delete(void*, void*) { /* Do nothing */ }
  1351. inline void operator delete[](void*, void*) { /* Do nothing */ }
  1352. #endif
  1353. #endif
  1354. /* Length of decimal number represented by INT32. */
  1355. #define MY_INT32_NUM_DECIMAL_DIGITS 11
  1356. /* Length of decimal number represented by INT64. */
  1357. #define MY_INT64_NUM_DECIMAL_DIGITS 21
  1358. /* Define some useful general macros (should be done after all headers). */
  1359. #if !defined(max)
  1360. #define max(a, b) ((a) > (b) ? (a) : (b))
  1361. #define min(a, b) ((a) < (b) ? (a) : (b))
  1362. #endif
  1363. /*
  1364. Only Linux is known to need an explicit sync of the directory to make sure a
  1365. file creation/deletion/renaming in(from,to) this directory durable.
  1366. */
  1367. #ifdef TARGET_OS_LINUX
  1368. #define NEED_EXPLICIT_SYNC_DIR 1
  1369. #endif
  1370. #if !defined(__cplusplus) && !defined(bool)
  1371. #define bool In_C_you_should_use_my_bool_instead()
  1372. #endif
  1373. #ifndef HAVE_RINT
  1374. /**
  1375. All integers up to this number can be represented exactly as double precision
  1376. values (DBL_MANT_DIG == 53 for IEEE 754 hardware).
  1377. */
  1378. #define MAX_EXACT_INTEGER ((1LL << DBL_MANT_DIG) - 1)
  1379. /**
  1380. rint(3) implementation for platforms that do not have it.
  1381. Always rounds to the nearest integer with ties being rounded to the nearest
  1382. even integer to mimic glibc's rint() behavior in the "round-to-nearest"
  1383. FPU mode. Hardware-specific optimizations are possible (frndint on x86).
  1384. Unlike this implementation, hardware will also honor the FPU rounding mode.
  1385. */
  1386. static inline double rint(double x)
  1387. {
  1388. double f, i;
  1389. f = modf(x, &i);
  1390. /*
  1391. All doubles with absolute values > MAX_EXACT_INTEGER are even anyway,
  1392. no need to check it.
  1393. */
  1394. if (x > 0.0)
  1395. i += (double) ((f > 0.5) || (f == 0.5 &&
  1396. i <= (double) MAX_EXACT_INTEGER &&
  1397. (longlong) i % 2));
  1398. else
  1399. i -= (double) ((f < -0.5) || (f == -0.5 &&
  1400. i >= (double) -MAX_EXACT_INTEGER &&
  1401. (longlong) i % 2));
  1402. return i;
  1403. }
  1404. #endif /* HAVE_RINT */
  1405. /*
  1406. MYSQL_PLUGIN_IMPORT macro is used to export mysqld data
  1407. (i.e variables) for usage in storage engine loadable plugins.
  1408. Outside of Windows, it is dummy.
  1409. */
  1410. #ifndef MYSQL_PLUGIN_IMPORT
  1411. #if (defined(_WIN32) && defined(MYSQL_DYNAMIC_PLUGIN))
  1412. #define MYSQL_PLUGIN_IMPORT __declspec(dllimport)
  1413. #else
  1414. #define MYSQL_PLUGIN_IMPORT
  1415. #endif
  1416. #endif
  1417. #endif /* my_global_h */