my_global.h 41 KB

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