my_global.h 49.4 KB
Newer Older
1
/* Copyright (C) 2000-2003 MySQL AB
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2 3 4

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6 7

   This program is distributed in the hope that it will be useful,
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
9 10 11 12 13 14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
15

16
/* This is the include file that should be included 'first' in every C file. */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
17 18 19 20

#ifndef _global_h
#define _global_h

21 22 23 24 25 26 27 28 29 30 31
/*
  InnoDB depends on some MySQL internals which other plugins should not
  need.  This is because of InnoDB's foreign key support, "safe" binlog
  truncation, and other similar legacy features.

  We define accessors for these internals unconditionally, but do not
  expose them in mysql/plugin.h.  They are declared in ha_innodb.h for
  InnoDB's use.
*/
#define INNODB_COMPATIBILITY_HOOKS

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
32 33 34 35 36 37 38 39 40 41 42 43
#ifdef __CYGWIN__
/* We use a Unix API, so pretend it's not Windows */
#undef WIN
#undef WIN32
#undef _WIN
#undef _WIN32
#undef _WIN64
#undef __WIN__
#undef __WIN32__
#define HAVE_ERRNO_AS_DEFINE
#endif /* __CYGWIN__ */

44 45 46 47 48 49 50 51 52
#if defined(__QNXNTO__) && !defined(FD_SETSIZE)
#define FD_SETSIZE 1024         /* Max number of file descriptor bits in
                                   fd_set, used when calling 'select'
                                   Must be defined before including
                                   "sys/select.h" and "sys/time.h"
                                 */
#endif


53 54
/* to make command line shorter we'll define USE_PRAGMA_INTERFACE here */
#ifdef USE_PRAGMA_IMPLEMENTATION
55 56 57
#define USE_PRAGMA_INTERFACE
#endif

monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
58 59 60 61
#if defined(i386) && !defined(__i386__)
#define __i386__
#endif

62 63 64 65 66 67 68 69
/* Macros to make switching between C and C++ mode easier */
#ifdef __cplusplus
#define C_MODE_START    extern "C" {
#define C_MODE_END	}
#else
#define C_MODE_START
#define C_MODE_END
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
70 71 72

#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
#include <config-win.h>
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
73 74 75 76 77 78
#elif defined(__NETWARE__)
#include <my_config.h>
#include <config-netware.h>
#if defined(__cplusplus) && defined(inline)
#undef inline				/* fix configure problem */
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
79 80 81 82 83 84 85
#else
#include <my_config.h>
#if defined(__cplusplus) && defined(inline)
#undef inline				/* fix configure problem */
#endif
#endif /* _WIN32... */

86 87 88 89 90 91 92
/* Make it easier to add conditionl code for windows */
#ifdef __WIN__
#define IF_WIN(A,B) (A)
#else
#define IF_WIN(A,B) (B)
#endif

93 94 95 96 97 98
#ifndef EMBEDDED_LIBRARY
#ifdef WITH_NDB_BINLOG
#define HAVE_NDB_BINLOG 1
#endif
#endif /* !EMBEDDED_LIBRARY */

99 100 101 102 103
#ifndef EMBEDDED_LIBRARY
#define HAVE_REPLICATION
#define HAVE_EXTERNAL_CLIENT
#endif

monty@mysql.com's avatar
monty@mysql.com committed
104 105 106 107
/* Some defines to avoid ifdefs in the code */
#ifndef NETWARE_YIELD
#define NETWARE_YIELD
#define NETWARE_SET_SCREEN_MODE(A)
108 109
#endif

110 111 112 113 114
/* Workaround for _LARGE_FILES and _LARGE_FILE_API incompatibility on AIX */
#if defined(_AIX) && defined(_LARGE_FILE_API)
#undef _LARGE_FILE_API
#endif

mmj@tiger.mmj.dk's avatar
mmj@tiger.mmj.dk committed
115 116 117 118
/*
  The macros below are used to allow build of Universal/fat binaries of
  MySQL and MySQL applications under darwin. 
*/
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
#if defined(__APPLE__) && defined(__MACH__)
#  undef SIZEOF_CHARP 
#  undef SIZEOF_SHORT 
#  undef SIZEOF_INT 
#  undef SIZEOF_LONG 
#  undef SIZEOF_LONG_LONG 
#  undef SIZEOF_OFF_T 
#  undef WORDS_BIGENDIAN
#  define SIZEOF_SHORT 2
#  define SIZEOF_INT 4
#  define SIZEOF_LONG_LONG 8
#  define SIZEOF_OFF_T 8
#  if defined(__i386__) || defined(__ppc__)
#    define SIZEOF_CHARP 4
#    define SIZEOF_LONG 4
#  elif defined(__x86_64__) || defined(__ppc64__)
#    define SIZEOF_CHARP 8
#    define SIZEOF_LONG 8
#  else
#    error Building FAT binary for an unknown architecture.
#  endif
#  if defined(__ppc__) || defined(__ppc64__)
#    define WORDS_BIGENDIAN
#  endif
#endif /* defined(__APPLE__) && defined(__MACH__) */
mmj@tiger.mmj.dk's avatar
mmj@tiger.mmj.dk committed
144 145


monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
146 147 148 149 150 151 152
/*
  The macros below are borrowed from include/linux/compiler.h in the
  Linux kernel. Use them to indicate the likelyhood of the truthfulness
  of a condition. This serves two purposes - newer versions of gcc will be
  able to optimize for branch predication, which could yield siginficant
  performance gains in frequently executed sections of the code, and the
  other reason to use them is for documentation
153 154
*/

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
155
#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
156 157 158 159 160 161 162
#define __builtin_expect(x, expected_value) (x)
#endif

#define likely(x)	__builtin_expect((x),1)
#define unlikely(x)	__builtin_expect((x),0)


163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
/*
  The macros below are useful in optimising places where it has been
  discovered that cache misses stall the process and where a prefetch
  of the cache line can improve matters. This is available in GCC 3.1.1
  and later versions.
  PREFETCH_READ says that addr is going to be used for reading and that
  it is to be kept in caches if possible for a while
  PREFETCH_WRITE also says that the item to be cached is likely to be
  updated.
  The *LOCALITY scripts are also available for experimentation purposes
  mostly and should only be used if they are verified to improve matters.
  For more input see GCC manual (available in GCC 3.1.1 and later)
*/

#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
#define PREFETCH_READ(addr) __builtin_prefetch(addr, 0, 3)
#define PREFETCH_WRITE(addr) \
  __builtin_prefetch(addr, 1, 3)
#define PREFETCH_READ_LOCALITY(addr, locality) \
  __builtin_prefetch(addr, 0, locality)
#define PREFETCH_WRITE_LOCALITY(addr, locality) \
  __builtin_prefetch(addr, 1, locality)
#else
#define PREFETCH_READ(addr)
#define PREFETCH_READ_LOCALITY(addr, locality)
#define PREFETCH_WRITE(addr)
#define PREFETCH_WRITE_LOCALITY(addr, locality)
#endif

/*
  The following macro is used to ensure that code often used in most
  SQL statements and definitely for parts of the SQL processing are
  kept in a code segment by itself. This has the advantage that the
  risk of common code being overlapping in caches of the CPU is less.
  This can be a cause of big performance problems.
  Routines should be put in this category with care and when they are
  put there one should also strive to make as much of the error handling
  as possible (or uncommon code of the routine) to execute in a
  separate method to avoid moving to much code to this code segment.

  It is very easy to use, simply add HOT_METHOD at the end of the
  function declaration.
  For more input see GCC manual (available in GCC 2.95 and later)
*/

#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
#define HOT_METHOD \
  __attribute__ ((section ("hot_code_section")))
#else
#define HOT_METHOD
#endif

/*
  The following macro is used to ensure that popular global variables
  are located next to each other to avoid that they contend for the
  same cache lines.

  It is very easy to use, simply add HOT_DATA at the end of the declaration
  of the variable, the variable must be initialised because of the way
  that linker works so a declaration using HOT_DATA should look like:
  uint global_hot_data HOT_DATA = 0;
  For more input see GCC manual (available in GCC 2.95 and later)
*/

#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
#define HOT_DATA \
  __attribute__ ((section ("hot_data_section")))
#else
#define HOT_DATA
#endif

234 235 236 237 238 239 240 241 242 243 244
/*
  now let's figure out if inline functions are supported
  autoconf defines 'inline' to be empty, if not
*/
#define inline_test_1(X)        X ## 1
#define inline_test_2(X)        inline_test_1(X)
#if inline_test_2(inline) != 1
#define HAVE_INLINE
#endif
#undef inline_test_2
#undef inline_test_1
245 246
/* helper macro for "instantiating" inline functions */
#define STATIC_INLINE static inline
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263

/*
  The following macros are used to control inlining a bit more than
  usual. These macros are used to ensure that inlining always or
  never occurs (independent of compilation mode).
  For more input see GCC manual (available in GCC 3.1.1 and later)
*/

#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
#define ALWAYS_INLINE __attribute__ ((always_inline))
#define NEVER_INLINE __attribute__ ((noinline))
#else
#define ALWAYS_INLINE
#define NEVER_INLINE
#endif


monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
264
/* Fix problem with S_ISLNK() on Linux */
265
#if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
266 267 268 269
#undef  _GNU_SOURCE
#define _GNU_SOURCE 1
#endif

270 271 272 273 274 275 276 277
/*
  Temporary solution to solve bug#7156. Include "sys/types.h" before
  the thread headers, else the function madvise() will not be defined
*/
#if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
#include <sys/types.h>
#endif

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
278 279 280 281
/* The client defines this to avoid all thread code */
#if defined(UNDEF_THREADS_HACK)
#undef THREAD
#undef HAVE_LINUXTHREADS
282
#undef HAVE_NPTL
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
283 284 285 286 287 288 289 290 291 292 293 294
#endif

#ifdef HAVE_THREADS_WITHOUT_SOCKETS
/* MIT pthreads does not work with unix sockets */
#undef HAVE_SYS_UN_H
#endif

#define __EXTENSIONS__ 1	/* We want some extension */
#ifndef __STDC_EXT__
#define __STDC_EXT__ 1          /* To get large file support on hpux */
#endif

serg@serg.mylan's avatar
serg@serg.mylan committed
295
/*
296
  Solaris 9 include file <sys/feature_tests.h> refers to X/Open document
serg@serg.mylan's avatar
serg@serg.mylan committed
297 298 299

    System Interfaces and Headers, Issue 5

300
  saying we should define _XOPEN_SOURCE=500 to get POSIX.1c prototypes,
serg@serg.mylan's avatar
serg@serg.mylan committed
301
  but apparently other systems (namely FreeBSD) don't agree.
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317

  On a newer Solaris 10, the above file recognizes also _XOPEN_SOURCE=600.
  Furthermore, it tests that if a program requires older standard
  (_XOPEN_SOURCE<600 or _POSIX_C_SOURCE<200112L) it cannot be
  run on a new compiler (that defines _STDC_C99) and issues an #error.
  It's also an #error if a program requires new standard (_XOPEN_SOURCE=600
  or _POSIX_C_SOURCE=200112L) and a compiler does not define _STDC_C99.

  To add more to this mess, Sun Studio C compiler defines _STDC_C99 while
  C++ compiler does not!

  So, in a desperate attempt to get correct prototypes for both
  C and C++ code, we define either _XOPEN_SOURCE=600 or _XOPEN_SOURCE=500
  depending on the compiler's announced C standard support.

  Cleaner solutions are welcome.
serg@serg.mylan's avatar
serg@serg.mylan committed
318
*/
319
#ifdef __sun
320 321 322
#if __STDC_VERSION__ - 0 >= 199901L
#define _XOPEN_SOURCE 600
#else
serg@serg.mylan's avatar
serg@serg.mylan committed
323 324
#define _XOPEN_SOURCE 500
#endif
325
#endif
serg@serg.mylan's avatar
serg@serg.mylan committed
326

327
#if defined(THREAD) && !defined(__WIN__)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
328 329 330
#ifndef _POSIX_PTHREAD_SEMANTICS
#define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
#endif
331

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
332 333 334 335 336 337
#if !defined(SCO)
#define _REENTRANT	1	/* Some thread libraries require this */
#endif
#if !defined(_THREAD_SAFE) && !defined(_AIX)
#define _THREAD_SAFE            /* Required for OSF1 */
#endif
338 339 340 341 342
#if defined(HPUX10) || defined(HPUX11)
C_MODE_START			/* HPUX needs this, signal.h bug */
#include <pthread.h>
C_MODE_END
#else
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
343
#include <pthread.h>		/* AIX must have this included first */
344
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
345 346 347 348 349 350 351 352 353
#if !defined(SCO) && !defined(_REENTRANT)
#define _REENTRANT	1	/* Threads requires reentrant code */
#endif
#endif /* THREAD */

/* Go around some bugs in different OS and compilers */
#ifdef _AIX			/* By soren@t.dk */
#define _H_STRINGS
#define _SYS_STREAM_H
354
/* #define _AIX32_CURSES */	/* XXX: this breaks AIX 4.3.3 (others?). */
355 356
#define ulonglong2double(A) my_ulonglong2double(A)
#define my_off_t2double(A)  my_ulonglong2double(A)
357
C_MODE_START
358
double my_ulonglong2double(unsigned long long A);
359
C_MODE_END
360
#endif /* _AIX */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
361 362 363 364

#ifdef HAVE_BROKEN_SNPRINTF	/* HPUX 10.20 don't have this defined */
#undef HAVE_SNPRINTF
#endif
365 366 367 368 369
#ifdef HAVE_BROKEN_PREAD
/*
  pread()/pwrite() are not 64 bit safe on HP-UX 11.0 without
  installing the kernel patch PHKL_20349 or greater
*/
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
370 371 372
#undef HAVE_PREAD
#undef HAVE_PWRITE
#endif
373 374 375 376
#if defined(HAVE_BROKEN_INLINE) && !defined(__cplusplus)
#undef inline
#define inline
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
377 378 379 380 381 382 383 384

#ifdef UNDEF_HAVE_GETHOSTBYNAME_R		/* For OSF4.x */
#undef HAVE_GETHOSTBYNAME_R
#endif
#ifdef UNDEF_HAVE_INITGROUPS			/* For AIX 4.3 */
#undef HAVE_INITGROUPS
#endif

385 386 387 388 389 390 391
/* gcc/egcs issues */

#if defined(__GNUC) && defined(__EXCEPTIONS)
#error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
#endif


monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
392
/* Fix a bug in gcc 2.8.0 on IRIX 6.2 */
393
#if SIZEOF_LONG == 4 && defined(__LONG_MAX__) && (__GNUC__ == 2 && __GNUC_MINOR__ == 8)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
#undef __LONG_MAX__             /* Is a longlong value in gcc 2.8.0 ??? */
#define __LONG_MAX__ 2147483647
#endif

/* egcs 1.1.2 has a problem with memcpy on Alpha */
#if defined(__GNUC__) && defined(__alpha__) && ! (__GNUC__ > 2 || (__GNUC__ == 2 &&  __GNUC_MINOR__ >= 95))
#define BAD_MEMCPY
#endif

#if defined(_lint) && !defined(lint)
#define lint
#endif
#if SIZEOF_LONG_LONG > 4 && !defined(_LONG_LONG)
#define _LONG_LONG 1		/* For AIX string library */
#endif

#ifndef stdin
#include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif

#include <math.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef HAVE_FLOAT_H
#include <float.h>
#endif

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_SYS_TIMEB_H
#include <sys/timeb.h>				/* Avoid warnings on SCO */
#endif
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif /* TIME_WITH_SYS_TIME */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
#undef HAVE_ALLOCA
#undef HAVE_ALLOCA_H
#endif
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
457

458
#include <errno.h>				/* Recommended by debian */
459
/* We need the following to go around a problem with openssl on solaris */
460
#if defined(HAVE_CRYPT_H)
461 462
#include <crypt.h>
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
463

464 465 466 467 468 469 470
/*
  A lot of our programs uses asserts, so better to always include it
  This also fixes a problem when people uses DBUG_ASSERT without including
  assert.h
*/
#include <assert.h>

antony@ppcg5.local's avatar
antony@ppcg5.local committed
471
/* an assert that works at compile-time. only for constant expression */
472
#ifndef __GNUC__
473 474
#define compile_time_assert(X)  do { } while(0)
#else
antony@ppcg5.local's avatar
antony@ppcg5.local committed
475 476 477 478 479 480
#define compile_time_assert(X)                                  \
  do                                                            \
  {                                                             \
    char compile_time_assert[(X) ? 1 : -1]                      \
                             __attribute__ ((unused));          \
  } while(0)
481
#endif
antony@ppcg5.local's avatar
antony@ppcg5.local committed
482

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
483
/* Go around some bugs in different OS and compilers */
kent@mysql.com's avatar
kent@mysql.com committed
484 485 486
#if defined (HPUX11) && defined(_LARGEFILE_SOURCE)
#define _LARGEFILE64_SOURCE
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
487 488 489 490
#if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H)
#include <sys/stream.h>		/* HPUX 10.20 defines ulong here. UGLY !!! */
#define HAVE_ULONG
#endif
491
#if defined(HPUX10) && defined(_LARGEFILE64_SOURCE) && defined(THREAD)
492 493 494 495
/* Fix bug in setrlimit */
#undef setrlimit
#define setrlimit cma_setrlimit64
#endif
496 497 498 499
/* Declare madvise where it is not declared for C++, like Solaris */
#if HAVE_MADVISE && !HAVE_DECL_MADVISE && defined(__cplusplus)
extern "C" int madvise(void *addr, size_t len, int behav);
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
500

501 502 503 504 505 506 507
#ifdef __QNXNTO__
/* This has to be after include limits.h */
#define HAVE_ERRNO_AS_DEFINE
#define HAVE_FCNTL_LOCK
#undef  HAVE_FINITE
#undef  LONGLONG_MIN            /* These get wrongly defined in QNX 6.2 */
#undef  LONGLONG_MAX            /* standard system library 'limits.h' */
508
#ifdef __cplusplus
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
509 510 511
#ifndef HAVE_RINT
#define HAVE_RINT
#endif                          /* rint() and isnan() functions are not */
512 513 514
#define rint(a) std::rint(a)    /* visible in C++ scope due to an error */
#define isnan(a) std::isnan(a)  /* in the usr/include/math.h on QNX     */
#endif
515 516
#endif

517
/* We can not live without the following defines */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
518 519 520 521 522 523 524

#define USE_MYFUNC 1		/* Must use syscall indirection */
#define MASTER 1		/* Compile without unireg */
#define ENGLISH 1		/* Messages in English */
#define POSIX_MISTAKE 1		/* regexp: Fix stupid spec error */
#define USE_REGEX 1		/* We want the use the regex library */
/* Do not define for ultra sparcs */
525
#define USE_BMOVE512 1		/* Use this unless system bmove is faster */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
526

527 528 529
#define QUOTE_ARG(x)		#x	/* Quote argument (before cpp) */
#define STRINGIFY_ARG(x) QUOTE_ARG(x)	/* Quote argument, after cpp */

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
/* Paranoid settings. Define I_AM_PARANOID if you are paranoid */
#ifdef I_AM_PARANOID
#define DONT_ALLOW_USER_CHANGE 1
#define DONT_USE_MYSQL_PWD 1
#endif

/* Does the system remember a signal handler after a signal ? */
#ifndef HAVE_BSD_SIGNALS
#define DONT_REMEMBER_SIGNAL
#endif

/* Define void to stop lint from generating "null effekt" comments */
#ifndef DONT_DEFINE_VOID
#ifdef _lint
int	__void__;
#define VOID(X)		(__void__ = (int) (X))
#else
#undef VOID
#define VOID(X)		(X)
#endif
#endif /* DONT_DEFINE_VOID */

#if defined(_lint) || defined(FORCE_INIT_OF_VARS)
#define LINT_INIT(var)	var=0			/* No uninitialize-warning */
#else
#define LINT_INIT(var)
#endif

558 559 560 561 562 563
#if defined(_lint) || defined(FORCE_INIT_OF_VARS) || defined(HAVE_purify)
#define PURIFY_OR_LINT_INIT(var) var=0
#else
#define PURIFY_OR_LINT_INIT(var)
#endif

564
#if !defined(HAVE_UINT)
565 566
#undef HAVE_UINT
#define HAVE_UINT
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
567 568 569 570
typedef unsigned int uint;
typedef unsigned short ushort;
#endif

571
#define CMP_NUM(a,b)    (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
572
#define sgn(a)		(((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
573
#define swap_variables(t, a, b) { t dummy; dummy= a; a= b; b= dummy; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
574
#define test(a)		((a) ? 1 : 0)
575 576
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
577
#define test_all_bits(a,b) (((a) & (b)) == (b))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
578
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
579 580
#define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
#ifndef HAVE_RINT
mysqldev@build.mysql2.com's avatar
mysqldev@build.mysql2.com committed
581
#define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
582 583
#endif

584
/* Define some general constants */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
585 586 587 588 589 590 591 592 593
#ifndef TRUE
#define TRUE		(1)	/* Logical true */
#define FALSE		(0)	/* Logical false */
#endif

#if defined(__GNUC__)
#define function_volatile	volatile
#define my_reinterpret_cast(A) reinterpret_cast<A>
#define my_const_cast(A) const_cast<A>
594 595 596
# ifndef GCC_VERSION
#  define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
# endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
597 598 599 600
#elif !defined(my_reinterpret_cast)
#define my_reinterpret_cast(A) (A)
#define my_const_cast(A) (A)
#endif
601

602
#include <my_attribute.h>
603

kent@mysql.com's avatar
kent@mysql.com committed
604 605
/*
  Wen using the embedded library, users might run into link problems,
606
  duplicate declaration of __cxa_pure_virtual, solved by declaring it a
kent@mysql.com's avatar
kent@mysql.com committed
607 608
  weak symbol.
*/
609
#if defined(USE_MYSYS_NEW) && ! defined(DONT_DECLARE_CXA_PURE_VIRTUAL)
kent@mysql.com's avatar
kent@mysql.com committed
610 611 612 613 614
C_MODE_START
int __cxa_pure_virtual () __attribute__ ((weak));
C_MODE_END
#endif

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
615 616
/* From old s-system.h */

617 618 619 620 621
/*
  Support macros for non ansi & other old compilers. Since such
  things are no longer supported we do nothing. We keep then since
  some of our code may still be needed to upgrade old customers.
*/
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
622 623 624 625
#define _VARARGS(X) X
#define _STATIC_VARARGS(X) X
#define _PC(X)	X

626
/* The DBUG_ON flag always takes precedence over default DBUG_OFF */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
627 628 629 630
#if defined(DBUG_ON) && defined(DBUG_OFF)
#undef DBUG_OFF
#endif

631 632 633 634 635 636
/* We might be forced to turn debug off, if not turned off already */
#if (defined(FORCE_DBUG_OFF) || defined(_lint)) && !defined(DBUG_OFF)
#  define DBUG_OFF
#  ifdef DBUG_ON
#    undef DBUG_ON
#  endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
637 638
#endif

639
#include <my_dbug.h>
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
640 641 642 643 644 645 646 647 648 649 650 651 652 653

#define MIN_ARRAY_SIZE	0	/* Zero or One. Gcc allows zero*/
#define ASCII_BITS_USED 8	/* Bit char used */
#define NEAR_F			/* No near function handling */

/* Some types that is different between systems */

typedef int	File;		/* File descriptor */
#ifndef Socket_defined
typedef int	my_socket;	/* File descriptor for sockets */
#define INVALID_SOCKET -1
#endif
/* Type for fuctions that handles signals */
#define sig_handler RETSIGTYPE
654
C_MODE_START
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
655
typedef void	(*sig_return)();/* Returns type from signal */
656
C_MODE_END
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
657 658 659 660 661 662 663 664 665 666 667 668 669
#if defined(__GNUC__) && !defined(_lint)
typedef char	pchar;		/* Mixed prototypes can take char */
typedef char	puchar;		/* Mixed prototypes can take char */
typedef char	pbool;		/* Mixed prototypes can take char */
typedef short	pshort;		/* Mixed prototypes can take short int */
typedef float	pfloat;		/* Mixed prototypes can take float */
#else
typedef int	pchar;		/* Mixed prototypes can't take char */
typedef uint	puchar;		/* Mixed prototypes can't take char */
typedef int	pbool;		/* Mixed prototypes can't take char */
typedef int	pshort;		/* Mixed prototypes can't take short int */
typedef double	pfloat;		/* Mixed prototypes can't take float */
#endif
670
C_MODE_START
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
671 672
typedef int	(*qsort_cmp)(const void *,const void *);
typedef int	(*qsort_cmp2)(void*, const void *,const void *);
673
C_MODE_END
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
674 675 676 677
#define qsort_t RETQSORTTYPE	/* Broken GCC cant handle typedef !!!! */
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
678
typedef SOCKET_SIZE_TYPE size_socket;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
679 680 681 682 683 684 685

#ifndef SOCKOPT_OPTLEN_TYPE
#define SOCKOPT_OPTLEN_TYPE size_socket
#endif

/* file create flags */

monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
686
#ifndef O_SHARE			/* Probably not windows */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
687 688 689 690
#define O_SHARE		0	/* Flag to my_open for shared files */
#ifndef O_BINARY
#define O_BINARY	0	/* Flag to my_open for binary files */
#endif
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
691 692 693
#ifndef FILE_BINARY
#define FILE_BINARY	O_BINARY /* Flag to my_fopen for binary streams */
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
694 695 696 697 698
#ifdef HAVE_FCNTL
#define HAVE_FCNTL_LOCK
#define F_TO_EOF	0L	/* Param to lockf() to lock rest of file */
#endif
#endif /* O_SHARE */
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
699

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
700 701 702 703 704 705
#ifndef O_TEMPORARY
#define O_TEMPORARY	0
#endif
#ifndef O_SHORT_LIVED
#define O_SHORT_LIVED	0
#endif
706 707 708
#ifndef O_NOFOLLOW
#define O_NOFOLLOW      0
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
709

710 711 712 713 714 715 716 717 718
/* additional file share flags for win32 */
#ifdef __WIN__
#define _SH_DENYRWD     0x110    /* deny read/write mode & delete */
#define _SH_DENYWRD     0x120    /* deny write mode & delete      */
#define _SH_DENYRDD     0x130    /* deny read mode & delete       */
#define _SH_DENYDEL     0x140    /* deny delete only              */
#endif /* __WIN__ */


monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
/* #define USE_RECORD_LOCK	*/

	/* Unsigned types supported by the compiler */
#define UNSINT8			/* unsigned int8 (char) */
#define UNSINT16		/* unsigned int16 */
#define UNSINT32		/* unsigned int32 */

	/* General constants */
#define SC_MAXWIDTH	256	/* Max width of screen (for error messages) */
#define FN_LEN		256	/* Max file name len */
#define FN_HEADLEN	253	/* Max length of filepart of file name */
#define FN_EXTLEN	20	/* Max length of extension (part of FN_LEN) */
#define FN_REFLEN	512	/* Max length of full path-name */
#define FN_EXTCHAR	'.'
#define FN_HOMELIB	'~'	/* ~/ is used as abbrev for home dir */
#define FN_CURLIB	'.'	/* ./ is used as abbrev for current dir */
serg@serg.mylan's avatar
serg@serg.mylan committed
735
#define FN_PARENTDIR	".."	/* Parent directory; Must be a string */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
736 737 738 739 740

#ifndef FN_LIBCHAR
#define FN_LIBCHAR	'/'
#define FN_ROOTDIR	"/"
#endif
741 742 743
#define MY_NFILE	64	/* This is only used to save filenames */
#ifndef OS_FILE_LIMIT
#define OS_FILE_LIMIT	65535
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
744 745 746 747 748 749
#endif

/* #define EXT_IN_LIBNAME     */
/* #define FN_NO_CASE_SENCE   */
/* #define FN_UPPER_CASE TRUE */

750 751 752 753 754
/*
  Io buffer size; Must be a power of 2 and a multiple of 512. May be
  smaller what the disk page size. This influences the speed of the
  isam btree library. eg to big to slow.
*/
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
755
#define IO_SIZE			4096
756 757 758 759
/*
  How much overhead does malloc have. The code often allocates
  something like 1024-MALLOC_OVERHEAD bytes
*/
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
760 761 762 763 764 765 766 767 768 769 770
#ifdef SAFEMALLOC
#define MALLOC_OVERHEAD (8+24+4)
#else
#define MALLOC_OVERHEAD 8
#endif
	/* get memory in huncs */
#define ONCE_ALLOC_INIT		(uint) (4096-MALLOC_OVERHEAD)
	/* Typical record cash */
#define RECORD_CACHE_SIZE	(uint) (64*1024-MALLOC_OVERHEAD)
	/* Typical key cash */
#define KEY_CACHE_SIZE		(uint) (8*1024*1024-MALLOC_OVERHEAD)
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
771 772 773
	/* Default size of a key cache block  */
#define KEY_CACHE_BLOCK_SIZE	(uint) 1024

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788

	/* Some things that this system doesn't have */

#define NO_HASH			/* Not needed anymore */
#ifdef __WIN__
#define NO_DIR_LIBRARY		/* Not standar dir-library */
#define USE_MY_STAT_STRUCT	/* For my_lib */
#endif

/* Some defines of functions for portability */

#undef remove		/* Crashes MySQL on SCO 5.0.0 */
#ifndef __WIN__
#define closesocket(A)	close(A)
#ifndef ulonglong2double
789 790
#define ulonglong2double(A) ((double) (ulonglong) (A))
#define my_off_t2double(A)  ((double) (my_off_t) (A))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
791
#endif
792 793 794
#ifndef double2ulonglong
#define double2ulonglong(A) ((ulonglong) (double) (A))
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
795 796 797 798 799 800 801 802
#endif

#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#define ulong_to_double(X) ((double) (ulong) (X))
#define SET_STACK_SIZE(X)	/* Not needed on real machines */

803 804 805 806
#ifndef STACK_DIRECTION
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
#endif

807
#if !defined(HAVE_STRTOK_R)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
808 809 810 811 812 813 814 815 816
#define strtok_r(A,B,C) strtok((A),(B))
#endif

/* This is from the old m-machine.h file */

#if SIZEOF_LONG_LONG > 4
#define HAVE_LONG_LONG 1
#endif

817 818 819
/*
  Some pre-ANSI-C99 systems like AIX 5.1 and Linux/GCC 2.95 define
  ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined.
820
  Also on Windows we define these constants by hand in config-win.h.
821 822
*/

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
823 824 825 826 827
#if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
#define LONGLONG_MIN	((long long) 0x8000000000000000LL)
#define LONGLONG_MAX	((long long) 0x7FFFFFFFFFFFFFFFLL)
#endif

konstantin@mysql.com's avatar
konstantin@mysql.com committed
828
#if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
829 830 831 832 833 834
/* First check for ANSI C99 definition: */
#ifdef ULLONG_MAX
#define ULONGLONG_MAX  ULLONG_MAX
#else
#define ULONGLONG_MAX ((unsigned long long)(~0ULL))
#endif
konstantin@mysql.com's avatar
konstantin@mysql.com committed
835
#endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/
836

837 838 839 840 841 842 843
#define INT_MIN32       (~0x7FFFFFFFL)
#define INT_MAX32       0x7FFFFFFFL
#define UINT_MAX32      0xFFFFFFFFL
#define INT_MIN24       (~0x007FFFFF)
#define INT_MAX24       0x007FFFFF
#define UINT_MAX24      0x00FFFFFF
#define INT_MIN16       (~0x7FFF)
844 845
#define INT_MAX16       0x7FFF
#define UINT_MAX16      0xFFFF
846 847
#define INT_MIN8        (~0x7F)
#define INT_MAX8        0x7F
848
#define UINT_MAX8       0xFF
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
849 850 851 852 853 854 855 856 857 858

/* From limits.h instead */
#ifndef DBL_MIN
#define DBL_MIN		4.94065645841246544e-324
#define FLT_MIN		((float)1.40129846432481707e-45)
#endif
#ifndef DBL_MAX
#define DBL_MAX		1.79769313486231470e+308
#define FLT_MAX		((float)3.40282346638528860e+38)
#endif
859 860
#ifndef SIZE_T_MAX
#define SIZE_T_MAX ~((size_t) 0)
861
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
862

863 864 865 866
#ifndef isfinite
#ifdef HAVE_FINITE
#define isfinite(x) finite(x)
#else
867
#define finite(x) (1.0 / fabs(x) > 0.0)
868 869
#endif /* HAVE_FINITE */
#endif /* isfinite */
870 871 872 873 874

#ifndef HAVE_ISNAN
#define isnan(x) ((x) != (x))
#endif

875 876 877 878
#ifdef HAVE_ISINF
/* isinf() can be used in both C and C++ code */
#define my_isinf(X) isinf(X)
#else
879
#define my_isinf(X) (!isfinite(X) && !isnan(X))
serg@serg.mylan's avatar
serg@serg.mylan committed
880 881
#endif

882 883 884 885 886 887 888 889 890 891 892
/* Define missing math constants. */
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.7182818284590452354
#endif
#ifndef M_LN2
#define M_LN2 0.69314718055994530942
#endif

893 894 895 896
/*
  Max size that must be added to a so that we know Size to make
  adressable obj.
*/
897
#if SIZEOF_CHARP == 4
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
898
typedef long		my_ptrdiff_t;
899 900 901 902
#else
typedef long long	my_ptrdiff_t;
#endif

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
903 904 905 906
#define MY_ALIGN(A,L)	(((A) + (L) - 1) & ~((L) - 1))
#define ALIGN_SIZE(A)	MY_ALIGN((A),sizeof(double))
/* Size to make adressable obj. */
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
907
			 /* Offset of field f in structure t */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
908
#define OFFSET(t, f)	((size_t)(char *)&((t *)0)->f)
909 910
#define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
911

912 913 914
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]

915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
/*
  Custom version of standard offsetof() macro which can be used to get
  offsets of members in class for non-POD types (according to the current
  version of C++ standard offsetof() macro can't be used in such cases and
  attempt to do so causes warnings to be emitted, OTOH in many cases it is
  still OK to assume that all instances of the class has the same offsets
  for the same members).

  This is temporary solution which should be removed once File_parser class
  and related routines are refactored.
*/

#define my_offsetof(TYPE, MEMBER) \
        ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
930 931 932 933 934 935 936 937 938 939
#define NullS		(char *) 0
/* Nowdays we do not support MessyDos */
#ifndef NEAR
#define NEAR				/* Who needs segments ? */
#define FAR				/* On a good machine */
#ifndef HUGE_PTR
#define HUGE_PTR
#endif
#endif
#if defined(__IBMC__) || defined(__IBMCPP__)
940 941
/* This was  _System _Export but caused a lot of warnings on _AIX43 */
#define STDCALL
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
942 943 944 945 946 947 948 949 950 951
#elif !defined( STDCALL)
#define STDCALL
#endif

/* Typdefs for easyier portability */

#ifndef HAVE_UCHAR
typedef unsigned char	uchar;	/* Short for unsigned char */
#endif

serg@serg.mylan's avatar
serg@serg.mylan committed
952 953 954 955 956 957 958 959 960 961 962 963
#ifndef HAVE_INT8
typedef signed char int8;       /* Signed integer >= 8  bits */
#endif
#ifndef HAVE_UINT8
typedef unsigned char uint8;    /* Unsigned integer >= 8  bits */
#endif
#ifndef HAVE_INT16
typedef short int16;
#endif
#ifndef HAVE_UINT16
typedef unsigned short uint16;
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
964
#if SIZEOF_INT == 4
serg@serg.mylan's avatar
serg@serg.mylan committed
965 966 967 968 969
#ifndef HAVE_INT32
typedef int int32;
#endif
#ifndef HAVE_UINT32
typedef unsigned int uint32;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
970 971
#endif
#elif SIZEOF_LONG == 4
serg@serg.mylan's avatar
serg@serg.mylan committed
972 973 974 975 976
#ifndef HAVE_INT32
typedef long int32;
#endif
#ifndef HAVE_UINT32
typedef unsigned long uint32;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
977 978
#endif
#else
979
#error Neither int or long is of 4 bytes width
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
980 981
#endif

982
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
983
typedef unsigned long	ulong;		  /* Short for unsigned long */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
984 985
#endif
#ifndef longlong_defined
986 987 988 989 990 991
/* 
  Using [unsigned] long long is preferable as [u]longlong because we use 
  [unsigned] long long unconditionally in many places, 
  for example in constants with [U]LL suffix.
*/
#if defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 8
992 993
typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
typedef long long int	longlong;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
994
#else
995
typedef unsigned long	ulonglong;	  /* ulong or unsigned long long */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
996 997 998
typedef long		longlong;
#endif
#endif
serg@serg.mylan's avatar
serg@serg.mylan committed
999
#ifndef HAVE_INT64
1000
typedef longlong int64;
serg@serg.mylan's avatar
serg@serg.mylan committed
1001 1002
#endif
#ifndef HAVE_UINT64
1003
typedef ulonglong uint64;
serg@serg.mylan's avatar
serg@serg.mylan committed
1004
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1005

hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1006 1007 1008 1009 1010 1011 1012 1013
#if defined(NO_CLIENT_LONG_LONG)
typedef unsigned long my_ulonglong;
#elif defined (__WIN__)
typedef unsigned __int64 my_ulonglong;
#else
typedef unsigned long long my_ulonglong;
#endif

1014 1015 1016 1017
#if SIZEOF_CHARP == SIZEOF_INT
typedef int intptr;
#elif SIZEOF_CHARP == SIZEOF_LONG
typedef long intptr;
1018 1019
#elif SIZEOF_CHARP == SIZEOF_LONG_LONG
typedef long long intptr;
1020
#else
1021
#error sizeof(void *) is neither sizeof(int) nor sizeof(long) nor sizeof(long long)
1022 1023
#endif

1024 1025
#define MY_ERRPTR ((void*)(intptr)1)

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1026
#ifdef USE_RAID
1027 1028 1029 1030
/*
  The following is done with a if to not get problems with pre-processors
  with late define evaluation
*/
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
#if SIZEOF_OFF_T == 4
#define SYSTEM_SIZEOF_OFF_T 4
#else
#define SYSTEM_SIZEOF_OFF_T 8
#endif
#undef  SIZEOF_OFF_T
#define SIZEOF_OFF_T	    8
#else
#define SYSTEM_SIZEOF_OFF_T SIZEOF_OFF_T
#endif /* USE_RAID */

#if SIZEOF_OFF_T > 4
typedef ulonglong my_off_t;
#else
typedef unsigned long my_off_t;
#endif
#define MY_FILEPOS_ERROR	(~(my_off_t) 0)
1048
#if !defined(__WIN__)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1049 1050 1051 1052 1053
typedef off_t os_off_t;
#endif

#if defined(__WIN__)
#define socket_errno	WSAGetLastError()
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1054
#define SOCKET_EINTR	WSAEINTR
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1055
#define SOCKET_EAGAIN	WSAEINPROGRESS
1056
#define SOCKET_ETIMEDOUT WSAETIMEDOUT
1057
#define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
1058
#define SOCKET_EADDRINUSE WSAEADDRINUSE
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1059 1060 1061 1062 1063 1064 1065
#define SOCKET_ENFILE	ENFILE
#define SOCKET_EMFILE	EMFILE
#else /* Unix */
#define socket_errno	errno
#define closesocket(A)	close(A)
#define SOCKET_EINTR	EINTR
#define SOCKET_EAGAIN	EAGAIN
1066
#define SOCKET_ETIMEDOUT SOCKET_EINTR
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1067
#define SOCKET_EWOULDBLOCK EWOULDBLOCK
1068
#define SOCKET_EADDRINUSE EADDRINUSE
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1069 1070 1071 1072 1073 1074 1075 1076
#define SOCKET_ENFILE	ENFILE
#define SOCKET_EMFILE	EMFILE
#endif

typedef uint8		int7;	/* Most effective integer 0 <= x <= 127 */
typedef short		int15;	/* Most effective integer 0 <= x <= 32767 */
typedef int		myf;	/* Type of MyFlags in my_funcs */
typedef char		my_bool; /* Small bool */
1077
#if !defined(bool) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1078 1079 1080 1081 1082 1083 1084 1085
typedef char		bool;	/* Ordinary boolean values 0 1 */
#endif
	/* Macros for converting *constants* to the right type */
#define INT8(v)		(int8) (v)
#define INT16(v)	(int16) (v)
#define INT32(v)	(int32) (v)
#define MYF(v)		(myf) (v)

1086 1087 1088 1089 1090 1091 1092 1093
#ifndef LL
#ifdef HAVE_LONG_LONG
#define LL(A) A ## LL
#else
#define LL(A) A ## L
#endif
#endif

1094 1095 1096 1097 1098 1099 1100 1101
#ifndef ULL
#ifdef HAVE_LONG_LONG
#define ULL(A) A ## ULL
#else
#define ULL(A) A ## UL
#endif
#endif

1102 1103 1104 1105
/*
  Defines to make it possible to prioritize register assignments. No
  longer that important with modern compilers.
*/
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
#ifndef USING_X
#define reg1 register
#define reg2 register
#define reg3 register
#define reg4 register
#define reg5 register
#define reg6 register
#define reg7 register
#define reg8 register
#define reg9 register
#define reg10 register
#define reg11 register
#define reg12 register
#define reg13 register
#define reg14 register
#define reg15 register
#define reg16 register
#endif

1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
/*
  Sometimes we want to make sure that the variable is not put into
  a register in debugging mode so we can see its value in the core
*/

#ifndef DBUG_OFF
#define dbug_volatile volatile
#else
#define dbug_volatile
#endif

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1136 1137 1138 1139 1140 1141
/* Defines for time function */
#define SCALE_SEC	100
#define SCALE_USEC	10000
#define MY_HOW_OFTEN_TO_ALARM	2	/* How often we want info on screen */
#define MY_HOW_OFTEN_TO_WRITE	1000	/* How often we want info on screen */

1142

1143

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1144
/*
1145 1146
  Define-funktions for reading and storing in machine independent format
  (low byte first)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1147 1148 1149
*/

/* Optimized store functions for Intel x86 */
1150
#if defined(__i386__) || defined(_WIN32)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
#define sint2korr(A)	(*((int16 *) (A)))
#define sint3korr(A)	((int32) ((((uchar) (A)[2]) & 128) ? \
				  (((uint32) 255L << 24) | \
				   (((uint32) (uchar) (A)[2]) << 16) |\
				   (((uint32) (uchar) (A)[1]) << 8) | \
				   ((uint32) (uchar) (A)[0])) : \
				  (((uint32) (uchar) (A)[2]) << 16) |\
				  (((uint32) (uchar) (A)[1]) << 8) | \
				  ((uint32) (uchar) (A)[0])))
#define sint4korr(A)	(*((long *) (A)))
#define uint2korr(A)	(*((uint16 *) (A)))
1162
#if defined(HAVE_purify) && !defined(_WIN32)
1163 1164 1165 1166
#define uint3korr(A)	(uint32) (((uint32) ((uchar) (A)[0])) +\
				  (((uint32) ((uchar) (A)[1])) << 8) +\
				  (((uint32) ((uchar) (A)[2])) << 16))
#else
1167 1168 1169 1170 1171 1172 1173
/*
   ATTENTION !
   
    Please, note, uint3korr reads 4 bytes (not 3) !
    It means, that you have to provide enough allocated space !
*/
#define uint3korr(A)	(long) (*((unsigned int *) (A)) & 0xFFFFFF)
1174
#endif /* HAVE_purify && !_WIN32 */
1175
#define uint4korr(A)	(*((uint32 *) (A)))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1176 1177 1178 1179
#define uint5korr(A)	((ulonglong)(((uint32) ((uchar) (A)[0])) +\
				    (((uint32) ((uchar) (A)[1])) << 8) +\
				    (((uint32) ((uchar) (A)[2])) << 16) +\
				    (((uint32) ((uchar) (A)[3])) << 24)) +\
1180
				    (((ulonglong) ((uchar) (A)[4])) << 32))
1181 1182 1183 1184 1185 1186
#define uint6korr(A)	((ulonglong)(((uint32)    ((uchar) (A)[0]))          + \
                                     (((uint32)    ((uchar) (A)[1])) << 8)   + \
                                     (((uint32)    ((uchar) (A)[2])) << 16)  + \
                                     (((uint32)    ((uchar) (A)[3])) << 24)) + \
                         (((ulonglong) ((uchar) (A)[4])) << 32) +       \
                         (((ulonglong) ((uchar) (A)[5])) << 40))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1187 1188 1189
#define uint8korr(A)	(*((ulonglong *) (A)))
#define sint8korr(A)	(*((longlong *) (A)))
#define int2store(T,A)	*((uint16*) (T))= (uint16) (A)
1190 1191 1192
#define int3store(T,A)  do { *(T)=  (uchar) ((A));\
                            *(T+1)=(uchar) (((uint) (A) >> 8));\
                            *(T+2)=(uchar) (((A) >> 16)); } while (0)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1193
#define int4store(T,A)	*((long *) (T))= (long) (A)
1194 1195 1196 1197 1198
#define int5store(T,A)  do { *(T)= (uchar)((A));\
                             *((T)+1)=(uchar) (((A) >> 8));\
                             *((T)+2)=(uchar) (((A) >> 16));\
                             *((T)+3)=(uchar) (((A) >> 24)); \
                             *((T)+4)=(uchar) (((A) >> 32)); } while(0)
1199 1200 1201 1202 1203 1204
#define int6store(T,A)  do { *(T)=    (uchar)((A));          \
                             *((T)+1)=(uchar) (((A) >> 8));  \
                             *((T)+2)=(uchar) (((A) >> 16)); \
                             *((T)+3)=(uchar) (((A) >> 24)); \
                             *((T)+4)=(uchar) (((A) >> 32)); \
                             *((T)+5)=(uchar) (((A) >> 40)); } while(0)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1205 1206 1207 1208 1209 1210
#define int8store(T,A)	*((ulonglong *) (T))= (ulonglong) (A)

typedef union {
  double v;
  long m[2];
} doubleget_union;
1211
#define doubleget(V,M)	\
1212 1213 1214 1215 1216 1217 1218
do { doubleget_union _tmp; \
     _tmp.m[0] = *((long*)(M)); \
     _tmp.m[1] = *(((long*) (M))+1); \
     (V) = _tmp.v; } while(0)
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
			     *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
                         } while (0)
monty@mysql.com's avatar
monty@mysql.com committed
1219 1220
#define float4get(V,M)   do { *((float *) &(V)) = *((float*) (M)); } while(0)
#define float8get(V,M)   doubleget((V),(M))
1221 1222 1223
#define float4store(V,M) memcpy((uchar*) V,(uchar*) (&M),sizeof(float))
#define floatstore(T,V)  memcpy((uchar*)(T), (uchar*)(&V),sizeof(float))
#define floatget(V,M)    memcpy((uchar*) &V,(uchar*) (M),sizeof(float))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1224
#define float8store(V,M) doublestore((V),(M))
1225
#else
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1226

1227 1228 1229 1230
/*
  We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
  were done before)
*/
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
#define sint2korr(A)	(int16) (((int16) ((uchar) (A)[0])) +\
				 ((int16) ((int16) (A)[1]) << 8))
#define sint3korr(A)	((int32) ((((uchar) (A)[2]) & 128) ? \
				  (((uint32) 255L << 24) | \
				   (((uint32) (uchar) (A)[2]) << 16) |\
				   (((uint32) (uchar) (A)[1]) << 8) | \
				   ((uint32) (uchar) (A)[0])) : \
				  (((uint32) (uchar) (A)[2]) << 16) |\
				  (((uint32) (uchar) (A)[1]) << 8) | \
				  ((uint32) (uchar) (A)[0])))
#define sint4korr(A)	(int32) (((int32) ((uchar) (A)[0])) +\
				(((int32) ((uchar) (A)[1]) << 8)) +\
				(((int32) ((uchar) (A)[2]) << 16)) +\
				(((int32) ((int16) (A)[3]) << 24)))
#define sint8korr(A)	(longlong) uint8korr(A)
#define uint2korr(A)	(uint16) (((uint16) ((uchar) (A)[0])) +\
				  ((uint16) ((uchar) (A)[1]) << 8))
#define uint3korr(A)	(uint32) (((uint32) ((uchar) (A)[0])) +\
				  (((uint32) ((uchar) (A)[1])) << 8) +\
				  (((uint32) ((uchar) (A)[2])) << 16))
#define uint4korr(A)	(uint32) (((uint32) ((uchar) (A)[0])) +\
				  (((uint32) ((uchar) (A)[1])) << 8) +\
				  (((uint32) ((uchar) (A)[2])) << 16) +\
				  (((uint32) ((uchar) (A)[3])) << 24))
#define uint5korr(A)	((ulonglong)(((uint32) ((uchar) (A)[0])) +\
				    (((uint32) ((uchar) (A)[1])) << 8) +\
				    (((uint32) ((uchar) (A)[2])) << 16) +\
				    (((uint32) ((uchar) (A)[3])) << 24)) +\
1259
				    (((ulonglong) ((uchar) (A)[4])) << 32))
1260 1261 1262 1263 1264 1265
#define uint6korr(A)	((ulonglong)(((uint32)    ((uchar) (A)[0]))          + \
                                     (((uint32)    ((uchar) (A)[1])) << 8)   + \
                                     (((uint32)    ((uchar) (A)[2])) << 16)  + \
                                     (((uint32)    ((uchar) (A)[3])) << 24)) + \
                         (((ulonglong) ((uchar) (A)[4])) << 32) +       \
                         (((ulonglong) ((uchar) (A)[5])) << 40))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1266 1267 1268 1269 1270 1271 1272 1273
#define uint8korr(A)	((ulonglong)(((uint32) ((uchar) (A)[0])) +\
				    (((uint32) ((uchar) (A)[1])) << 8) +\
				    (((uint32) ((uchar) (A)[2])) << 16) +\
				    (((uint32) ((uchar) (A)[3])) << 24)) +\
			(((ulonglong) (((uint32) ((uchar) (A)[4])) +\
				    (((uint32) ((uchar) (A)[5])) << 8) +\
				    (((uint32) ((uchar) (A)[6])) << 16) +\
				    (((uint32) ((uchar) (A)[7])) << 24))) <<\
1274 1275 1276
				    32))
#define int2store(T,A)       do { uint def_temp= (uint) (A) ;\
                                  *((uchar*) (T))=  (uchar)(def_temp); \
serg@serg.mylan's avatar
serg@serg.mylan committed
1277
                                   *((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \
1278 1279 1280 1281 1282 1283
                             } while(0)
#define int3store(T,A)       do { /*lint -save -e734 */\
                                  *((uchar*)(T))=(uchar) ((A));\
                                  *((uchar*) (T)+1)=(uchar) (((A) >> 8));\
                                  *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \
                                  /*lint -restore */} while(0)
serg@serg.mylan's avatar
serg@serg.mylan committed
1284 1285 1286 1287
#define int4store(T,A)       do { *((char *)(T))=(char) ((A));\
                                  *(((char *)(T))+1)=(char) (((A) >> 8));\
                                  *(((char *)(T))+2)=(char) (((A) >> 16));\
                                  *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
#define int5store(T,A)       do { *((char *)(T))=     (char)((A));  \
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
		                } while(0)
#define int6store(T,A)       do { *((char *)(T))=     (char)((A)); \
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
                                  *(((char *)(T))+5)= (char)(((A) >> 40)); \
                                } while(0)
1301 1302 1303
#define int8store(T,A)       do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \
                                  int4store((T),def_temp); \
                                  int4store((T+4),def_temp2); } while(0)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1304
#ifdef WORDS_BIGENDIAN
1305 1306 1307 1308
#define float4store(T,A) do { *(T)= ((uchar *) &A)[3];\
                              *((T)+1)=(char) ((uchar *) &A)[2];\
                              *((T)+2)=(char) ((uchar *) &A)[1];\
                              *((T)+3)=(char) ((uchar *) &A)[0]; } while(0)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1309

1310
#define float4get(V,M)   do { float def_temp;\
1311 1312 1313 1314
                              ((uchar*) &def_temp)[0]=(M)[3];\
                              ((uchar*) &def_temp)[1]=(M)[2];\
                              ((uchar*) &def_temp)[2]=(M)[1];\
                              ((uchar*) &def_temp)[3]=(M)[0];\
1315
                              (V)=def_temp; } while(0)
1316 1317 1318 1319 1320 1321 1322 1323
#define float8store(T,V) do { *(T)= ((uchar *) &V)[7];\
                              *((T)+1)=(char) ((uchar *) &V)[6];\
                              *((T)+2)=(char) ((uchar *) &V)[5];\
                              *((T)+3)=(char) ((uchar *) &V)[4];\
                              *((T)+4)=(char) ((uchar *) &V)[3];\
                              *((T)+5)=(char) ((uchar *) &V)[2];\
                              *((T)+6)=(char) ((uchar *) &V)[1];\
                              *((T)+7)=(char) ((uchar *) &V)[0]; } while(0)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1324

1325
#define float8get(V,M)   do { double def_temp;\
1326 1327 1328 1329 1330 1331 1332 1333
                              ((uchar*) &def_temp)[0]=(M)[7];\
                              ((uchar*) &def_temp)[1]=(M)[6];\
                              ((uchar*) &def_temp)[2]=(M)[5];\
                              ((uchar*) &def_temp)[3]=(M)[4];\
                              ((uchar*) &def_temp)[4]=(M)[3];\
                              ((uchar*) &def_temp)[5]=(M)[2];\
                              ((uchar*) &def_temp)[6]=(M)[1];\
                              ((uchar*) &def_temp)[7]=(M)[0];\
1334
                              (V) = def_temp; } while(0)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1335
#else
1336 1337
#define float4get(V,M)   memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
#define float4store(V,M) memcpy_fixed((uchar*) V,(uchar*) (&M),sizeof(float))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1338 1339

#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
1340 1341 1342 1343 1344 1345 1346 1347
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\
                              *(((char*)T)+1)=(char) ((uchar *) &V)[5];\
                              *(((char*)T)+2)=(char) ((uchar *) &V)[6];\
                              *(((char*)T)+3)=(char) ((uchar *) &V)[7];\
                              *(((char*)T)+4)=(char) ((uchar *) &V)[0];\
                              *(((char*)T)+5)=(char) ((uchar *) &V)[1];\
                              *(((char*)T)+6)=(char) ((uchar *) &V)[2];\
                              *(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\
1348
                         while(0)
1349
#define doubleget(V,M)   do { double def_temp;\
1350 1351 1352 1353 1354 1355 1356 1357
                              ((uchar*) &def_temp)[0]=(M)[4];\
                              ((uchar*) &def_temp)[1]=(M)[5];\
                              ((uchar*) &def_temp)[2]=(M)[6];\
                              ((uchar*) &def_temp)[3]=(M)[7];\
                              ((uchar*) &def_temp)[4]=(M)[0];\
                              ((uchar*) &def_temp)[5]=(M)[1];\
                              ((uchar*) &def_temp)[6]=(M)[2];\
                              ((uchar*) &def_temp)[7]=(M)[3];\
1358
                              (V) = def_temp; } while(0)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1359 1360 1361 1362 1363 1364
#endif /* __FLOAT_WORD_ORDER */

#define float8get(V,M)   doubleget((V),(M))
#define float8store(V,M) doublestore((V),(M))
#endif /* WORDS_BIGENDIAN */

1365
#endif /* __i386__ OR _WIN32 */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1366

1367 1368 1369 1370 1371 1372 1373 1374
/*
  Macro for reading 32-bit integer from network byte order (big-endian)
  from unaligned memory location.
*/
#define int4net(A)        (int32) (((uint32) ((uchar) (A)[3]))        |\
				  (((uint32) ((uchar) (A)[2])) << 8)  |\
				  (((uint32) ((uchar) (A)[1])) << 16) |\
				  (((uint32) ((uchar) (A)[0])) << 24))
1375 1376 1377 1378 1379
/*
  Define-funktions for reading and storing in machine format from/to
  short/long to/from some place in memory V should be a (not
  register) variable, M is a pointer to byte
*/
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1380 1381 1382

#ifdef WORDS_BIGENDIAN

1383 1384 1385 1386 1387
#define ushortget(V,M)  do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\
                                 ((uint16) ((uint16) (M)[0]) << 8)); } while(0)
#define shortget(V,M)   do { V = (short) (((short) ((uchar) (M)[1]))+\
                                 ((short) ((short) (M)[0]) << 8)); } while(0)
#define longget(V,M)    do { int32 def_temp;\
1388 1389 1390 1391
                             ((uchar*) &def_temp)[0]=(M)[0];\
                             ((uchar*) &def_temp)[1]=(M)[1];\
                             ((uchar*) &def_temp)[2]=(M)[2];\
                             ((uchar*) &def_temp)[3]=(M)[3];\
1392 1393
                             (V)=def_temp; } while(0)
#define ulongget(V,M)   do { uint32 def_temp;\
1394 1395 1396 1397
                            ((uchar*) &def_temp)[0]=(M)[0];\
                            ((uchar*) &def_temp)[1]=(M)[1];\
                            ((uchar*) &def_temp)[2]=(M)[2];\
                            ((uchar*) &def_temp)[3]=(M)[3];\
1398 1399
                            (V)=def_temp; } while(0)
#define shortstore(T,A) do { uint def_temp=(uint) (A) ;\
1400 1401 1402 1403 1404 1405
                             *(((char*)T)+1)=(char)(def_temp); \
                             *(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
#define longstore(T,A)  do { *(((char*)T)+3)=((A));\
                             *(((char*)T)+2)=(((A) >> 8));\
                             *(((char*)T)+1)=(((A) >> 16));\
                             *(((char*)T)+0)=(((A) >> 24)); } while(0)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1406

1407 1408 1409 1410 1411 1412
#define floatget(V,M)    memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
#define floatstore(T,V)  memcpy_fixed((uchar*) (T),(uchar*)(&V),sizeof(float))
#define doubleget(V,M)	 memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
#define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
#define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
#define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1413 1414 1415

#else

1416 1417 1418 1419
#define ushortget(V,M)	do { V = uint2korr(M); } while(0)
#define shortget(V,M)	do { V = sint2korr(M); } while(0)
#define longget(V,M)	do { V = sint4korr(M); } while(0)
#define ulongget(V,M)   do { V = uint4korr(M); } while(0)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1420 1421
#define shortstore(T,V) int2store(T,V)
#define longstore(T,V)	int4store(T,V)
1422
#ifndef floatstore
1423 1424
#define floatstore(T,V)  memcpy_fixed((uchar*) (T),(uchar*) (&V),sizeof(float))
#define floatget(V,M)    memcpy_fixed((uchar*) &V, (uchar*) (M), sizeof(float))
1425
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1426
#ifndef doubleget
1427 1428
#define doubleget(V,M)	 memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
#define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1429
#endif /* doubleget */
1430 1431
#define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
#define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441

#endif /* WORDS_BIGENDIAN */

/* sprintf does not always return the number of bytes :- */
#ifdef SPRINTF_RETURNS_INT
#define my_sprintf(buff,args) sprintf args
#else
#ifdef SPRINTF_RETURNS_PTR
#define my_sprintf(buff,args) ((int)(sprintf args - buff))
#else
1442
#define my_sprintf(buff,args) ((ulong) sprintf args, (ulong) strlen(buff))
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1443 1444 1445 1446 1447
#endif
#endif

#ifndef THREAD
#define thread_safe_increment(V,L) (V)++
1448
#define thread_safe_decrement(V,L) (V)--
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1449 1450 1451
#define thread_safe_add(V,C,L)     (V)+=(C)
#define thread_safe_sub(V,C,L)     (V)-=(C)
#define statistic_increment(V,L)   (V)++
1452
#define statistic_decrement(V,L)   (V)--
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1453
#define statistic_add(V,C,L)       (V)+=(C)
1454
#define statistic_sub(V,C,L)       (V)-=(C)
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1455 1456
#endif

1457 1458 1459 1460 1461 1462
#ifdef HAVE_CHARSET_utf8
#define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8"
#else
#define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
#endif

1463 1464 1465 1466
#if defined(EMBEDDED_LIBRARY) && !defined(HAVE_EMBEDDED_PRIVILEGE_CONTROL)
#define NO_EMBEDDED_ACCESS_CHECKS
#endif

1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485
#ifdef HAVE_DLOPEN
#if defined(__WIN__)
#define dlsym(lib, name) GetProcAddress((HMODULE)lib, name)
#define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0)
#define dlclose(lib) FreeLibrary((HMODULE)lib)
#elif defined(HAVE_DLFCN_H)
#include <dlfcn.h>
#endif
#endif

/* FreeBSD 2.2.2 does not define RTLD_NOW) */
#ifndef RTLD_NOW
#define RTLD_NOW 1
#endif

#ifndef HAVE_DLERROR
#define dlerror() ""
#endif

1486

1487
#ifndef __NETWARE__
1488
/*
1489
 *  Include standard definitions of operator new and delete.
1490 1491
 */
#ifdef __cplusplus
1492
#include <new>
1493
#endif
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505
#else
/*
 *  Define placement versions of operator new and operator delete since
 *  we don't have <new> when building for Netware.
 */
#ifdef __cplusplus
inline void *operator new(size_t, void *ptr) { return ptr; }
inline void *operator new[](size_t, void *ptr) { return ptr; }
inline void  operator delete(void*, void*) { /* Do nothing */ }
inline void  operator delete[](void*, void*) { /* Do nothing */ }
#endif
#endif
1506

1507 1508 1509 1510 1511 1512
/* Length of decimal number represented by INT32. */
#define MY_INT32_NUM_DECIMAL_DIGITS 11

/* Length of decimal number represented by INT64. */
#define MY_INT64_NUM_DECIMAL_DIGITS 21

1513 1514 1515 1516
/* Define some useful general macros (should be done after all headers). */
#if !defined(max)
#define max(a, b)	((a) > (b) ? (a) : (b))
#define min(a, b)	((a) < (b) ? (a) : (b))
1517 1518 1519 1520 1521 1522 1523
#endif  
/*
  Only Linux is known to need an explicit sync of the directory to make sure a
  file creation/deletion/renaming in(from,to) this directory durable.
*/
#ifdef TARGET_OS_LINUX
#define NEED_EXPLICIT_SYNC_DIR 1
1524 1525
#endif

1526 1527 1528 1529
#if !defined(__cplusplus) && !defined(bool)
#define bool In_C_you_should_use_my_bool_instead()
#endif

1530
#endif /* my_global_h */