my_global.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /*
  2. Copyright (c) 2001, 2013, Oracle and/or its affiliates.
  3. Copyright (c) 2010, 2013, Monty Program Ab.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
  14. /* This is the include file that should be included 'first' in every C file. */
  15. #ifndef MY_GLOBAL_INCLUDED
  16. #define MY_GLOBAL_INCLUDED
  17. /* Client library users on Windows need this macro defined here. */
  18. #if !defined(__WIN__) && defined(_WIN32)
  19. #define __WIN__
  20. #endif
  21. /*
  22. InnoDB depends on some MySQL internals which other plugins should not
  23. need. This is because of InnoDB's foreign key support, "safe" binlog
  24. truncation, and other similar legacy features.
  25. We define accessors for these internals unconditionally, but do not
  26. expose them in mysql/plugin.h. They are declared in ha_innodb.h for
  27. InnoDB's use.
  28. */
  29. #define INNODB_COMPATIBILITY_HOOKS
  30. #ifdef __CYGWIN__
  31. /* We use a Unix API, so pretend it's not Windows */
  32. #undef WIN
  33. #undef WIN32
  34. #undef _WIN
  35. #undef _WIN32
  36. #undef _WIN64
  37. #undef __WIN__
  38. #undef __WIN32__
  39. #define HAVE_ERRNO_AS_DEFINE
  40. #define _POSIX_MONOTONIC_CLOCK
  41. #define _POSIX_THREAD_CPUTIME
  42. #endif /* __CYGWIN__ */
  43. #if defined(__OpenBSD__) && (OpenBSD >= 200411)
  44. #define HAVE_ERRNO_AS_DEFINE
  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. #ifdef __cplusplus
  58. #define CPP_UNNAMED_NS_START namespace {
  59. #define CPP_UNNAMED_NS_END }
  60. #endif
  61. #include <my_config.h>
  62. #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
  63. #define HAVE_PSI_INTERFACE
  64. #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
  65. /* Make it easier to add conditional code in _expressions_ */
  66. #ifdef __WIN__
  67. #define IF_WIN(A,B) A
  68. #else
  69. #define IF_WIN(A,B) B
  70. #endif
  71. #ifdef EMBEDDED_LIBRARY
  72. #define IF_EMBEDDED(A,B) A
  73. #else
  74. #define IF_EMBEDDED(A,B) B
  75. #endif
  76. #ifdef WITH_PARTITION_STORAGE_ENGINE
  77. #define IF_PARTITIONING(A,B) A
  78. #else
  79. #define IF_PARTITIONING(A,B) B
  80. #endif
  81. #if defined (_WIN32)
  82. /*
  83. off_t is 32 bit long. We do not use C runtime functions
  84. with off_t but native Win32 file IO APIs, that work with
  85. 64 bit offsets.
  86. */
  87. #undef SIZEOF_OFF_T
  88. #define SIZEOF_OFF_T 8
  89. /*
  90. Prevent inclusion of Windows GDI headers - they define symbol
  91. ERROR that conflicts with mysql headers.
  92. */
  93. #ifndef NOGDI
  94. #define NOGDI
  95. #endif
  96. /* Include common headers.*/
  97. #include <winsock2.h>
  98. #include <ws2tcpip.h> /* SOCKET */
  99. #include <io.h> /* access(), chmod() */
  100. #include <process.h> /* getpid() */
  101. #define sleep(a) Sleep((a)*1000)
  102. /* Define missing access() modes. */
  103. #define F_OK 0
  104. #define W_OK 2
  105. #define R_OK 4 /* Test for read permission. */
  106. /* Define missing file locking constants. */
  107. #define F_RDLCK 1
  108. #define F_WRLCK 2
  109. #define F_UNLCK 3
  110. #define F_TO_EOF 0x3FFFFFFF
  111. /* Shared memory and named pipe connections are supported. */
  112. #define HAVE_SMEM 1
  113. #define HAVE_NAMED_PIPE 1
  114. #define shared_memory_buffer_length 16000
  115. #define default_shared_memory_base_name "MYSQL"
  116. #endif /* _WIN32*/
  117. /* Workaround for _LARGE_FILES and _LARGE_FILE_API incompatibility on AIX */
  118. #if defined(_AIX) && defined(_LARGE_FILE_API)
  119. #undef _LARGE_FILE_API
  120. #undef __GNUG__
  121. #endif
  122. /*
  123. The macros below are used to allow build of Universal/fat binaries of
  124. MySQL and MySQL applications under darwin.
  125. */
  126. #if defined(__APPLE__) && defined(__MACH__)
  127. # undef SIZEOF_CHARP
  128. # undef SIZEOF_SHORT
  129. # undef SIZEOF_INT
  130. # undef SIZEOF_LONG
  131. # undef SIZEOF_LONG_LONG
  132. # undef SIZEOF_OFF_T
  133. # undef WORDS_BIGENDIAN
  134. # define SIZEOF_SHORT 2
  135. # define SIZEOF_INT 4
  136. # define SIZEOF_LONG_LONG 8
  137. # define SIZEOF_OFF_T 8
  138. # if defined(__i386__) || defined(__ppc__)
  139. # define SIZEOF_CHARP 4
  140. # define SIZEOF_LONG 4
  141. # elif defined(__x86_64__) || defined(__ppc64__)
  142. # define SIZEOF_CHARP 8
  143. # define SIZEOF_LONG 8
  144. # else
  145. # error Building FAT binary for an unknown architecture.
  146. # endif
  147. # if defined(__ppc__) || defined(__ppc64__)
  148. # define WORDS_BIGENDIAN
  149. # endif
  150. #endif /* defined(__APPLE__) && defined(__MACH__) */
  151. /*
  152. The macros below are borrowed from include/linux/compiler.h in the
  153. Linux kernel. Use them to indicate the likelyhood of the truthfulness
  154. of a condition. This serves two purposes - newer versions of gcc will be
  155. able to optimize for branch predication, which could yield siginficant
  156. performance gains in frequently executed sections of the code, and the
  157. other reason to use them is for documentation
  158. */
  159. #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
  160. #define __builtin_expect(x, expected_value) (x)
  161. #endif
  162. /**
  163. The semantics of builtin_expect() are that
  164. 1) its two arguments are long
  165. 2) it's likely that they are ==
  166. Those of our likely(x) are that x can be bool/int/longlong/pointer.
  167. */
  168. #define likely(x) __builtin_expect(((x) != 0),1)
  169. #define unlikely(x) __builtin_expect(((x) != 0),0)
  170. /* Fix problem with S_ISLNK() on Linux */
  171. #if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
  172. #undef _GNU_SOURCE
  173. #define _GNU_SOURCE 1
  174. #endif
  175. /*
  176. Temporary solution to solve bug#7156. Include "sys/types.h" before
  177. the thread headers, else the function madvise() will not be defined
  178. */
  179. #if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
  180. #include <sys/types.h>
  181. #endif
  182. #define __EXTENSIONS__ 1 /* We want some extension */
  183. #ifndef __STDC_EXT__
  184. #define __STDC_EXT__ 1 /* To get large file support on hpux */
  185. #endif
  186. /*
  187. Solaris 9 include file <sys/feature_tests.h> refers to X/Open document
  188. System Interfaces and Headers, Issue 5
  189. saying we should define _XOPEN_SOURCE=500 to get POSIX.1c prototypes,
  190. but apparently other systems (namely FreeBSD) don't agree.
  191. On a newer Solaris 10, the above file recognizes also _XOPEN_SOURCE=600.
  192. Furthermore, it tests that if a program requires older standard
  193. (_XOPEN_SOURCE<600 or _POSIX_C_SOURCE<200112L) it cannot be
  194. run on a new compiler (that defines _STDC_C99) and issues an #error.
  195. It's also an #error if a program requires new standard (_XOPEN_SOURCE=600
  196. or _POSIX_C_SOURCE=200112L) and a compiler does not define _STDC_C99.
  197. To add more to this mess, Sun Studio C compiler defines _STDC_C99 while
  198. C++ compiler does not!
  199. So, in a desperate attempt to get correct prototypes for both
  200. C and C++ code, we define either _XOPEN_SOURCE=600 or _XOPEN_SOURCE=500
  201. depending on the compiler's announced C standard support.
  202. Cleaner solutions are welcome.
  203. */
  204. #ifdef __sun
  205. #if __STDC_VERSION__ - 0 >= 199901L
  206. #define _XOPEN_SOURCE 600
  207. #else
  208. #define _XOPEN_SOURCE 500
  209. #endif
  210. #endif
  211. #ifdef _AIX
  212. /*
  213. AIX includes inttypes.h from sys/types.h
  214. Explicitly request format macros before the first inclusion of inttypes.h
  215. */
  216. #define __STDC_FORMAT_MACROS
  217. #endif
  218. #if !defined(__WIN__)
  219. #ifndef _POSIX_PTHREAD_SEMANTICS
  220. #define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
  221. #endif
  222. #if !defined(SCO)
  223. #define _REENTRANT 1 /* Some thread libraries require this */
  224. #endif
  225. #if !defined(_THREAD_SAFE) && !defined(_AIX)
  226. #define _THREAD_SAFE /* Required for OSF1 */
  227. #endif
  228. #if defined(HPUX10) || defined(HPUX11)
  229. C_MODE_START /* HPUX needs this, signal.h bug */
  230. #include <pthread.h>
  231. C_MODE_END
  232. #else
  233. #include <pthread.h> /* AIX must have this included first */
  234. #endif
  235. #if !defined(SCO) && !defined(_REENTRANT)
  236. #define _REENTRANT 1 /* Threads requires reentrant code */
  237. #endif
  238. #endif /* !defined(__WIN__) */
  239. /* Go around some bugs in different OS and compilers */
  240. #ifdef _AIX /* By soren@t.dk */
  241. #define _H_STRINGS
  242. #define _SYS_STREAM_H
  243. /* #define _AIX32_CURSES */ /* XXX: this breaks AIX 4.3.3 (others?). */
  244. #define ulonglong2double(A) my_ulonglong2double(A)
  245. #define my_off_t2double(A) my_ulonglong2double(A)
  246. C_MODE_START
  247. inline double my_ulonglong2double(unsigned long long A) { return (double)A; }
  248. C_MODE_END
  249. #endif /* _AIX */
  250. #ifdef UNDEF_HAVE_INITGROUPS /* For AIX 4.3 */
  251. #undef HAVE_INITGROUPS
  252. #endif
  253. /* gcc/egcs issues */
  254. #if defined(__GNUC) && defined(__EXCEPTIONS)
  255. #error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
  256. #endif
  257. #if defined(_lint) && !defined(lint)
  258. #define lint
  259. #endif
  260. #if SIZEOF_LONG_LONG > 4 && !defined(_LONG_LONG)
  261. #define _LONG_LONG 1 /* For AIX string library */
  262. #endif
  263. /* Workaround for _LARGE_FILES and _LARGE_FILE_API incompatibility on AIX */
  264. #if defined(_AIX) && defined(_LARGE_FILE_API)
  265. #undef _LARGE_FILE_API
  266. #undef __GNUG__
  267. #endif
  268. #ifndef stdin
  269. #include <stdio.h>
  270. #endif
  271. #include <stdarg.h>
  272. #ifdef HAVE_STDLIB_H
  273. #include <stdlib.h>
  274. #endif
  275. #ifdef HAVE_STDDEF_H
  276. #include <stddef.h>
  277. #endif
  278. #include <math.h>
  279. #ifdef HAVE_LIMITS_H
  280. #include <limits.h>
  281. #endif
  282. #ifdef HAVE_FLOAT_H
  283. #include <float.h>
  284. #endif
  285. #ifdef HAVE_FENV_H
  286. #include <fenv.h> /* For fesetround() */
  287. #endif
  288. #ifdef HAVE_SYS_TYPES_H
  289. #include <sys/types.h>
  290. #endif
  291. /* Workaround for _LARGE_FILES and _LARGE_FILE_API incompatibility on AIX */
  292. #if defined(_AIX) && defined(_LARGE_FILE_API)
  293. #undef _LARGE_FILE_API
  294. #undef __GNUG__
  295. #endif
  296. #ifdef HAVE_FCNTL_H
  297. #include <fcntl.h>
  298. #endif
  299. #ifdef HAVE_SYS_STAT_H
  300. #include <sys/stat.h>
  301. #endif
  302. #if TIME_WITH_SYS_TIME
  303. # include <sys/time.h>
  304. # include <time.h>
  305. #else
  306. # if HAVE_SYS_TIME_H
  307. # include <sys/time.h>
  308. # else
  309. # include <time.h>
  310. # endif
  311. #endif /* TIME_WITH_SYS_TIME */
  312. #ifdef HAVE_UNISTD_H
  313. #include <unistd.h>
  314. #endif
  315. #if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
  316. #undef HAVE_ALLOCA
  317. #undef HAVE_ALLOCA_H
  318. #endif
  319. #ifdef HAVE_ALLOCA_H
  320. #include <alloca.h>
  321. #endif
  322. #include <errno.h> /* Recommended by debian */
  323. /* We need the following to go around a problem with openssl on solaris */
  324. #if defined(HAVE_CRYPT_H)
  325. #include <crypt.h>
  326. #endif
  327. /*
  328. A lot of our programs uses asserts, so better to always include it
  329. This also fixes a problem when people uses DBUG_ASSERT without including
  330. assert.h
  331. */
  332. #include <assert.h>
  333. /* an assert that works at compile-time. only for constant expression */
  334. #ifdef _some_old_compiler_that_does_not_understand_the_construct_below_
  335. #define compile_time_assert(X) do { } while(0)
  336. #else
  337. #define compile_time_assert(X) \
  338. do \
  339. { \
  340. typedef char compile_time_assert[(X) ? 1 : -1] __attribute__((unused)); \
  341. } while(0)
  342. #endif
  343. /* Go around some bugs in different OS and compilers */
  344. #if defined (HPUX11) && defined(_LARGEFILE_SOURCE)
  345. #ifndef _LARGEFILE64_SOURCE
  346. #define _LARGEFILE64_SOURCE
  347. #endif
  348. #endif
  349. #if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H)
  350. #include <sys/stream.h> /* HPUX 10.20 defines ulong here. UGLY !!! */
  351. #define HAVE_ULONG
  352. #endif
  353. #if defined(HPUX10) && defined(_LARGEFILE64_SOURCE)
  354. /* Fix bug in setrlimit */
  355. #undef setrlimit
  356. #define setrlimit cma_setrlimit64
  357. #endif
  358. /* Declare madvise where it is not declared for C++, like Solaris */
  359. #if HAVE_MADVISE && !HAVE_DECL_MADVISE && defined(__cplusplus)
  360. extern "C" int madvise(void *addr, size_t len, int behav);
  361. #endif
  362. #define QUOTE_ARG(x) #x /* Quote argument (before cpp) */
  363. #define STRINGIFY_ARG(x) QUOTE_ARG(x) /* Quote argument, after cpp */
  364. /* Paranoid settings. Define I_AM_PARANOID if you are paranoid */
  365. #ifdef I_AM_PARANOID
  366. #define DONT_ALLOW_USER_CHANGE 1
  367. #define DONT_USE_MYSQL_PWD 1
  368. #endif
  369. /* Does the system remember a signal handler after a signal ? */
  370. #if !defined(HAVE_BSD_SIGNALS) && !defined(HAVE_SIGACTION)
  371. #define SIGNAL_HANDLER_RESET_ON_DELIVERY
  372. #endif
  373. #ifndef STDERR_FILENO
  374. #define STDERR_FILENO fileno(stderr)
  375. #endif
  376. #ifndef SO_EXT
  377. #ifdef _WIN32
  378. #define SO_EXT ".dll"
  379. #else
  380. #define SO_EXT ".so"
  381. #endif
  382. #endif
  383. /*
  384. Suppress uninitialized variable warning without generating code.
  385. */
  386. #if defined(__GNUC__)
  387. /* GCC specific self-initialization which inhibits the warning. */
  388. #define UNINIT_VAR(x) x= x
  389. #elif defined(_lint) || defined(FORCE_INIT_OF_VARS)
  390. #define UNINIT_VAR(x) x= 0
  391. #else
  392. #define UNINIT_VAR(x) x
  393. #endif
  394. /* This is only to be used when reseting variables in a class constructor */
  395. #if defined(_lint) || defined(FORCE_INIT_OF_VARS)
  396. #define LINT_INIT(x) x= 0
  397. #else
  398. #define LINT_INIT(x)
  399. #endif
  400. #if !defined(HAVE_UINT)
  401. #undef HAVE_UINT
  402. #define HAVE_UINT
  403. typedef unsigned int uint;
  404. typedef unsigned short ushort;
  405. #endif
  406. #define swap_variables(t, a, b) do { t dummy; dummy= a; a= b; b= dummy; } while(0)
  407. #define MY_TEST(a) ((a) ? 1 : 0)
  408. #define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
  409. #define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
  410. #define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
  411. #define test_all_bits(a,b) (((a) & (b)) == (b))
  412. #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
  413. /* Define some general constants */
  414. #ifndef TRUE
  415. #define TRUE (1) /* Logical true */
  416. #define FALSE (0) /* Logical false */
  417. #endif
  418. #include <my_compiler.h>
  419. /*
  420. Wen using the embedded library, users might run into link problems,
  421. duplicate declaration of __cxa_pure_virtual, solved by declaring it a
  422. weak symbol.
  423. */
  424. #if defined(USE_MYSYS_NEW) && ! defined(DONT_DECLARE_CXA_PURE_VIRTUAL)
  425. C_MODE_START
  426. int __cxa_pure_virtual () __attribute__ ((weak));
  427. C_MODE_END
  428. #endif
  429. /* The DBUG_ON flag always takes precedence over default DBUG_OFF */
  430. #if defined(DBUG_ON) && defined(DBUG_OFF)
  431. #undef DBUG_OFF
  432. #endif
  433. /* We might be forced to turn debug off, if not turned off already */
  434. #if (defined(FORCE_DBUG_OFF) || defined(_lint)) && !defined(DBUG_OFF)
  435. # define DBUG_OFF
  436. # ifdef DBUG_ON
  437. # undef DBUG_ON
  438. # endif
  439. #endif
  440. #ifdef DBUG_OFF
  441. #undef EXTRA_DEBUG
  442. #endif
  443. /* Some types that is different between systems */
  444. typedef int File; /* File descriptor */
  445. #ifdef _WIN32
  446. typedef SOCKET my_socket;
  447. #else
  448. typedef int my_socket; /* File descriptor for sockets */
  449. #define INVALID_SOCKET -1
  450. #endif
  451. /* Type for fuctions that handles signals */
  452. #define sig_handler RETSIGTYPE
  453. C_MODE_START
  454. #ifdef HAVE_SIGHANDLER_T
  455. #define sig_return sighandler_t
  456. #else
  457. typedef void (*sig_return)(void); /* Returns type from signal */
  458. #endif
  459. C_MODE_END
  460. #if defined(__GNUC__) && !defined(_lint)
  461. typedef char pchar; /* Mixed prototypes can take char */
  462. typedef char puchar; /* Mixed prototypes can take char */
  463. typedef char pbool; /* Mixed prototypes can take char */
  464. typedef short pshort; /* Mixed prototypes can take short int */
  465. typedef float pfloat; /* Mixed prototypes can take float */
  466. #else
  467. typedef int pchar; /* Mixed prototypes can't take char */
  468. typedef uint puchar; /* Mixed prototypes can't take char */
  469. typedef int pbool; /* Mixed prototypes can't take char */
  470. typedef int pshort; /* Mixed prototypes can't take short int */
  471. typedef double pfloat; /* Mixed prototypes can't take float */
  472. #endif
  473. C_MODE_START
  474. typedef int (*qsort_cmp)(const void *,const void *);
  475. typedef int (*qsort_cmp2)(void*, const void *,const void *);
  476. C_MODE_END
  477. #define qsort_t RETQSORTTYPE /* Broken GCC cant handle typedef !!!! */
  478. #ifdef HAVE_SYS_SOCKET_H
  479. #include <sys/socket.h>
  480. #endif
  481. typedef SOCKET_SIZE_TYPE size_socket;
  482. #ifndef SOCKOPT_OPTLEN_TYPE
  483. #define SOCKOPT_OPTLEN_TYPE size_socket
  484. #endif
  485. /* file create flags */
  486. #ifndef O_SHARE /* Probably not windows */
  487. #define O_SHARE 0 /* Flag to my_open for shared files */
  488. #ifndef O_BINARY
  489. #define O_BINARY 0 /* Flag to my_open for binary files */
  490. #endif
  491. #ifndef FILE_BINARY
  492. #define FILE_BINARY O_BINARY /* Flag to my_fopen for binary streams */
  493. #endif
  494. #ifdef HAVE_FCNTL
  495. #define HAVE_FCNTL_LOCK
  496. #define F_TO_EOF 0L /* Param to lockf() to lock rest of file */
  497. #endif
  498. #endif /* O_SHARE */
  499. #ifndef O_TEMPORARY
  500. #define O_TEMPORARY 0
  501. #endif
  502. #ifndef O_SHORT_LIVED
  503. #define O_SHORT_LIVED 0
  504. #endif
  505. #ifndef O_NOFOLLOW
  506. #define O_NOFOLLOW 0
  507. #endif
  508. #ifndef O_CLOEXEC
  509. #define O_CLOEXEC 0
  510. #endif
  511. #ifndef SOCK_CLOEXEC
  512. #define SOCK_CLOEXEC 0
  513. #endif
  514. /* additional file share flags for win32 */
  515. #ifdef __WIN__
  516. #define _SH_DENYRWD 0x110 /* deny read/write mode & delete */
  517. #define _SH_DENYWRD 0x120 /* deny write mode & delete */
  518. #define _SH_DENYRDD 0x130 /* deny read mode & delete */
  519. #define _SH_DENYDEL 0x140 /* deny delete only */
  520. #endif /* __WIN__ */
  521. /* General constants */
  522. #define FN_LEN 256 /* Max file name len */
  523. #define FN_HEADLEN 253 /* Max length of filepart of file name */
  524. #define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */
  525. #define FN_REFLEN 512 /* Max length of full path-name */
  526. #define FN_EXTCHAR '.'
  527. #define FN_HOMELIB '~' /* ~/ is used as abbrev for home dir */
  528. #define FN_CURLIB '.' /* ./ is used as abbrev for current dir */
  529. #define FN_PARENTDIR ".." /* Parent directory; Must be a string */
  530. #ifdef _WIN32
  531. #define FN_LIBCHAR '\\'
  532. #define FN_LIBCHAR2 '/'
  533. #define FN_DIRSEP "/\\" /* Valid directory separators */
  534. #define FN_EXEEXT ".exe"
  535. #define FN_SOEXT ".dll"
  536. #define FN_ROOTDIR "\\"
  537. #define FN_DEVCHAR ':'
  538. #define FN_NETWORK_DRIVES /* Uses \\ to indicate network drives */
  539. #define FN_NO_CASE_SENCE /* Files are not case-sensitive */
  540. #else
  541. #define FN_LIBCHAR '/'
  542. #define FN_LIBCHAR2 '/'
  543. #define FN_DIRSEP "/" /* Valid directory separators */
  544. #define FN_EXEEXT ""
  545. #define FN_SOEXT ".so"
  546. #define FN_ROOTDIR "/"
  547. #endif
  548. /*
  549. MY_FILE_MIN is Windows speciality and is used to quickly detect
  550. the mismatch of CRT and mysys file IO usage on Windows at runtime.
  551. CRT file descriptors can be in the range 0-2047, whereas descriptors returned
  552. by my_open() will start with 2048. If a file descriptor with value less then
  553. MY_FILE_MIN is passed to mysys IO function, chances are it stemms from
  554. open()/fileno() and not my_open()/my_fileno.
  555. For Posix, mysys functions are light wrappers around libc, and MY_FILE_MIN
  556. is logically 0.
  557. */
  558. #ifdef _WIN32
  559. #define MY_FILE_MIN 2048
  560. #else
  561. #define MY_FILE_MIN 0
  562. #endif
  563. /*
  564. MY_NFILE is the default size of my_file_info array.
  565. It is larger on Windows, because it all file handles are stored in my_file_info
  566. Default size is 16384 and this should be enough for most cases.If it is not
  567. enough, --max-open-files with larger value can be used.
  568. For Posix , my_file_info array is only used to store filenames for
  569. error reporting and its size is not a limitation for number of open files.
  570. */
  571. #ifdef _WIN32
  572. #define MY_NFILE (16384 + MY_FILE_MIN)
  573. #else
  574. #define MY_NFILE 64
  575. #endif
  576. #ifndef OS_FILE_LIMIT
  577. #define OS_FILE_LIMIT UINT_MAX
  578. #endif
  579. /*
  580. Io buffer size; Must be a power of 2 and a multiple of 512. May be
  581. smaller what the disk page size. This influences the speed of the
  582. isam btree library. eg to big to slow.
  583. */
  584. #define IO_SIZE 4096
  585. /*
  586. How much overhead does malloc have. The code often allocates
  587. something like 1024-MALLOC_OVERHEAD bytes
  588. */
  589. #define MALLOC_OVERHEAD 8
  590. /* get memory in huncs */
  591. #define ONCE_ALLOC_INIT (uint) 4096
  592. /* Typical record cache */
  593. #define RECORD_CACHE_SIZE (uint) (128*1024)
  594. /* Typical key cache */
  595. #define KEY_CACHE_SIZE (uint) (128L*1024L*1024L)
  596. /* Default size of a key cache block */
  597. #define KEY_CACHE_BLOCK_SIZE (uint) 1024
  598. /* Some things that this system doesn't have */
  599. #ifdef _WIN32
  600. #define NO_DIR_LIBRARY /* Not standard dir-library */
  601. #endif
  602. /* Some defines of functions for portability */
  603. #undef remove /* Crashes MySQL on SCO 5.0.0 */
  604. #ifndef __WIN__
  605. #define closesocket(A) close(A)
  606. #endif
  607. #if (_MSC_VER)
  608. #if !defined(_WIN64)
  609. inline double my_ulonglong2double(unsigned long long value)
  610. {
  611. long long nr=(long long) value;
  612. if (nr >= 0)
  613. return (double) nr;
  614. return (18446744073709551616.0 + (double) nr);
  615. }
  616. #define ulonglong2double my_ulonglong2double
  617. #define my_off_t2double my_ulonglong2double
  618. #endif /* _WIN64 */
  619. inline unsigned long long my_double2ulonglong(double d)
  620. {
  621. double t= d - (double) 0x8000000000000000ULL;
  622. if (t >= 0)
  623. return ((unsigned long long) t) + 0x8000000000000000ULL;
  624. return (unsigned long long) d;
  625. }
  626. #define double2ulonglong my_double2ulonglong
  627. #endif
  628. #ifndef ulonglong2double
  629. #define ulonglong2double(A) ((double) (ulonglong) (A))
  630. #define my_off_t2double(A) ((double) (my_off_t) (A))
  631. #endif
  632. #ifndef double2ulonglong
  633. #define double2ulonglong(A) ((ulonglong) (double) (A))
  634. #endif
  635. #ifndef offsetof
  636. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  637. #endif
  638. #define ulong_to_double(X) ((double) (ulong) (X))
  639. #ifndef STACK_DIRECTION
  640. #error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
  641. #endif
  642. #if !defined(HAVE_STRTOK_R)
  643. #define strtok_r(A,B,C) strtok((A),(B))
  644. #endif
  645. #if SIZEOF_LONG_LONG >= 8
  646. #define HAVE_LONG_LONG 1
  647. #else
  648. #error WHAT? sizeof(long long) < 8 ???
  649. #endif
  650. /*
  651. Some pre-ANSI-C99 systems like AIX 5.1 and Linux/GCC 2.95 define
  652. ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined.
  653. */
  654. #if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
  655. #define LONGLONG_MIN ((long long) 0x8000000000000000LL)
  656. #define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL)
  657. #endif
  658. #if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
  659. /* First check for ANSI C99 definition: */
  660. #ifdef ULLONG_MAX
  661. #define ULONGLONG_MAX ULLONG_MAX
  662. #else
  663. #define ULONGLONG_MAX ((unsigned long long)(~0ULL))
  664. #endif
  665. #endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/
  666. #define INT_MIN64 (~0x7FFFFFFFFFFFFFFFLL)
  667. #define INT_MAX64 0x7FFFFFFFFFFFFFFFLL
  668. #define INT_MIN32 (~0x7FFFFFFFL)
  669. #define INT_MAX32 0x7FFFFFFFL
  670. #define UINT_MAX32 0xFFFFFFFFL
  671. #define INT_MIN24 (~0x007FFFFF)
  672. #define INT_MAX24 0x007FFFFF
  673. #define UINT_MAX24 0x00FFFFFF
  674. #define INT_MIN16 (~0x7FFF)
  675. #define INT_MAX16 0x7FFF
  676. #define UINT_MAX16 0xFFFF
  677. #define INT_MIN8 (~0x7F)
  678. #define INT_MAX8 0x7F
  679. #define UINT_MAX8 0xFF
  680. /* From limits.h instead */
  681. #ifndef DBL_MIN
  682. #define DBL_MIN 4.94065645841246544e-324
  683. #define FLT_MIN ((float)1.40129846432481707e-45)
  684. #endif
  685. #ifndef DBL_MAX
  686. #define DBL_MAX 1.79769313486231470e+308
  687. #define FLT_MAX ((float)3.40282346638528860e+38)
  688. #endif
  689. #ifndef SIZE_T_MAX
  690. #define SIZE_T_MAX (~((size_t) 0))
  691. #endif
  692. #ifndef isfinite
  693. #ifdef HAVE_FINITE
  694. #define isfinite(x) finite(x)
  695. #else
  696. #define finite(x) (1.0 / fabs(x) > 0.0)
  697. #endif /* HAVE_FINITE */
  698. #elif (__cplusplus >= 201103L)
  699. #include <cmath>
  700. static inline bool isfinite(double x) { return std::isfinite(x); }
  701. #endif /* isfinite */
  702. #ifndef HAVE_ISNAN
  703. #define isnan(x) ((x) != (x))
  704. #endif
  705. #ifdef HAVE_ISINF
  706. #define my_isinf(X) isinf(X)
  707. #else /* !HAVE_ISINF */
  708. #define my_isinf(X) (!finite(X) && !isnan(X))
  709. #endif
  710. /* Define missing math constants. */
  711. #ifndef M_PI
  712. #define M_PI 3.14159265358979323846
  713. #endif
  714. #ifndef M_E
  715. #define M_E 2.7182818284590452354
  716. #endif
  717. #ifndef M_LN2
  718. #define M_LN2 0.69314718055994530942
  719. #endif
  720. #ifndef HAVE_LOG2
  721. /*
  722. This will be slightly slower and perhaps a tiny bit less accurate than
  723. doing it the IEEE754 way but log2() should be available on C99 systems.
  724. */
  725. static inline double log2(double x)
  726. {
  727. return (log(x) / M_LN2);
  728. }
  729. #endif
  730. /*
  731. Max size that must be added to a so that we know Size to make
  732. adressable obj.
  733. */
  734. #if SIZEOF_CHARP == 4
  735. typedef long my_ptrdiff_t;
  736. #else
  737. typedef long long my_ptrdiff_t;
  738. #endif
  739. #define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
  740. #define MY_ALIGN_DOWN(A,L) ((A) & ~((L) - 1))
  741. #define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
  742. #define ALIGN_MAX_UNIT (sizeof(double))
  743. /* Size to make adressable obj. */
  744. #define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A), sizeof(double)))
  745. #define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
  746. #define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
  747. #define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
  748. /*
  749. Custom version of standard offsetof() macro which can be used to get
  750. offsets of members in class for non-POD types (according to the current
  751. version of C++ standard offsetof() macro can't be used in such cases and
  752. attempt to do so causes warnings to be emitted, OTOH in many cases it is
  753. still OK to assume that all instances of the class has the same offsets
  754. for the same members).
  755. This is temporary solution which should be removed once File_parser class
  756. and related routines are refactored.
  757. */
  758. #define my_offsetof(TYPE, MEMBER) PTR_BYTE_DIFF(&((TYPE *)0x10)->MEMBER, 0x10)
  759. #define NullS (char *) 0
  760. #ifdef STDCALL
  761. #undef STDCALL
  762. #endif
  763. #ifdef _WIN32
  764. #define STDCALL __stdcall
  765. #else
  766. #define STDCALL
  767. #endif
  768. /* Typdefs for easyier portability */
  769. #ifndef HAVE_UCHAR
  770. typedef unsigned char uchar; /* Short for unsigned char */
  771. #endif
  772. #ifndef HAVE_INT8
  773. typedef signed char int8; /* Signed integer >= 8 bits */
  774. #endif
  775. #ifndef HAVE_UINT8
  776. typedef unsigned char uint8; /* Unsigned integer >= 8 bits */
  777. #endif
  778. #ifndef HAVE_INT16
  779. typedef short int16;
  780. #endif
  781. #ifndef HAVE_UINT16
  782. typedef unsigned short uint16;
  783. #endif
  784. #if SIZEOF_INT == 4
  785. #ifndef HAVE_INT32
  786. typedef int int32;
  787. #endif
  788. #ifndef HAVE_UINT32
  789. typedef unsigned int uint32;
  790. #endif
  791. #elif SIZEOF_LONG == 4
  792. #ifndef HAVE_INT32
  793. typedef long int32;
  794. #endif
  795. #ifndef HAVE_UINT32
  796. typedef unsigned long uint32;
  797. #endif
  798. #else
  799. #error Neither int or long is of 4 bytes width
  800. #endif
  801. #if !defined(HAVE_ULONG) && !defined(__USE_MISC)
  802. typedef unsigned long ulong; /* Short for unsigned long */
  803. #endif
  804. #ifndef longlong_defined
  805. /*
  806. Using [unsigned] long long is preferable as [u]longlong because we use
  807. [unsigned] long long unconditionally in many places,
  808. for example in constants with [U]LL suffix.
  809. */
  810. #if defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 8
  811. typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
  812. typedef long long int longlong;
  813. #else
  814. typedef unsigned long ulonglong; /* ulong or unsigned long long */
  815. typedef long longlong;
  816. #endif
  817. #endif
  818. #ifndef HAVE_INT64
  819. typedef longlong int64;
  820. #endif
  821. #ifndef HAVE_UINT64
  822. typedef ulonglong uint64;
  823. #endif
  824. #if defined(NO_CLIENT_LONG_LONG)
  825. typedef unsigned long my_ulonglong;
  826. #elif defined (__WIN__)
  827. typedef unsigned __int64 my_ulonglong;
  828. #else
  829. typedef unsigned long long my_ulonglong;
  830. #endif
  831. #if SIZEOF_CHARP == SIZEOF_INT
  832. typedef unsigned int intptr;
  833. #elif SIZEOF_CHARP == SIZEOF_LONG
  834. typedef unsigned long intptr;
  835. #elif SIZEOF_CHARP == SIZEOF_LONG_LONG
  836. typedef unsigned long long intptr;
  837. #else
  838. #error sizeof(void *) is neither sizeof(int) nor sizeof(long) nor sizeof(long long)
  839. #endif
  840. #define MY_ERRPTR ((void*)(intptr)1)
  841. #if defined(_WIN32)
  842. typedef unsigned long long my_off_t;
  843. typedef unsigned long long os_off_t;
  844. #else
  845. typedef off_t os_off_t;
  846. #if SIZEOF_OFF_T > 4
  847. typedef ulonglong my_off_t;
  848. #else
  849. typedef unsigned long my_off_t;
  850. #endif
  851. #endif /*_WIN32*/
  852. #define MY_FILEPOS_ERROR (~(my_off_t) 0)
  853. /*
  854. TODO Convert these to use Bitmap class.
  855. */
  856. typedef ulonglong table_map; /* Used for table bits in join */
  857. typedef ulong nesting_map; /* Used for flags of nesting constructs */
  858. /* often used type names - opaque declarations */
  859. typedef const struct charset_info_st CHARSET_INFO;
  860. typedef struct st_mysql_lex_string LEX_STRING;
  861. #if defined(__WIN__)
  862. #define socket_errno WSAGetLastError()
  863. #define SOCKET_EINTR WSAEINTR
  864. #define SOCKET_EAGAIN WSAEINPROGRESS
  865. #define SOCKET_ETIMEDOUT WSAETIMEDOUT
  866. #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
  867. #define SOCKET_EADDRINUSE WSAEADDRINUSE
  868. #define SOCKET_ECONNRESET WSAECONNRESET
  869. #define SOCKET_ENFILE ENFILE
  870. #define SOCKET_EMFILE EMFILE
  871. #else /* Unix */
  872. #define socket_errno errno
  873. #define closesocket(A) close(A)
  874. #define SOCKET_EINTR EINTR
  875. #define SOCKET_EAGAIN EAGAIN
  876. #define SOCKET_EWOULDBLOCK EWOULDBLOCK
  877. #define SOCKET_EADDRINUSE EADDRINUSE
  878. #define SOCKET_ETIMEDOUT ETIMEDOUT
  879. #define SOCKET_ECONNRESET ECONNRESET
  880. #define SOCKET_ENFILE ENFILE
  881. #define SOCKET_EMFILE EMFILE
  882. #endif
  883. #include <mysql/plugin.h> /* my_bool */
  884. typedef ulong myf; /* Type of MyFlags in my_funcs */
  885. #define MYF(v) (myf) (v)
  886. /*
  887. Defines to make it possible to prioritize register assignments. No
  888. longer that important with modern compilers.
  889. */
  890. #ifndef USING_X
  891. #define reg1 register
  892. #define reg2 register
  893. #define reg3 register
  894. #define reg4 register
  895. #define reg5 register
  896. #define reg6 register
  897. #define reg7 register
  898. #define reg8 register
  899. #define reg9 register
  900. #define reg10 register
  901. #define reg11 register
  902. #define reg12 register
  903. #define reg13 register
  904. #define reg14 register
  905. #define reg15 register
  906. #define reg16 register
  907. #endif
  908. #include <my_dbug.h>
  909. /* Some helper macros */
  910. #define YESNO(X) ((X) ? "yes" : "no")
  911. #define MY_HOW_OFTEN_TO_ALARM 2 /* How often we want info on screen */
  912. #define MY_HOW_OFTEN_TO_WRITE 10000 /* How often we want info on screen */
  913. #include <my_byteorder.h>
  914. #ifdef HAVE_CHARSET_utf8
  915. #define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8"
  916. #else
  917. #define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
  918. #endif
  919. #if defined(EMBEDDED_LIBRARY) && !defined(HAVE_EMBEDDED_PRIVILEGE_CONTROL)
  920. #define NO_EMBEDDED_ACCESS_CHECKS
  921. #endif
  922. #ifdef _WIN32
  923. #define dlsym(lib, name) (void*)GetProcAddress((HMODULE)lib, name)
  924. #define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0)
  925. #define dlclose(lib) FreeLibrary((HMODULE)lib)
  926. static inline char *dlerror(void)
  927. {
  928. static char win_errormsg[2048];
  929. if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  930. 0, GetLastError(), 0, win_errormsg, 2048, NULL))
  931. return win_errormsg;
  932. return "";
  933. }
  934. #define HAVE_DLOPEN 1
  935. #define HAVE_DLERROR 1
  936. #endif
  937. #ifdef HAVE_DLFCN_H
  938. #include <dlfcn.h>
  939. #endif
  940. #ifdef HAVE_DLOPEN
  941. #ifndef HAVE_DLERROR
  942. #define dlerror() ""
  943. #endif
  944. #else
  945. #define dlerror() "No support for dynamic loading (static build?)"
  946. #define dlopen(A,B) 0
  947. #define dlsym(A,B) 0
  948. #define dlclose(A) 0
  949. #endif
  950. /*
  951. * Include standard definitions of operator new and delete.
  952. */
  953. #ifdef __cplusplus
  954. #include <new>
  955. #endif
  956. /* Length of decimal number represented by INT32. */
  957. #define MY_INT32_NUM_DECIMAL_DIGITS 11
  958. /* Length of decimal number represented by INT64. */
  959. #define MY_INT64_NUM_DECIMAL_DIGITS 21
  960. #ifdef __cplusplus
  961. #include <limits> /* should be included before min/max macros */
  962. #endif
  963. /* Define some useful general macros (should be done after all headers). */
  964. #define MY_MAX(a, b) ((a) > (b) ? (a) : (b))
  965. #define MY_MIN(a, b) ((a) < (b) ? (a) : (b))
  966. #define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
  967. /*
  968. Only Linux is known to need an explicit sync of the directory to make sure a
  969. file creation/deletion/renaming in(from,to) this directory durable.
  970. */
  971. #ifdef TARGET_OS_LINUX
  972. #define NEED_EXPLICIT_SYNC_DIR 1
  973. #else
  974. /*
  975. On linux default rwlock scheduling policy is good enough for
  976. waiting_threads.c, on other systems use our special implementation
  977. (which is slower).
  978. QQ perhaps this should be tested in configure ? how ?
  979. */
  980. #define WT_RWLOCKS_USE_MUTEXES 1
  981. #endif
  982. #if !defined(__cplusplus) && !defined(bool)
  983. #define bool In_C_you_should_use_my_bool_instead()
  984. #endif
  985. /* Provide __func__ macro definition for platforms that miss it. */
  986. #if !defined (__func__)
  987. #if __STDC_VERSION__ < 199901L
  988. # if __GNUC__ >= 2
  989. # define __func__ __FUNCTION__
  990. # else
  991. # define __func__ "<unknown>"
  992. # endif
  993. #elif defined(_MSC_VER)
  994. # if _MSC_VER < 1300
  995. # define __func__ "<unknown>"
  996. # else
  997. # define __func__ __FUNCTION__
  998. # endif
  999. #elif defined(__BORLANDC__)
  1000. # define __func__ __FUNC__
  1001. #else
  1002. # define __func__ "<unknown>"
  1003. #endif
  1004. #endif /* !defined(__func__) */
  1005. #ifndef HAVE_RINT
  1006. /**
  1007. All integers up to this number can be represented exactly as double precision
  1008. values (DBL_MANT_DIG == 53 for IEEE 754 hardware).
  1009. */
  1010. #define MAX_EXACT_INTEGER ((1LL << DBL_MANT_DIG) - 1)
  1011. /**
  1012. rint(3) implementation for platforms that do not have it.
  1013. Always rounds to the nearest integer with ties being rounded to the nearest
  1014. even integer to mimic glibc's rint() behavior in the "round-to-nearest"
  1015. FPU mode. Hardware-specific optimizations are possible (frndint on x86).
  1016. Unlike this implementation, hardware will also honor the FPU rounding mode.
  1017. */
  1018. static inline double rint(double x)
  1019. {
  1020. double f, i;
  1021. f = modf(x, &i);
  1022. /*
  1023. All doubles with absolute values > MAX_EXACT_INTEGER are even anyway,
  1024. no need to check it.
  1025. */
  1026. if (x > 0.0)
  1027. i += (double) ((f > 0.5) || (f == 0.5 &&
  1028. i <= (double) MAX_EXACT_INTEGER &&
  1029. (longlong) i % 2));
  1030. else
  1031. i -= (double) ((f < -0.5) || (f == -0.5 &&
  1032. i >= (double) -MAX_EXACT_INTEGER &&
  1033. (longlong) i % 2));
  1034. return i;
  1035. }
  1036. #endif /* HAVE_RINT */
  1037. /*
  1038. MYSQL_PLUGIN_IMPORT macro is used to export mysqld data
  1039. (i.e variables) for usage in storage engine loadable plugins.
  1040. Outside of Windows, it is dummy.
  1041. */
  1042. #ifndef MYSQL_PLUGIN_IMPORT
  1043. #if (defined(_WIN32) && defined(MYSQL_DYNAMIC_PLUGIN))
  1044. #define MYSQL_PLUGIN_IMPORT __declspec(dllimport)
  1045. #else
  1046. #define MYSQL_PLUGIN_IMPORT
  1047. #endif
  1048. #endif
  1049. /* Defines that are unique to the embedded version of MySQL */
  1050. #ifdef EMBEDDED_LIBRARY
  1051. /* Things we don't need in the embedded version of MySQL */
  1052. /* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */
  1053. #undef HAVE_SMEM /* No shared memory */
  1054. #else
  1055. #define HAVE_REPLICATION
  1056. #define HAVE_EXTERNAL_CLIENT
  1057. #endif /* EMBEDDED_LIBRARY */
  1058. /* Workaround for _LARGE_FILES and _LARGE_FILE_API incompatibility on AIX */
  1059. #if defined(_AIX) && defined(_LARGE_FILE_API)
  1060. #undef _LARGE_FILE_API
  1061. #undef __GNUG__
  1062. #endif
  1063. #endif /* my_global_h */