my_sys.h 40.2 KB
Newer Older
1
/* Copyright (C) 2000-2003 MySQL AB
unknown's avatar
unknown 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
unknown's avatar
unknown committed
5
   the Free Software Foundation; version 2 of the License.
unknown's avatar
unknown committed
6 7

   This program is distributed in the hope that it will be useful,
unknown's avatar
unknown committed
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
unknown's avatar
unknown 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 */
unknown's avatar
unknown committed
15 16 17

#ifndef _my_sys_h
#define _my_sys_h
18 19 20

#include "my_global.h"                  /* C_MODE_START, C_MODE_END */

unknown's avatar
unknown committed
21
C_MODE_START
unknown's avatar
unknown committed
22 23 24 25 26 27 28 29 30

#ifdef HAVE_AIOWAIT
#include <sys/asynch.h>			/* Used by record-cache */
typedef struct my_aio_result {
  aio_result_t result;
  int	       pending;
} my_aio_result;
#endif

Sergei Golubchik's avatar
Sergei Golubchik committed
31
#include <my_valgrind.h>
32

unknown's avatar
unknown committed
33 34 35
#include <my_pthread.h>

#include <m_ctype.h>                    /* for CHARSET_INFO */
unknown's avatar
unknown committed
36
#include <stdarg.h>
37
#include <typelib.h>
38 39 40
#ifdef _WIN32
#include <malloc.h> /*for alloca*/
#endif
Sergei Golubchik's avatar
Sergei Golubchik committed
41
#include <mysql/plugin.h>
unknown's avatar
unknown committed
42

43
#define MY_INIT(name)   { my_progname= name; my_init(); }
unknown's avatar
unknown committed
44

Marc Alff's avatar
Marc Alff committed
45 46 47 48 49 50 51 52 53 54 55
/**
  Max length of an error message generated by mysys utilities.
  Some mysys functions produce error messages. These mostly go
  to stderr.
  This constant defines the size of the buffer used to format
  the message. It should be kept in sync with MYSQL_ERRMSG_SIZE,
  since sometimes mysys errors are stored in the server diagnostics
  area, and we would like to avoid unexpected truncation.
*/
#define MYSYS_ERRMSG_SIZE   (512)

56
#define MY_FILE_ERROR	((size_t) -1)
unknown's avatar
unknown committed
57 58 59 60 61 62 63 64

	/* General bitmaps for my_func's */
#define MY_FFNF		1	/* Fatal if file not found */
#define MY_FNABP	2	/* Fatal if not all bytes read/writen */
#define MY_NABP		4	/* Error if not all bytes read/writen */
#define MY_FAE		8	/* Fatal if any error */
#define MY_WME		16	/* Write message on error */
#define MY_WAIT_IF_FULL 32	/* Wait and try again if disk full error */
65
#define MY_IGNORE_BADFD 32      /* my_sync: ignore 'bad descriptor' errors */
66
#define MY_UNUSED       64      /* Unused (was support for RAID) */
67 68
#define MY_FULL_IO     512      /* For my_read - loop intil I/O is complete */
#define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
unknown's avatar
unknown committed
69 70
#define MY_LINK_WARNING 32	/* my_redel() gives warning if links */
#define MY_COPYTIME	64	/* my_redel() copys time */
71 72
#define MY_DELETE_OLD	256	/* my_create_with_symlink() */
#define MY_RESOLVE_LINK 128	/* my_realpath(); Only resolve links */
unknown's avatar
unknown committed
73
#define MY_HOLD_ORIGINAL_MODES 128  /* my_copy() holds to file modes */
74
#define MY_REDEL_MAKE_BACKUP 256
unknown's avatar
unknown committed
75
#define MY_SEEK_NOT_DONE 32	/* my_lock may have to do a seek */
76 77 78
#define MY_SHORT_WAIT	64	/* my_lock() don't wait if can't lock */
#define MY_FORCE_LOCK   128     /* use my_lock() even if disable_locking */
#define MY_NO_WAIT      256	/* my_lock() don't wait at all */
unknown's avatar
unknown committed
79 80 81 82
#define MY_ZEROFILL	32	/* my_malloc(), fill array with zero */
#define MY_ALLOW_ZERO_PTR 64	/* my_realloc() ; zero ptr -> malloc */
#define MY_FREE_ON_ERROR 128	/* my_realloc() ; Free old ptr on error */
#define MY_HOLD_ON_ERROR 256	/* my_realloc() ; Return old ptr on error */
83
#define MY_DONT_OVERWRITE_FILE 2048 /* my_copy: Don't overwrite file */
unknown's avatar
unknown committed
84
#define MY_THREADSAFE 2048      /* my_seek(): lock fd mutex */
85
#define MY_SYNC       4096      /* my_copy(): sync dst file */
86
#define MY_SYNC_DIR   32768     /* my_create/delete/rename: sync directory */
unknown's avatar
unknown committed
87 88 89

#define MY_CHECK_ERROR	1	/* Params to my_end; Check open-close */
#define MY_GIVE_INFO	2	/* Give time info about process*/
90
#define MY_DONT_FREE_DBUG 4     /* Do not call DBUG_END() in my_end() */
unknown's avatar
unknown committed
91 92 93 94 95 96 97 98

#define ME_HIGHBYTE	8	/* Shift for colours */
#define ME_NOCUR	1	/* Don't use curses message */
#define ME_OLDWIN	2	/* Use old window */
#define ME_BELL		4	/* Ring bell then printing message */
#define ME_HOLDTANG	8	/* Don't delete last keys */
#define ME_WAITTOT	16	/* Wait for errtime secs of for a action */
#define ME_WAITTANG	32	/* Wait for a user action  */
99
#define ME_NOREFRESH	64	/* Write the error message to error log */
unknown's avatar
unknown committed
100 101 102 103
#define ME_NOINPUT	128	/* Dont use the input libary */
#define ME_COLOUR1	((1 << ME_HIGHBYTE))	/* Possibly error-colours */
#define ME_COLOUR2	((2 << ME_HIGHBYTE))
#define ME_COLOUR3	((3 << ME_HIGHBYTE))
104 105 106
#define ME_JUST_INFO    1024    /**< not error but just info */
#define ME_JUST_WARNING 2048    /**< not error but just warning */
#define ME_FATALERROR   4096    /* Fatal statement error */
unknown's avatar
unknown committed
107

108 109 110 111 112 113 114 115 116
	/* Bits in last argument to fn_format */
#define MY_REPLACE_DIR		1	/* replace dir in name with 'dir' */
#define MY_REPLACE_EXT		2	/* replace extension with 'ext' */
#define MY_UNPACK_FILENAME	4	/* Unpack name (~ -> home) */
#define MY_PACK_FILENAME	8	/* Pack name (home -> ~) */
#define MY_RESOLVE_SYMLINKS	16	/* Resolve all symbolic links */
#define MY_RETURN_REAL_PATH	32	/* return full path for file */
#define MY_SAFE_PATH		64	/* Return NULL if too long path */
#define MY_RELATIVE_PATH	128	/* name is relative to 'dir' */
117 118
#define MY_APPEND_EXT           256     /* add 'ext' as additional extension*/

119

unknown's avatar
unknown committed
120 121 122 123 124 125 126 127 128
	/* My seek flags */
#define MY_SEEK_SET	0
#define MY_SEEK_CUR	1
#define MY_SEEK_END	2

	/* Some constants */
#define MY_WAIT_FOR_USER_TO_FIX_PANIC	60	/* in seconds */
#define MY_WAIT_GIVE_USER_A_MESSAGE	10	/* Every 10 times of prev */
#define MIN_COMPRESS_LENGTH		50	/* Don't compress small bl. */
129
#define DFLT_INIT_HITS  3
unknown's avatar
unknown committed
130

131 132
	/* root_alloc flags */
#define MY_KEEP_PREALLOC	1
133
#define MY_MARK_BLOCKS_FREE     2  /* move used to free list and reuse them */
unknown's avatar
unknown committed
134

unknown's avatar
unknown committed
135 136 137
	/* Internal error numbers (for assembler functions) */
#define MY_ERRNO_EDOM		33
#define MY_ERRNO_ERANGE		34
unknown's avatar
unknown committed
138

unknown's avatar
unknown committed
139 140 141 142 143 144 145
	/* Bits for get_date timeflag */
#define GETDATE_DATE_TIME	1
#define GETDATE_SHORT_DATE	2
#define GETDATE_HHMMSSTIME	4
#define GETDATE_GMT		8
#define GETDATE_FIXEDLENGTH	16

146 147 148
/* Extra length needed for filename if one calls my_create_backup_name */
#define MY_BACKUP_NAME_EXTRA_LENGTH 17

unknown's avatar
unknown committed
149
	/* defines when allocating data */
150
extern void *my_malloc(size_t Size,myf MyFlags);
151
extern void *my_multi_malloc(myf MyFlags, ...);
152
extern void *my_realloc(void *oldpoint, size_t Size, myf MyFlags);
153
extern void my_free(void *ptr);
154
extern void *my_memdup(const void *from,size_t length,myf MyFlags);
155
extern char *my_strdup(const char *from,myf MyFlags);
156
extern char *my_strndup(const char *from, size_t length,
157
				   myf MyFlags);
158 159 160 161 162 163 164 165 166 167
#if defined(ENABLED_DEBUG_SYNC)
extern void (*debug_sync_C_callback_ptr)(const char *, size_t);
#define DEBUG_SYNC_C(_sync_point_name_) do {                            \
    if (debug_sync_C_callback_ptr != NULL)                              \
      (*debug_sync_C_callback_ptr)(STRING_WITH_LEN(_sync_point_name_)); } \
  while(0)
#else
#define DEBUG_SYNC_C(_sync_point_name_)
#endif /* defined(ENABLED_DEBUG_SYNC) */

168 169
#ifdef HAVE_LARGE_PAGES
extern uint my_get_large_page_size(void);
170
extern uchar * my_large_malloc(size_t size, myf my_flags);
171
extern void my_large_free(uchar *ptr);
172 173 174
#else
#define my_get_large_page_size() (0)
#define my_large_malloc(A,B) my_malloc_lock((A),(B))
175
#define my_large_free(A) my_free_lock((A))
176 177
#endif /* HAVE_LARGE_PAGES */

178
#if defined(HAVE_ALLOCA) && !defined(HAVE_valgrind)
unknown's avatar
unknown committed
179
#if defined(_AIX) && !defined(__GNUC__) && !defined(_AIX43)
unknown's avatar
unknown committed
180
#pragma alloca
181
#endif /* _AIX */
182 183
#if defined(__MWERKS__)
#undef alloca
unknown's avatar
unknown committed
184
#define alloca _alloca
185
#endif /* __MWERKS__ */
186
#if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) && ! defined(alloca)
187 188
#define alloca __builtin_alloca
#endif /* GNUC */
unknown's avatar
unknown committed
189
#define my_alloca(SZ) alloca((size_t) (SZ))
190
#define my_afree(PTR) ((void)0)
unknown's avatar
unknown committed
191
#else
192
#define my_alloca(SZ) my_malloc(SZ,MYF(MY_FAE))
193
#define my_afree(PTR) my_free(PTR)
unknown's avatar
unknown committed
194
#endif /* HAVE_ALLOCA */
unknown's avatar
unknown committed
195

Sergei Golubchik's avatar
Sergei Golubchik committed
196
#define my_safe_alloca(size, min_length) ((size <= min_length) ? my_alloca(size) : my_malloc(size,MYF(MY_FAE)))
Sergei Golubchik's avatar
Sergei Golubchik committed
197
#define my_safe_afree(ptr, size, min_length) ((size <= min_length) ? my_afree(ptr) : my_free(ptr))
Sergei Golubchik's avatar
Sergei Golubchik committed
198

199
#ifndef errno				/* did we already get it? */
unknown's avatar
unknown committed
200 201 202 203 204
#ifdef HAVE_ERRNO_AS_DEFINE
#include <errno.h>			/* errno is a define */
#else
extern int errno;			/* declare errno */
#endif
205
#endif					/* #ifndef errno */
unknown's avatar
unknown committed
206
extern char *home_dir;			/* Home directory for user */
207
extern const char *my_progname;		/* program-name (printed in errors) */
208
extern const char *my_progname_short;	/* like above but without directory */
209
extern char curr_dir[];		/* Current directory for user */
Marc Alff's avatar
Marc Alff committed
210 211
extern void (*error_handler_hook)(uint my_err, const char *str,myf MyFlags);
extern void (*fatal_error_handler_hook)(uint my_err, const char *str,
unknown's avatar
unknown committed
212
				       myf MyFlags);
213
extern uint my_file_limit;
214
extern ulong my_thread_stack_size;
unknown's avatar
unknown committed
215

Sergei Golubchik's avatar
Sergei Golubchik committed
216
extern const char *(*proc_info_hook)(MYSQL_THD, const char *, const char *,
Konstantin Osipov's avatar
Konstantin Osipov committed
217 218
                                     const char *, const unsigned int);

219 220 221 222 223
#ifdef HAVE_LARGE_PAGES
extern my_bool my_use_large_pages;
extern uint    my_large_page_size;
#endif

unknown's avatar
unknown committed
224
/* charsets */
225
#define MY_ALL_CHARSETS_SIZE 2048
226
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *default_charset_info;
227
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *all_charsets[MY_ALL_CHARSETS_SIZE];
228
extern struct charset_info_st compiled_charsets[];
229

230
/* statistics */
231
extern ulong	my_file_opened,my_stream_opened, my_tmp_file_created;
232
extern ulong    my_file_total_opened;
233
extern ulong    my_sync_count;
234
extern uint	mysys_usage_id;
unknown's avatar
unknown committed
235
extern my_bool	my_init_done;
236
extern my_bool  my_assert_on_error;
237
extern myf      my_global_flags;        /* Set to MY_WME for more error messages */
unknown's avatar
unknown committed
238 239 240 241 242 243
					/* Point to current my_message() */
extern void (*my_sigtstp_cleanup)(void),
					/* Executed before jump to shell */
	    (*my_sigtstp_restart)(void),
	    (*my_abort_hook)(int);
					/* Executed when comming from shell */
244 245 246 247 248 249
extern MYSQL_PLUGIN_IMPORT int my_umask;		/* Default creation mask  */
extern int my_umask_dir,
	   my_recived_signals,	/* Signals we have got */
	   my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */
	   my_dont_interrupt;	/* call remember_intr when set */
extern my_bool my_use_symdir;
unknown's avatar
unknown committed
250 251

extern ulong	my_default_record_cache_size;
252 253
extern my_bool  my_disable_locking, my_disable_async_io,
                my_disable_flush_key_blocks, my_disable_symlinks;
254
extern my_bool my_disable_sync;
unknown's avatar
unknown committed
255 256
extern char	wild_many,wild_one,wild_prefix;
extern const char *charsets_dir;
257
/* from default.c */
258
extern const char *my_defaults_extra_file;
259 260
extern const char *my_defaults_group_suffix;
extern const char *my_defaults_file;
unknown's avatar
unknown committed
261

262 263
extern my_bool timed_mutexes;

264 265 266 267 268 269
enum loglevel {
   ERROR_LEVEL,
   WARNING_LEVEL,
   INFORMATION_LEVEL
};

270 271
enum cache_type
{
unknown's avatar
unknown committed
272
  TYPE_NOT_SET= 0, READ_CACHE, WRITE_CACHE,
273 274 275 276 277
  SEQ_READ_APPEND		/* sequential read or append */,
  READ_FIFO, READ_NET,WRITE_NET};

enum flush_type
{
278 279 280 281 282 283 284
  FLUSH_KEEP,           /* flush block and keep it in the cache */
  FLUSH_RELEASE,        /* flush block and remove it from the cache */
  FLUSH_IGNORE_CHANGED, /* remove block from the cache */
  /*
    As my_disable_flush_pagecache_blocks is always 0, the following option
    is strictly equivalent to FLUSH_KEEP
  */
unknown's avatar
unknown committed
285
  FLUSH_FORCE_WRITE,
unknown's avatar
unknown committed
286 287 288 289 290 291
  /**
     @brief like FLUSH_KEEP but return immediately if file is already being
     flushed (even partially) by another thread; only for page cache,
     forbidden for key cache.
  */
  FLUSH_KEEP_LAZY
292
};
unknown's avatar
unknown committed
293 294 295 296 297 298 299

typedef struct st_record_cache	/* Used when cacheing records */
{
  File file;
  int	rc_seek,error,inited;
  uint	rc_length,read_length,reclength;
  my_off_t rc_record_pos,end_of_file;
300
  uchar *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos;
unknown's avatar
unknown committed
301 302 303 304 305 306 307
#ifdef HAVE_AIOWAIT
  int	use_async_io;
  my_aio_result aio_result;
#endif
  enum cache_type type;
} RECORD_CACHE;

308 309 310 311 312
enum file_type
{
  UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN,
  FILE_BY_MKSTEMP, FILE_BY_DUP
};
unknown's avatar
unknown committed
313

314
struct st_my_file_info
unknown's avatar
unknown committed
315
{
316 317 318 319 320 321
  char  *name;
#ifdef _WIN32
  HANDLE fhandle;   /* win32 file handle */
  int    oflag;     /* open flags, e.g O_APPEND */
#endif
  enum   file_type	type;
322 323 324
};

extern struct st_my_file_info *my_file_info;
unknown's avatar
unknown committed
325

326 327
typedef struct st_dynamic_array
{
328
  uchar *buffer;
329 330 331 332 333
  uint elements,max_element;
  uint alloc_increment;
  uint size_of_element;
} DYNAMIC_ARRAY;

unknown's avatar
unknown committed
334 335
typedef struct st_my_tmpdir
{
336
  DYNAMIC_ARRAY full_list;
unknown's avatar
unknown committed
337 338
  char **list;
  uint cur, max;
Marc Alff's avatar
Marc Alff committed
339
  mysql_mutex_t mutex;
unknown's avatar
unknown committed
340
} MY_TMPDIR;
unknown's avatar
unknown committed
341

342 343
typedef struct st_dynamic_string
{
unknown's avatar
unknown committed
344
  char *str;
345
  size_t length,max_length,alloc_increment;
unknown's avatar
unknown committed
346 347
} DYNAMIC_STRING;

348 349
struct st_io_cache;
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
unknown's avatar
unknown committed
350

unknown's avatar
unknown committed
351 352
typedef struct st_io_cache_share
{
Marc Alff's avatar
Marc Alff committed
353 354 355
  mysql_mutex_t       mutex;           /* To sync on reads into buffer. */
  mysql_cond_t        cond;            /* To wait for signals. */
  mysql_cond_t        cond_writer;     /* For a synchronized writer. */
356 357 358 359
  /* Offset in file corresponding to the first byte of buffer. */
  my_off_t              pos_in_file;
  /* If a synchronized write cache is the source of the data. */
  struct st_io_cache    *source_cache;
360 361
  uchar                 *buffer;         /* The read buffer. */
  uchar                 *read_end;       /* Behind last valid byte of buffer. */
362 363 364
  int                   running_threads; /* threads not in lock. */
  int                   total_threads;   /* threads sharing the cache. */
  int                   error;           /* Last error. */
unknown's avatar
unknown committed
365
#ifdef NOT_YET_IMPLEMENTED
unknown's avatar
unknown committed
366 367 368 369
  /* whether the structure should be free'd */
  my_bool alloced;
#endif
} IO_CACHE_SHARE;
unknown's avatar
unknown committed
370

unknown's avatar
unknown committed
371 372
typedef struct st_io_cache		/* Used when cacheing files */
{
373
  /* Offset in file corresponding to the first byte of uchar* buffer. */
unknown's avatar
unknown committed
374 375 376 377 378
  my_off_t pos_in_file;
  /*
    The offset of end of file for READ_CACHE and WRITE_CACHE.
    For SEQ_READ_APPEND it the maximum of the actual end of file and
    the position represented by read_end.
379
  */
unknown's avatar
unknown committed
380 381
  my_off_t end_of_file;
  /* Points to current read position in the buffer */
382
  uchar	*read_pos;
unknown's avatar
unknown committed
383
  /* the non-inclusive boundary in the buffer for the currently valid read */
384 385
  uchar  *read_end;
  uchar  *buffer;				/* The read buffer */
unknown's avatar
unknown committed
386
  /* Used in ASYNC_IO */
387
  uchar  *request_pos;
unknown's avatar
unknown committed
388 389

  /* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
390
  uchar  *write_buffer;
unknown's avatar
unknown committed
391 392 393
  /*
    Only used in SEQ_READ_APPEND, and points to the current read position
    in the write buffer. Note that reads in SEQ_READ_APPEND caches can
394 395
    happen from both read buffer (uchar* buffer) and write buffer
    (uchar* write_buffer).
396
  */
397
  uchar *append_read_pos;
unknown's avatar
unknown committed
398
  /* Points to current write position in the write buffer */
399
  uchar *write_pos;
unknown's avatar
unknown committed
400
  /* The non-inclusive boundary of the valid write area */
401
  uchar *write_end;
unknown's avatar
unknown committed
402 403 404 405 406 407

  /*
    Current_pos and current_end are convenience variables used by
    my_b_tell() and other routines that need to know the current offset
    current_pos points to &write_pos, and current_end to &write_end in a
    WRITE_CACHE, and &read_pos and &read_end respectively otherwise
408
  */
409
  uchar  **current_pos, **current_end;
410

unknown's avatar
unknown committed
411 412 413 414
  /*
    The lock is for append buffer used in SEQ_READ_APPEND cache
    need mutex copying from append buffer to read buffer.
  */
Marc Alff's avatar
Marc Alff committed
415
  mysql_mutex_t append_buffer_lock;
unknown's avatar
unknown committed
416 417 418 419 420 421 422
  /*
    The following is used when several threads are reading the
    same file in parallel. They are synchronized on disk
    accesses reading the cached part of the file asynchronously.
    It should be set to NULL to disable the feature.  Only
    READ_CACHE mode is supported.
  */
unknown's avatar
unknown committed
423
  IO_CACHE_SHARE *share;
424

unknown's avatar
unknown committed
425 426 427 428 429 430 431
  /*
    A caller will use my_b_read() macro to read from the cache
    if the data is already in cache, it will be simply copied with
    memcpy() and internal variables will be accordinging updated with
    no functions invoked. However, if the data is not fully in the cache,
    my_b_read() will call read_function to fetch the data. read_function
    must never be invoked directly.
432
  */
433
  int (*read_function)(struct st_io_cache *,uchar *,size_t);
unknown's avatar
unknown committed
434 435 436
  /*
    Same idea as in the case of read_function, except my_b_write() needs to
    be replaced with my_b_append() for a SEQ_READ_APPEND cache
437
  */
438
  int (*write_function)(struct st_io_cache *,const uchar *,size_t);
unknown's avatar
unknown committed
439 440 441 442
  /*
    Specifies the type of the cache. Depending on the type of the cache
    certain operations might not be available and yield unpredicatable
    results. Details to be documented later
443
  */
unknown's avatar
unknown committed
444
  enum cache_type type;
unknown's avatar
unknown committed
445 446 447 448 449 450
  /*
    Callbacks when the actual read I/O happens. These were added and
    are currently used for binary logging of LOAD DATA INFILE - when a
    block is read from the file, we create a block create/append event, and
    when IO_CACHE is closed, we create an end event. These functions could,
    of course be used for other things
451
  */
452 453
  IO_CACHE_CALLBACK pre_read;
  IO_CACHE_CALLBACK post_read;
454
  IO_CACHE_CALLBACK pre_close;
455 456
  /*
    Counts the number of times, when we were forced to use disk. We use it to
457 458
    increase the binlog_cache_disk_use and binlog_stmt_cache_disk_use status
    variables.
459 460
  */
  ulong disk_writes;
unknown's avatar
unknown committed
461
  void* arg;				/* for use by pre/post_read */
462 463
  char *file_name;			/* if used with 'open_cached_file' */
  char *dir,*prefix;
464
  File file; /* file descriptor */
unknown's avatar
unknown committed
465 466 467 468 469 470
  /*
    seek_not_done is set by my_b_seek() to inform the upcoming read/write
    operation that a seek needs to be preformed prior to the actual I/O
    error is 0 if the cache operation was successful, -1 if there was a
    "hard" error, and the actual number of I/O-ed bytes if the read/write was
    partial.
471
  */
unknown's avatar
unknown committed
472
  int	seek_not_done,error;
unknown's avatar
unknown committed
473
  /* buffer_length is memory size allocated for buffer or write_buffer */
474
  size_t	buffer_length;
unknown's avatar
unknown committed
475
  /* read_length is the same as buffer_length except when we use async io */
476
  size_t  read_length;
unknown's avatar
unknown committed
477
  myf	myflags;			/* Flags used to my_read/my_write */
unknown's avatar
unknown committed
478
  /*
unknown's avatar
unknown committed
479 480 481 482 483
    alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
    0 if it was supplied by the user.
    Currently READ_NET is the only one that will use a buffer allocated
    somewhere else
  */
unknown's avatar
unknown committed
484
  my_bool alloced_buffer;
unknown's avatar
unknown committed
485
#ifdef HAVE_AIOWAIT
unknown's avatar
unknown committed
486 487 488
  /*
    As inidicated by ifdef, this is for async I/O, which is not currently
    used (because it's not reliable on all systems)
489
  */
unknown's avatar
unknown committed
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
  uint inited;
  my_off_t aio_read_pos;
  my_aio_result aio_result;
#endif
} IO_CACHE;

typedef int (*qsort2_cmp)(const void *, const void *, const void *);

	/* defines for mf_iocache */

	/* Test if buffer is inited */
#define my_b_clear(info) (info)->buffer=0
#define my_b_inited(info) (info)->buffer
#define my_b_EOF INT_MIN

#define my_b_read(info,Buffer,Count) \
unknown's avatar
unknown committed
506 507 508
  ((info)->read_pos + (Count) <= (info)->read_end ?\
   (memcpy(Buffer,(info)->read_pos,(size_t) (Count)), \
    ((info)->read_pos+=(Count)),0) :\
unknown's avatar
unknown committed
509 510
   (*(info)->read_function)((info),Buffer,Count))

511 512 513 514
#define my_b_write(info,Buffer,Count) \
 ((info)->write_pos + (Count) <=(info)->write_end ?\
  (memcpy((info)->write_pos, (Buffer), (size_t)(Count)),\
   ((info)->write_pos+=(Count)),0) : \
515
   (*(info)->write_function)((info),(uchar *)(Buffer),(Count)))
unknown's avatar
unknown committed
516

unknown's avatar
unknown committed
517
#define my_b_get(info) \
unknown's avatar
unknown committed
518 519
  ((info)->read_pos != (info)->read_end ?\
   ((info)->read_pos++, (int) (uchar) (info)->read_pos[-1]) :\
unknown's avatar
unknown committed
520 521 522 523
   _my_b_get(info))

	/* my_b_write_byte dosn't have any err-check */
#define my_b_write_byte(info,chr) \
unknown's avatar
unknown committed
524 525 526
  (((info)->write_pos < (info)->write_end) ?\
   ((*(info)->write_pos++)=(chr)) :\
   (_my_b_write(info,0,0) , ((*(info)->write_pos++)=(chr))))
unknown's avatar
unknown committed
527 528

#define my_b_fill_cache(info) \
unknown's avatar
unknown committed
529
  (((info)->read_end=(info)->read_pos),(*(info)->read_function)(info,0,0))
unknown's avatar
unknown committed
530

unknown's avatar
unknown committed
531
#define my_b_tell(info) ((info)->pos_in_file + \
532
			 (size_t) (*(info)->current_pos - (info)->request_pos))
unknown's avatar
unknown committed
533 534
#define my_b_write_tell(info) ((info)->pos_in_file + \
			 ((info)->write_pos - (info)->write_buffer))
535

536 537 538 539 540
#define my_b_get_buffer_start(info) (info)->request_pos 
#define my_b_get_bytes_in_buffer(info) (char*) (info)->read_end -   \
  (char*) my_b_get_buffer_start(info)
#define my_b_get_pos_in_file(info) (info)->pos_in_file

541
/* tell write offset in the SEQ_APPEND cache */
542
int      my_b_copy_to_file(IO_CACHE *cache, FILE *file);
543
my_off_t my_b_append_tell(IO_CACHE* info);
544
my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
unknown's avatar
unknown committed
545

546
#define my_b_bytes_in_cache(info) (size_t) (*(info)->current_end - \
unknown's avatar
unknown committed
547
					  *(info)->current_pos)
unknown's avatar
unknown committed
548

unknown's avatar
unknown committed
549
typedef uint32 ha_checksum;
550
extern ulong my_crc_dbug_check;
unknown's avatar
unknown committed
551

552 553
/* Define the type of function to be passed to process_default_option_files */
typedef int (*Process_option_func)(void *ctx, const char *group_name,
554
                                   const char *option);
555

556
#include <my_alloc.h>
unknown's avatar
unknown committed
557

558

unknown's avatar
unknown committed
559 560 561 562
	/* Prototypes for mysys and my_func functions */

extern int my_copy(const char *from,const char *to,myf MyFlags);
extern int my_delete(const char *name,myf MyFlags);
563
extern int my_getwd(char * buf,size_t size,myf MyFlags);
unknown's avatar
unknown committed
564 565
extern int my_setwd(const char *dir,myf MyFlags);
extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags);
566
extern void *my_once_alloc(size_t Size,myf MyFlags);
unknown's avatar
unknown committed
567
extern void my_once_free(void);
unknown's avatar
unknown committed
568
extern char *my_once_strdup(const char *src,myf myflags);
569
extern void *my_once_memdup(const void *src, size_t len, myf myflags);
unknown's avatar
unknown committed
570
extern File my_open(const char *FileName,int Flags,myf MyFlags);
unknown's avatar
unknown committed
571 572 573
extern File my_register_filename(File fd, const char *FileName,
				 enum file_type type_of_file,
				 uint error_message_number, myf MyFlags);
unknown's avatar
unknown committed
574
extern File my_create(const char *FileName,int CreateFlags,
unknown's avatar
unknown committed
575
		      int AccessFlags, myf MyFlags);
unknown's avatar
unknown committed
576 577
extern int my_close(File Filedes,myf MyFlags);
extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
578
extern int my_readlink(char *to, const char *filename, myf MyFlags);
579
extern int my_is_symlink(const char *filename);
580 581 582 583
extern int my_realpath(char *to, const char *filename, myf MyFlags);
extern File my_create_with_symlink(const char *linkname, const char *filename,
				   int createflags, int access_flags,
				   myf MyFlags);
584 585
extern int my_delete_with_symlink(const char *name, myf MyFlags);
extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags);
586
extern int my_symlink(const char *content, const char *linkname, myf MyFlags);
587 588
extern size_t my_read(File Filedes,uchar *Buffer,size_t Count,myf MyFlags);
extern size_t my_pread(File Filedes,uchar *Buffer,size_t Count,my_off_t offset,
unknown's avatar
unknown committed
589 590 591 592
		     myf MyFlags);
extern int my_rename(const char *from,const char *to,myf MyFlags);
extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags);
extern my_off_t my_tell(File fd,myf MyFlags);
593
extern size_t my_write(File Filedes,const uchar *Buffer,size_t Count,
unknown's avatar
unknown committed
594
		     myf MyFlags);
595
extern size_t my_pwrite(File Filedes,const uchar *Buffer,size_t Count,
unknown's avatar
unknown committed
596
		      my_off_t offset,myf MyFlags);
597 598
extern size_t my_fread(FILE *stream,uchar *Buffer,size_t Count,myf MyFlags);
extern size_t my_fwrite(FILE *stream,const uchar *Buffer,size_t Count,
unknown's avatar
unknown committed
599 600 601
		      myf MyFlags);
extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags);
extern my_off_t my_ftell(FILE *stream,myf MyFlags);
unknown's avatar
unknown committed
602

unknown's avatar
unknown committed
603 604
/* implemented in my_memmem.c */
extern void *my_memmem(const void *haystack, size_t haystacklen,
605
                       const void *needle, size_t needlelen);
unknown's avatar
unknown committed
606 607


608 609
#ifdef _WIN32
extern int      my_access(const char *path, int amode);
unknown's avatar
unknown committed
610 611 612
#else
#define my_access access
#endif
613

unknown's avatar
unknown committed
614
extern int check_if_legal_filename(const char *path);
615
extern int check_if_legal_tablename(const char *path);
616

Vladislav Vaintroub's avatar
Vladislav Vaintroub committed
617
#ifdef _WIN32
618 619 620 621 622 623
extern int nt_share_delete(const char *name,myf MyFlags);
#define my_delete_allow_opened(fname,flags)  nt_share_delete((fname),(flags))
#else
#define my_delete_allow_opened(fname,flags)  my_delete((fname),(flags))
#endif

624 625 626 627 628 629
#ifdef _WIN32
/* Windows-only functions (CRT equivalents)*/
extern HANDLE   my_get_osfhandle(File fd);
extern void     my_osmaperr(unsigned long last_error);
#endif

unknown's avatar
unknown committed
630
extern void init_glob_errs(void);
631
extern const char** get_global_errmsgs();
632
extern void wait_for_free_space(const char *filename, int errors);
unknown's avatar
unknown committed
633
extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
634
extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
635
extern FILE *my_freopen(const char *path, const char *mode, FILE *stream);
unknown's avatar
unknown committed
636
extern int my_fclose(FILE *fd,myf MyFlags);
637
extern File my_fileno(FILE *fd);
638
extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
639
extern int my_chmod(const char *name, mode_t mode, myf my_flags);
Mikael Ronstrom's avatar
Mikael Ronstrom committed
640 641
extern void thr_set_sync_wait_callback(void (*before_sync)(void),
                                       void (*after_sync)(void));
642
extern int my_sync(File fd, myf my_flags);
643 644
extern int my_sync_dir(const char *dir_name, myf my_flags);
extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
645 646 647 648
extern void my_error(int nr,myf MyFlags, ...);
extern void my_printf_error(uint my_err, const char *format,
                            myf MyFlags, ...)
                            ATTRIBUTE_FORMAT(printf, 2, 4);
649 650
extern void my_printv_error(uint error, const char *format, myf MyFlags,
                            va_list ap);
651 652
extern int my_error_register(const char** (*get_errmsgs) (),
                             int first, int last);
653
extern const char **my_error_unregister(int first, int last);
Marc Alff's avatar
Marc Alff committed
654
extern void my_message(uint my_err, const char *str,myf MyFlags);
Davi Arnaut's avatar
Davi Arnaut committed
655
extern void my_message_stderr(uint my_err, const char *str, myf MyFlags);
656
extern my_bool my_init(void);
unknown's avatar
unknown committed
657
extern void my_end(int infoflag);
658 659 660 661
extern int my_redel(const char *from, const char *to, time_t backup_time_stamp,
                    myf MyFlags);
void my_create_backup_name(char *to, const char *from,
                           time_t backup_time_stamp);
unknown's avatar
unknown committed
662
extern int my_copystat(const char *from, const char *to, int MyFlags);
663
extern char * my_filename(File fd);
unknown's avatar
unknown committed
664

unknown's avatar
unknown committed
665
#ifdef EXTRA_DEBUG
unknown's avatar
unknown committed
666
void my_print_open_files(void);
unknown's avatar
unknown committed
667 668 669 670
#else
#define my_print_open_files()
#endif

unknown's avatar
unknown committed
671 672 673 674
extern my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist);
extern char *my_tmpdir(MY_TMPDIR *tmpdir);
extern void free_tmpdir(MY_TMPDIR *tmpdir);

unknown's avatar
unknown committed
675
extern void my_remember_signal(int signal_number,sig_handler (*func)(int));
676
extern size_t dirname_part(char * to,const char *name, size_t *to_res_length);
677
extern size_t dirname_length(const char *name);
unknown's avatar
unknown committed
678 679
#define base_name(A) (A+dirname_length(A))
extern int test_if_hard_path(const char *dir_name);
680
extern my_bool has_path(const char *name);
681
extern char *convert_dirname(char *to, const char *from, const char *from_end);
682 683 684 685
extern void to_unix_path(char * name);
extern char * fn_ext(const char *name);
extern char * fn_same(char * toname,const char *name,int flag);
extern char * fn_format(char * to,const char *name,const char *dir,
686
			   const char *form, uint flag);
687 688
extern size_t strlength(const char *str);
extern void pack_dirname(char * to,const char *from);
689
extern size_t normalize_dirname(char * to, const char *from);
690 691 692 693 694 695 696 697
extern size_t unpack_dirname(char * to,const char *from);
extern size_t cleanup_dirname(char * to,const char *from);
extern size_t system_filename(char * to,const char *from);
extern size_t unpack_filename(char * to,const char *from);
extern char * intern_filename(char * to,const char *from);
extern char * directory_file_name(char * dst, const char *src);
extern int pack_filename(char * to, const char *name, size_t max_length);
extern char * my_path(char * to,const char *progname,
unknown's avatar
unknown committed
698
			 const char *own_pathname_part);
699
extern char * my_load_path(char * to, const char *path,
unknown's avatar
unknown committed
700
			      const char *own_path_prefix);
unknown's avatar
unknown committed
701 702
extern int wild_compare(const char *str,const char *wildstr,
                        pbool str_is_pattern);
703 704
extern my_bool array_append_string_unique(const char *str,
                                          const char **array, size_t size);
705 706
extern void get_date(char * to,int timeflag,time_t use_time);
extern void soundex(CHARSET_INFO *, char * out_pntr, char * in_pntr,
unknown's avatar
unknown committed
707
                    pbool remove_garbage);
708 709
extern int init_record_cache(RECORD_CACHE *info,size_t cachesize,File file,
			     size_t reclength,enum cache_type type,
unknown's avatar
unknown committed
710
			     pbool use_async_io);
711
extern int read_cache_record(RECORD_CACHE *info,uchar *to);
unknown's avatar
unknown committed
712 713
extern int end_record_cache(RECORD_CACHE *info);
extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos,
714
			      const uchar *record,size_t length);
unknown's avatar
unknown committed
715 716
extern int flush_write_cache(RECORD_CACHE *info);
extern void handle_recived_signals(void);
717

unknown's avatar
unknown committed
718
extern sig_handler my_set_alarm_variable(int signo);
719
extern void my_string_ptr_sort(uchar *base,uint items,size_t size);
unknown's avatar
unknown committed
720
extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
721
				  size_t size_of_element,uchar *buffer[]);
722 723 724 725
extern qsort_t my_qsort(void *base_ptr, size_t total_elems, size_t size,
                        qsort_cmp cmp);
extern qsort_t my_qsort2(void *base_ptr, size_t total_elems, size_t size,
                         qsort2_cmp cmp, void *cmp_argument);
726 727 728 729
extern qsort2_cmp get_ptr_compare(size_t);
void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos);
my_off_t my_get_ptr(uchar *ptr, size_t pack_length);
extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
unknown's avatar
unknown committed
730 731 732 733 734
			 enum cache_type type,my_off_t seek_offset,
			 pbool use_async_io, myf cache_myflags);
extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
			       my_off_t seek_offset,pbool use_async_io,
			       pbool clear_cache);
735
extern void setup_io_cache(IO_CACHE* info);
736 737
extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count);
extern int _my_b_read_r(IO_CACHE *info,uchar *Buffer,size_t Count);
738 739
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
                                IO_CACHE *write_cache, uint num_threads);
740
extern void remove_io_thread(IO_CACHE *info);
741 742
extern int _my_b_seq_read(IO_CACHE *info,uchar *Buffer,size_t Count);
extern int _my_b_net_read(IO_CACHE *info,uchar *Buffer,size_t Count);
unknown's avatar
unknown committed
743
extern int _my_b_get(IO_CACHE *info);
744 745 746 747
extern int _my_b_async_read(IO_CACHE *info,uchar *Buffer,size_t Count);
extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
extern int my_b_append(IO_CACHE *info,const uchar *Buffer,size_t Count);
extern int my_b_safe_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
748

749 750
extern int my_block_write(IO_CACHE *info, const uchar *Buffer,
			  size_t Count, my_off_t pos);
751
extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
752

753
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
754

unknown's avatar
unknown committed
755
extern int end_io_cache(IO_CACHE *info);
756
extern size_t my_b_fill(IO_CACHE *info);
757
extern void my_b_seek(IO_CACHE *info,my_off_t pos);
758
extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
759
extern my_off_t my_b_filelength(IO_CACHE *info);
760 761
extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...);
extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
unknown's avatar
unknown committed
762
extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
763
				 const char *prefix, size_t cache_size,
unknown's avatar
unknown committed
764 765 766
				 myf cache_myflags);
extern my_bool real_open_cached_file(IO_CACHE *cache);
extern void close_cached_file(IO_CACHE *cache);
767 768
File create_temp_file(char *to, const char *dir, const char *pfx,
		      int mode, myf MyFlags);
769 770 771 772 773 774 775
#define my_init_dynamic_array(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D)
#define my_init_dynamic_array_ci(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D)
#define my_init_dynamic_array2(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E)
#define my_init_dynamic_array2_ci(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E)
extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size,
                                   void *init_buffer, uint init_alloc,
                                   uint alloc_increment);
unknown's avatar
unknown committed
776
/* init_dynamic_array() function is deprecated */
777 778
extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size,
                                  uint init_alloc, uint alloc_increment);
779
extern my_bool insert_dynamic(DYNAMIC_ARRAY *array, const uchar * element);
780 781 782
extern uchar *alloc_dynamic(DYNAMIC_ARRAY *array);
extern uchar *pop_dynamic(DYNAMIC_ARRAY*);
extern my_bool set_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
783
extern my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements);
784
extern void get_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
unknown's avatar
unknown committed
785 786 787
extern void delete_dynamic(DYNAMIC_ARRAY *array);
extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index);
extern void freeze_size(DYNAMIC_ARRAY *array);
788
extern int  get_index_dynamic(DYNAMIC_ARRAY *array, uchar * element);
unknown's avatar
unknown committed
789 790
#define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element)
#define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index))
unknown's avatar
unknown committed
791
#define push_dynamic(A,B) insert_dynamic((A),(B))
unknown's avatar
unknown committed
792
#define reset_dynamic(array) ((array)->elements= 0)
793
#define sort_dynamic(A,cmp) my_qsort((A)->buffer, (A)->elements, (A)->size_of_element, (cmp))
unknown's avatar
unknown committed
794 795

extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
796
				   size_t init_alloc,size_t alloc_increment);
unknown's avatar
unknown committed
797
extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append);
798
my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
799
			  size_t length);
800 801
extern my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append,
                                       ...);
unknown's avatar
unknown committed
802
extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str);
803 804
extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size);
extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n);
unknown's avatar
unknown committed
805
extern void dynstr_free(DYNAMIC_STRING *str);
806 807
extern void dynstr_reassociate(DYNAMIC_STRING *str, char **res, size_t *length,
                               size_t *alloc_length);
unknown's avatar
unknown committed
808
#ifdef HAVE_MLOCK
809
extern void *my_malloc_lock(size_t length,myf flags);
810
extern void my_free_lock(void *ptr);
unknown's avatar
unknown committed
811 812
#else
#define my_malloc_lock(A,B) my_malloc((A),(B))
813
#define my_free_lock(A) my_free((A))
unknown's avatar
unknown committed
814
#endif
unknown's avatar
unknown committed
815
#define alloc_root_inited(A) ((A)->min_malloc != 0)
816
#define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
unknown's avatar
unknown committed
817
#define clear_alloc_root(A) do { (A)->free= (A)->used= (A)->pre_alloc= 0; (A)->min_malloc=0;} while(0)
818 819 820 821
extern void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
			    size_t pre_alloc_size);
extern void *alloc_root(MEM_ROOT *mem_root, size_t Size);
extern void *multi_alloc_root(MEM_ROOT *mem_root, ...);
unknown's avatar
unknown committed
822 823
extern void free_root(MEM_ROOT *root, myf MyFLAGS);
extern void set_prealloc_root(MEM_ROOT *root, char *ptr);
824 825
extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
                                size_t prealloc_size);
unknown's avatar
unknown committed
826
extern char *strdup_root(MEM_ROOT *root,const char *str);
827 828 829 830
static inline char *safe_strdup_root(MEM_ROOT *root, const char *str)
{
  return str ? strdup_root(root, str) : 0;
}
831 832
extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
unknown's avatar
unknown committed
833 834 835
extern int get_defaults_options(int argc, char **argv,
                                char **defaults, char **extra_defaults,
                                char **group_suffix);
836 837
extern my_bool my_getopt_use_args_separator;
extern my_bool my_getopt_is_args_separator(const char* arg);
838 839
extern int my_load_defaults(const char *conf_file, const char **groups,
                            int *argc, char ***argv, const char ***);
840
extern int load_defaults(const char *conf_file, const char **groups,
841
                         int *argc, char ***argv);
842 843
extern int my_search_option_files(const char *conf_file, int *argc,
                                  char ***argv, uint *args_used,
844 845
                                  Process_option_func func, void *func_ctx,
                                  const char **default_directories);
unknown's avatar
unknown committed
846
extern void free_defaults(char **argv);
847
extern void my_print_default_files(const char *conf_file);
unknown's avatar
unknown committed
848
extern void print_defaults(const char *conf_file, const char **groups);
849 850 851 852
extern my_bool my_compress(uchar *, size_t *, size_t *);
extern my_bool my_uncompress(uchar *, size_t , size_t *);
extern uchar *my_compress_alloc(const uchar *packet, size_t *len,
                                size_t *complen);
853 854 855 856
extern void *my_az_allocator(void *dummy, unsigned int items, unsigned int size);
extern void my_az_free(void *dummy, void *address);
extern int my_compress_buffer(uchar *dest, size_t *destLen,
                              const uchar *source, size_t sourceLen);
857
extern int packfrm(uchar *, size_t, uchar **, size_t *);
858 859 860 861
extern int unpackfrm(uchar **, size_t *, const uchar *);

extern ha_checksum my_checksum(ha_checksum crc, const uchar *mem,
                               size_t count);
unknown's avatar
unknown committed
862
#ifndef DBUG_OFF
863
extern void my_debug_put_break_here(void);
unknown's avatar
unknown committed
864
#else
unknown's avatar
unknown committed
865
#define my_debug_put_break_here() do {} while(0)
unknown's avatar
unknown committed
866 867
#endif

unknown's avatar
unknown committed
868
extern void my_sleep(ulong m_seconds);
869
extern ulong crc32(ulong crc, const uchar *buf, uint len);
870 871 872
extern uint my_set_max_open_files(uint files);
void my_free_open_file_info(void);

unknown's avatar
unknown committed
873 874
extern my_bool my_gethwaddr(uchar *to);
extern int my_getncpus();
unknown's avatar
unknown committed
875

876
#define HRTIME_RESOLUTION               1000000ULL  /* microseconds */
877 878 879
typedef struct {ulonglong val;} my_hrtime_t;
void my_time_init();
extern my_hrtime_t my_hrtime();
880
extern ulonglong my_interval_timer(void);
881
extern ulonglong my_getcputime(void);
882

883
#define microsecond_interval_timer()    (my_interval_timer()/1000)
884 885
#define hrtime_to_time(X)               ((X).val/HRTIME_RESOLUTION)
#define hrtime_from_time(X)             ((ulonglong)((X)*HRTIME_RESOLUTION))
Sergei Golubchik's avatar
Sergei Golubchik committed
886
#define hrtime_to_double(X)             ((X).val/(double)HRTIME_RESOLUTION)
887
#define hrtime_sec_part(X)              ((ulong)((X).val % HRTIME_RESOLUTION))
888 889
#define my_time(X)                      hrtime_to_time(my_hrtime())

unknown's avatar
unknown committed
890
#ifdef HAVE_SYS_MMAN_H
891 892 893 894 895
#include <sys/mman.h>

#ifndef MAP_NOSYNC
#define MAP_NOSYNC      0
#endif
896
#ifndef MAP_NORESERVE
897 898
#define MAP_NORESERVE 0         /* For irix and AIX */
#endif
899

unknown's avatar
unknown committed
900 901 902
#ifdef HAVE_MMAP64
#define my_mmap(a,b,c,d,e,f)    mmap64(a,b,c,d,e,f)
#else
903
#define my_mmap(a,b,c,d,e,f)    mmap(a,b,c,d,e,f)
unknown's avatar
unknown committed
904
#endif
unknown's avatar
unknown committed
905
#define my_munmap(a,b)          munmap((a),(b))
906 907 908 909 910

#else
/* not a complete set of mmap() flags, but only those that nesessary */
#define PROT_READ        1
#define PROT_WRITE       2
unknown's avatar
unknown committed
911
#define MAP_NORESERVE    0
unknown's avatar
unknown committed
912
#define MAP_SHARED       0x0001
913
#define MAP_PRIVATE      0x0002
unknown's avatar
unknown committed
914
#define MAP_NOSYNC       0x0800
915 916
#define MAP_FAILED       ((void *)-1)
#define MS_SYNC          0x0000
unknown's avatar
unknown committed
917

unknown's avatar
unknown committed
918
#define HAVE_MMAP
919 920 921 922
void *my_mmap(void *, size_t, int, int, int, my_off_t);
int my_munmap(void *, size_t);
#endif

unknown's avatar
unknown committed
923 924 925 926 927 928 929
/* my_getpagesize */
#ifdef HAVE_GETPAGESIZE
#define my_getpagesize()        getpagesize()
#else
int my_getpagesize(void);
#endif

930 931
int my_msync(int, void *, size_t, int);

932
#define MY_UUID_SIZE 16
unknown's avatar
unknown committed
933 934
#define MY_UUID_STRING_LENGTH (8+1+4+1+4+1+4+1+12)

935 936
void my_uuid_init(ulong seed1, ulong seed2);
void my_uuid(uchar *guid);
unknown's avatar
unknown committed
937
void my_uuid2str(const uchar *guid, char *s);
unknown's avatar
unknown committed
938
void my_uuid_end();
939 940 941 942 943 944 945 946 947

struct my_rnd_struct {
  unsigned long seed1,seed2,max_value;
  double max_value_dbl;
};

void my_rnd_init(struct my_rnd_struct *rand_st, ulong seed1, ulong seed2);
double my_rnd(struct my_rnd_struct *rand_st);

948 949 950 951 952 953 954 955 956
/* character sets */
extern uint get_charset_number(const char *cs_name, uint cs_flags);
extern uint get_collation_number(const char *name);
extern const char *get_charset_name(uint cs_number);

extern CHARSET_INFO *get_charset(uint cs_number, myf flags);
extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags);
extern CHARSET_INFO *get_charset_by_csname(const char *cs_name,
					   uint cs_flags, myf my_flags);
957

958 959 960 961 962 963
extern my_bool resolve_charset(const char *cs_name,
                               CHARSET_INFO *default_cs,
                               CHARSET_INFO **cs);
extern my_bool resolve_collation(const char *cl_name,
                                 CHARSET_INFO *default_cl,
                                 CHARSET_INFO **cl);
964
extern void free_charsets(void);
965 966 967
extern char *get_charsets_dir(char *buf);
extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2);
extern my_bool init_compiled_charsets(myf flags);
968
extern void add_compiled_collation(struct charset_info_st *cs);
969 970 971
extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info,
                                      char *to, size_t to_length,
                                      const char *from, size_t length);
972 973 974 975 976
#ifdef __WIN__
#define BACKSLASH_MBTAIL
/* File system character set */
extern CHARSET_INFO *fs_character_set(void);
#endif
977 978 979
extern size_t escape_quotes_for_mysql(CHARSET_INFO *charset_info,
                                      char *to, size_t to_length,
                                      const char *from, size_t length);
unknown's avatar
unknown committed
980

981 982 983 984
extern void thd_increment_bytes_sent(ulong length);
extern void thd_increment_bytes_received(ulong length);
extern void thd_increment_net_big_packet_count(ulong length);

unknown's avatar
unknown committed
985 986
#ifdef __WIN__
extern my_bool have_tcpip;		/* Is set if tcpip is used */
987 988 989 990 991 992 993 994

/* implemented in my_windac.c */

int my_security_attr_create(SECURITY_ATTRIBUTES **psa, const char **perror,
                            DWORD owner_rights, DWORD everybody_rights);

void my_security_attr_free(SECURITY_ATTRIBUTES *sa);

995
/* implemented in my_conio.c */
996
char* my_cgets(char *string, size_t clen, size_t* plen);
997

unknown's avatar
unknown committed
998 999
#endif

Marc Alff's avatar
Marc Alff committed
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
#include <mysql/psi/psi.h>

#ifdef HAVE_PSI_INTERFACE
extern MYSQL_PLUGIN_IMPORT struct PSI_bootstrap *PSI_hook;
void my_init_mysys_psi_keys(void);
#endif

struct st_mysql_file;
extern struct st_mysql_file *mysql_stdin;

unknown's avatar
unknown committed
1010
C_MODE_END
unknown's avatar
unknown committed
1011
#endif /* _my_sys_h */