PageRenderTime 155ms CodeModel.GetById 64ms app.highlight 83ms RepoModel.GetById 1ms app.codeStats 0ms

/mysql/include/mysql/my_sys.h

http://ghostcb.googlecode.com/
C++ Header | 984 lines | 754 code | 98 blank | 132 comment | 8 complexity | 8171cb1d9df8cd97a6441cf5fb791c38 MD5 | raw file
  1/* Copyright (C) 2000-2003 MySQL AB
  2
  3   This program is free software; you can redistribute it and/or modify
  4   it under the terms of the GNU General Public License as published by
  5   the Free Software Foundation; version 2 of the License.
  6
  7   This program is distributed in the hope that it will be useful,
  8   but WITHOUT ANY WARRANTY; without even the implied warranty of
  9   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 10   GNU General Public License for more details.
 11
 12   You should have received a copy of the GNU General Public License
 13   along with this program; if not, write to the Free Software
 14   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 15
 16#ifndef _my_sys_h
 17#define _my_sys_h
 18C_MODE_START
 19
 20#ifdef HAVE_AIOWAIT
 21#include <sys/asynch.h>			/* Used by record-cache */
 22typedef struct my_aio_result {
 23  aio_result_t result;
 24  int	       pending;
 25} my_aio_result;
 26#endif
 27
 28#ifndef THREAD
 29extern int NEAR my_errno;		/* Last error in mysys */
 30#else
 31#include <my_pthread.h>
 32#endif
 33
 34#include <m_ctype.h>                    /* for CHARSET_INFO */
 35#include <stdarg.h>
 36#include <typelib.h>
 37
 38#define MYSYS_PROGRAM_USES_CURSES()  { error_handler_hook = my_message_curses;	mysys_uses_curses=1; }
 39#define MYSYS_PROGRAM_DONT_USE_CURSES()  { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
 40#define MY_INIT(name);		{ my_progname= name; my_init(); }
 41
 42#define ERRMSGSIZE	(SC_MAXWIDTH)	/* Max length of a error message */
 43#define NRERRBUFFS	(2)	/* Buffers for parameters */
 44#define MY_FILE_ERROR	((size_t) -1)
 45
 46	/* General bitmaps for my_func's */
 47#define MY_FFNF		1	/* Fatal if file not found */
 48#define MY_FNABP	2	/* Fatal if not all bytes read/writen */
 49#define MY_NABP		4	/* Error if not all bytes read/writen */
 50#define MY_FAE		8	/* Fatal if any error */
 51#define MY_WME		16	/* Write message on error */
 52#define MY_WAIT_IF_FULL 32	/* Wait and try again if disk full error */
 53#define MY_IGNORE_BADFD 32      /* my_sync: ignore 'bad descriptor' errors */
 54#define MY_SYNC_DIR     1024    /* my_create/delete/rename: sync directory */
 55#define MY_RAID         64      /* Support for RAID */
 56#define MY_FULL_IO     512      /* For my_read - loop intil I/O is complete */
 57#define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
 58#define MY_LINK_WARNING 32	/* my_redel() gives warning if links */
 59#define MY_COPYTIME	64	/* my_redel() copys time */
 60#define MY_DELETE_OLD	256	/* my_create_with_symlink() */
 61#define MY_RESOLVE_LINK 128	/* my_realpath(); Only resolve links */
 62#define MY_HOLD_ORIGINAL_MODES 128  /* my_copy() holds to file modes */
 63#define MY_REDEL_MAKE_BACKUP 256
 64#define MY_SEEK_NOT_DONE 32	/* my_lock may have to do a seek */
 65#define MY_DONT_WAIT	64	/* my_lock() don't wait if can't lock */
 66#define MY_ZEROFILL	32	/* my_malloc(), fill array with zero */
 67#define MY_ALLOW_ZERO_PTR 64	/* my_realloc() ; zero ptr -> malloc */
 68#define MY_FREE_ON_ERROR 128	/* my_realloc() ; Free old ptr on error */
 69#define MY_HOLD_ON_ERROR 256	/* my_realloc() ; Return old ptr on error */
 70#define MY_DONT_OVERWRITE_FILE 1024	/* my_copy: Don't overwrite file */
 71#define MY_THREADSAFE 2048      /* my_seek(): lock fd mutex */
 72
 73#define MY_CHECK_ERROR	1	/* Params to my_end; Check open-close */
 74#define MY_GIVE_INFO	2	/* Give time info about process*/
 75#define MY_DONT_FREE_DBUG 4     /* Do not call DBUG_END() in my_end() */
 76
 77#define MY_REMOVE_NONE    0     /* Params for modify_defaults_file */
 78#define MY_REMOVE_OPTION  1
 79#define MY_REMOVE_SECTION 2
 80
 81#define ME_HIGHBYTE	8	/* Shift for colours */
 82#define ME_NOCUR	1	/* Don't use curses message */
 83#define ME_OLDWIN	2	/* Use old window */
 84#define ME_BELL		4	/* Ring bell then printing message */
 85#define ME_HOLDTANG	8	/* Don't delete last keys */
 86#define ME_WAITTOT	16	/* Wait for errtime secs of for a action */
 87#define ME_WAITTANG	32	/* Wait for a user action  */
 88#define ME_NOREFRESH	64	/* Dont refresh screen */
 89#define ME_NOINPUT	128	/* Dont use the input libary */
 90#define ME_COLOUR1	((1 << ME_HIGHBYTE))	/* Possibly error-colours */
 91#define ME_COLOUR2	((2 << ME_HIGHBYTE))
 92#define ME_COLOUR3	((3 << ME_HIGHBYTE))
 93#define ME_FATALERROR   1024    /* Fatal statement error */
 94#define ME_NO_WARNING_FOR_ERROR 2048 /* Don't push a warning for error */
 95#define ME_NO_SP_HANDLER 4096 /* Don't call stored routine error handlers */
 96
 97	/* Bits in last argument to fn_format */
 98#define MY_REPLACE_DIR		1	/* replace dir in name with 'dir' */
 99#define MY_REPLACE_EXT		2	/* replace extension with 'ext' */
100#define MY_UNPACK_FILENAME	4	/* Unpack name (~ -> home) */
101#define MY_PACK_FILENAME	8	/* Pack name (home -> ~) */
102#define MY_RESOLVE_SYMLINKS	16	/* Resolve all symbolic links */
103#define MY_RETURN_REAL_PATH	32	/* return full path for file */
104#define MY_SAFE_PATH		64	/* Return NULL if too long path */
105#define MY_RELATIVE_PATH	128	/* name is relative to 'dir' */
106#define MY_APPEND_EXT           256     /* add 'ext' as additional extension*/
107
108
109	/* My seek flags */
110#define MY_SEEK_SET	0
111#define MY_SEEK_CUR	1
112#define MY_SEEK_END	2
113
114	/* Some constants */
115#define MY_WAIT_FOR_USER_TO_FIX_PANIC	60	/* in seconds */
116#define MY_WAIT_GIVE_USER_A_MESSAGE	10	/* Every 10 times of prev */
117#define MIN_COMPRESS_LENGTH		50	/* Don't compress small bl. */
118#define DFLT_INIT_HITS  3
119
120	/* root_alloc flags */
121#define MY_KEEP_PREALLOC	1
122#define MY_MARK_BLOCKS_FREE     2  /* move used to free list and reuse them */
123
124	/* Internal error numbers (for assembler functions) */
125#define MY_ERRNO_EDOM		33
126#define MY_ERRNO_ERANGE		34
127
128	/* Bits for get_date timeflag */
129#define GETDATE_DATE_TIME	1
130#define GETDATE_SHORT_DATE	2
131#define GETDATE_HHMMSSTIME	4
132#define GETDATE_GMT		8
133#define GETDATE_FIXEDLENGTH	16
134
135	/* defines when allocating data */
136#ifdef SAFEMALLOC
137#define my_malloc(SZ,FLAG) _mymalloc((SZ), __FILE__, __LINE__, FLAG )
138#define my_malloc_ci(SZ,FLAG) _mymalloc((SZ), sFile, uLine, FLAG )
139#define my_realloc(PTR,SZ,FLAG) _myrealloc((PTR), (SZ), __FILE__, __LINE__, FLAG )
140#define my_checkmalloc() _sanity( __FILE__, __LINE__ )
141#define my_free(PTR,FLAG) _myfree((PTR), __FILE__, __LINE__,FLAG)
142#define my_memdup(A,B,C) _my_memdup((A),(B), __FILE__,__LINE__,C)
143#define my_strdup(A,C) _my_strdup((A), __FILE__,__LINE__,C)
144#define my_strndup(A,B,C) _my_strndup((A),(B),__FILE__,__LINE__,C)
145#define TRASH(A,B) bfill(A, B, 0x8F)
146#define QUICK_SAFEMALLOC sf_malloc_quick=1
147#define NORMAL_SAFEMALLOC sf_malloc_quick=0
148extern uint sf_malloc_prehunc,sf_malloc_endhunc,sf_malloc_quick;
149extern ulonglong sf_malloc_mem_limit;
150
151#define CALLER_INFO_PROTO   , const char *sFile, uint uLine
152#define CALLER_INFO         , __FILE__, __LINE__
153#define ORIG_CALLER_INFO    , sFile, uLine
154#else
155#define my_checkmalloc()
156#undef TERMINATE
157#define TERMINATE(A,B) {}
158#define QUICK_SAFEMALLOC
159#define NORMAL_SAFEMALLOC
160extern void *my_malloc(size_t Size,myf MyFlags);
161#define my_malloc_ci(SZ,FLAG) my_malloc( SZ, FLAG )
162extern void *my_realloc(void *oldpoint, size_t Size, myf MyFlags);
163extern void my_no_flags_free(void *ptr);
164extern void *my_memdup(const void *from,size_t length,myf MyFlags);
165extern char *my_strdup(const char *from,myf MyFlags);
166extern char *my_strndup(const char *from, size_t length,
167				   myf MyFlags);
168/* we do use FG (as a no-op) in below so that a typo on FG is caught */
169#define my_free(PTR,FG) ((void)FG,my_no_flags_free(PTR))
170#define CALLER_INFO_PROTO   /* nothing */
171#define CALLER_INFO         /* nothing */
172#define ORIG_CALLER_INFO    /* nothing */
173#define TRASH(A,B) /* nothing */
174#endif
175
176#ifdef HAVE_LARGE_PAGES
177extern uint my_get_large_page_size(void);
178extern uchar * my_large_malloc(size_t size, myf my_flags);
179extern void my_large_free(uchar * ptr, myf my_flags);
180#else
181#define my_get_large_page_size() (0)
182#define my_large_malloc(A,B) my_malloc_lock((A),(B))
183#define my_large_free(A,B) my_free_lock((A),(B))
184#endif /* HAVE_LARGE_PAGES */
185
186#ifdef HAVE_ALLOCA
187#if defined(_AIX) && !defined(__GNUC__) && !defined(_AIX43)
188#pragma alloca
189#endif /* _AIX */
190#if defined(__MWERKS__)
191#undef alloca
192#define alloca _alloca
193#endif /* __MWERKS__ */
194#if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) && ! defined(alloca)
195#define alloca __builtin_alloca
196#endif /* GNUC */
197#define my_alloca(SZ) alloca((size_t) (SZ))
198#define my_afree(PTR) {}
199#else
200#define my_alloca(SZ) my_malloc(SZ,MYF(0))
201#define my_afree(PTR) my_free(PTR,MYF(MY_WME))
202#endif /* HAVE_ALLOCA */
203
204#ifndef errno				/* did we already get it? */
205#ifdef HAVE_ERRNO_AS_DEFINE
206#include <errno.h>			/* errno is a define */
207#else
208extern int errno;			/* declare errno */
209#endif
210#endif					/* #ifndef errno */
211extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
212extern char *home_dir;			/* Home directory for user */
213extern const char *my_progname;		/* program-name (printed in errors) */
214extern char NEAR curr_dir[];		/* Current directory for user */
215extern int (*error_handler_hook)(uint my_err, const char *str,myf MyFlags);
216extern int (*fatal_error_handler_hook)(uint my_err, const char *str,
217				       myf MyFlags);
218extern uint my_file_limit;
219extern ulong my_thread_stack_size;
220
221#ifdef HAVE_LARGE_PAGES
222extern my_bool my_use_large_pages;
223extern uint    my_large_page_size;
224#endif
225
226/* charsets */
227extern CHARSET_INFO *default_charset_info;
228extern CHARSET_INFO *all_charsets[256];
229extern CHARSET_INFO compiled_charsets[];
230
231/* statistics */
232extern ulong	my_file_opened,my_stream_opened, my_tmp_file_created;
233extern ulong    my_file_total_opened;
234extern uint	mysys_usage_id;
235extern my_bool	my_init_done;
236
237					/* Point to current my_message() */
238extern void (*my_sigtstp_cleanup)(void),
239					/* Executed before jump to shell */
240	    (*my_sigtstp_restart)(void),
241	    (*my_abort_hook)(int);
242					/* Executed when comming from shell */
243extern int NEAR my_umask,		/* Default creation mask  */
244	   NEAR my_umask_dir,
245	   NEAR my_recived_signals,	/* Signals we have got */
246	   NEAR my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */
247	   NEAR my_dont_interrupt;	/* call remember_intr when set */
248extern my_bool NEAR mysys_uses_curses, my_use_symdir;
249extern size_t sf_malloc_cur_memory, sf_malloc_max_memory;
250
251extern ulong	my_default_record_cache_size;
252extern my_bool NEAR my_disable_locking,NEAR my_disable_async_io,
253               NEAR my_disable_flush_key_blocks, NEAR my_disable_symlinks;
254extern char	wild_many,wild_one,wild_prefix;
255extern const char *charsets_dir;
256/* from default.c */
257extern char *my_defaults_extra_file;
258extern const char *my_defaults_group_suffix;
259extern const char *my_defaults_file;
260
261extern my_bool timed_mutexes;
262
263typedef struct wild_file_pack	/* Struct to hold info when selecting files */
264{
265  uint		wilds;		/* How many wildcards */
266  uint		not_pos;	/* Start of not-theese-files */
267  char *	*wild;		/* Pointer to wildcards */
268} WF_PACK;
269
270enum loglevel {
271   ERROR_LEVEL,
272   WARNING_LEVEL,
273   INFORMATION_LEVEL
274};
275
276enum cache_type
277{
278  TYPE_NOT_SET= 0, READ_CACHE, WRITE_CACHE,
279  SEQ_READ_APPEND		/* sequential read or append */,
280  READ_FIFO, READ_NET,WRITE_NET};
281
282enum flush_type
283{
284  FLUSH_KEEP,           /* flush block and keep it in the cache */
285  FLUSH_RELEASE,        /* flush block and remove it from the cache */
286  FLUSH_IGNORE_CHANGED, /* remove block from the cache */
287  /*
288    As my_disable_flush_pagecache_blocks is always 0, the following option
289    is strictly equivalent to FLUSH_KEEP
290  */
291  FLUSH_FORCE_WRITE
292};
293
294typedef struct st_record_cache	/* Used when cacheing records */
295{
296  File file;
297  int	rc_seek,error,inited;
298  uint	rc_length,read_length,reclength;
299  my_off_t rc_record_pos,end_of_file;
300  uchar *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos;
301#ifdef HAVE_AIOWAIT
302  int	use_async_io;
303  my_aio_result aio_result;
304#endif
305  enum cache_type type;
306} RECORD_CACHE;
307
308enum file_type
309{
310  UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN,
311  FILE_BY_MKSTEMP, FILE_BY_DUP
312};
313
314struct st_my_file_info
315{
316  char *		name;
317  enum file_type	type;
318#if defined(THREAD) && !defined(HAVE_PREAD)
319  pthread_mutex_t	mutex;
320#endif
321};
322
323extern struct st_my_file_info *my_file_info;
324
325typedef struct st_dynamic_array
326{
327  uchar *buffer;
328  uint elements,max_element;
329  uint alloc_increment;
330  uint size_of_element;
331} DYNAMIC_ARRAY;
332
333typedef struct st_my_tmpdir
334{
335  DYNAMIC_ARRAY full_list;
336  char **list;
337  uint cur, max;
338#ifdef THREAD
339  pthread_mutex_t mutex;
340#endif
341} MY_TMPDIR;
342
343typedef struct st_dynamic_string
344{
345  char *str;
346  size_t length,max_length,alloc_increment;
347} DYNAMIC_STRING;
348
349struct st_io_cache;
350typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
351
352#ifdef THREAD
353typedef struct st_io_cache_share
354{
355  pthread_mutex_t       mutex;           /* To sync on reads into buffer. */
356  pthread_cond_t        cond;            /* To wait for signals. */
357  pthread_cond_t        cond_writer;     /* For a synchronized writer. */
358  /* Offset in file corresponding to the first byte of buffer. */
359  my_off_t              pos_in_file;
360  /* If a synchronized write cache is the source of the data. */
361  struct st_io_cache    *source_cache;
362  uchar                 *buffer;         /* The read buffer. */
363  uchar                 *read_end;       /* Behind last valid byte of buffer. */
364  int                   running_threads; /* threads not in lock. */
365  int                   total_threads;   /* threads sharing the cache. */
366  int                   error;           /* Last error. */
367#ifdef NOT_YET_IMPLEMENTED
368  /* whether the structure should be free'd */
369  my_bool alloced;
370#endif
371} IO_CACHE_SHARE;
372#endif
373
374typedef struct st_io_cache		/* Used when cacheing files */
375{
376  /* Offset in file corresponding to the first byte of uchar* buffer. */
377  my_off_t pos_in_file;
378  /*
379    The offset of end of file for READ_CACHE and WRITE_CACHE.
380    For SEQ_READ_APPEND it the maximum of the actual end of file and
381    the position represented by read_end.
382  */
383  my_off_t end_of_file;
384  /* Points to current read position in the buffer */
385  uchar	*read_pos;
386  /* the non-inclusive boundary in the buffer for the currently valid read */
387  uchar  *read_end;
388  uchar  *buffer;				/* The read buffer */
389  /* Used in ASYNC_IO */
390  uchar  *request_pos;
391
392  /* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
393  uchar  *write_buffer;
394  /*
395    Only used in SEQ_READ_APPEND, and points to the current read position
396    in the write buffer. Note that reads in SEQ_READ_APPEND caches can
397    happen from both read buffer (uchar* buffer) and write buffer
398    (uchar* write_buffer).
399  */
400  uchar *append_read_pos;
401  /* Points to current write position in the write buffer */
402  uchar *write_pos;
403  /* The non-inclusive boundary of the valid write area */
404  uchar *write_end;
405
406  /*
407    Current_pos and current_end are convenience variables used by
408    my_b_tell() and other routines that need to know the current offset
409    current_pos points to &write_pos, and current_end to &write_end in a
410    WRITE_CACHE, and &read_pos and &read_end respectively otherwise
411  */
412  uchar  **current_pos, **current_end;
413#ifdef THREAD
414  /*
415    The lock is for append buffer used in SEQ_READ_APPEND cache
416    need mutex copying from append buffer to read buffer.
417  */
418  pthread_mutex_t append_buffer_lock;
419  /*
420    The following is used when several threads are reading the
421    same file in parallel. They are synchronized on disk
422    accesses reading the cached part of the file asynchronously.
423    It should be set to NULL to disable the feature.  Only
424    READ_CACHE mode is supported.
425  */
426  IO_CACHE_SHARE *share;
427#endif
428  /*
429    A caller will use my_b_read() macro to read from the cache
430    if the data is already in cache, it will be simply copied with
431    memcpy() and internal variables will be accordinging updated with
432    no functions invoked. However, if the data is not fully in the cache,
433    my_b_read() will call read_function to fetch the data. read_function
434    must never be invoked directly.
435  */
436  int (*read_function)(struct st_io_cache *,uchar *,size_t);
437  /*
438    Same idea as in the case of read_function, except my_b_write() needs to
439    be replaced with my_b_append() for a SEQ_READ_APPEND cache
440  */
441  int (*write_function)(struct st_io_cache *,const uchar *,size_t);
442  /*
443    Specifies the type of the cache. Depending on the type of the cache
444    certain operations might not be available and yield unpredicatable
445    results. Details to be documented later
446  */
447  enum cache_type type;
448  /*
449    Callbacks when the actual read I/O happens. These were added and
450    are currently used for binary logging of LOAD DATA INFILE - when a
451    block is read from the file, we create a block create/append event, and
452    when IO_CACHE is closed, we create an end event. These functions could,
453    of course be used for other things
454  */
455  IO_CACHE_CALLBACK pre_read;
456  IO_CACHE_CALLBACK post_read;
457  IO_CACHE_CALLBACK pre_close;
458  /*
459    Counts the number of times, when we were forced to use disk. We use it to
460    increase the binlog_cache_disk_use status variable.
461  */
462  ulong disk_writes;
463  void* arg;				/* for use by pre/post_read */
464  char *file_name;			/* if used with 'open_cached_file' */
465  char *dir,*prefix;
466  File file; /* file descriptor */
467  /*
468    seek_not_done is set by my_b_seek() to inform the upcoming read/write
469    operation that a seek needs to be preformed prior to the actual I/O
470    error is 0 if the cache operation was successful, -1 if there was a
471    "hard" error, and the actual number of I/O-ed bytes if the read/write was
472    partial.
473  */
474  int	seek_not_done,error;
475  /* buffer_length is memory size allocated for buffer or write_buffer */
476  size_t	buffer_length;
477  /* read_length is the same as buffer_length except when we use async io */
478  size_t  read_length;
479  myf	myflags;			/* Flags used to my_read/my_write */
480  /*
481    alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
482    0 if it was supplied by the user.
483    Currently READ_NET is the only one that will use a buffer allocated
484    somewhere else
485  */
486  my_bool alloced_buffer;
487#ifdef HAVE_AIOWAIT
488  /*
489    As inidicated by ifdef, this is for async I/O, which is not currently
490    used (because it's not reliable on all systems)
491  */
492  uint inited;
493  my_off_t aio_read_pos;
494  my_aio_result aio_result;
495#endif
496} IO_CACHE;
497
498typedef int (*qsort2_cmp)(const void *, const void *, const void *);
499
500	/* defines for mf_iocache */
501
502	/* Test if buffer is inited */
503#define my_b_clear(info) (info)->buffer=0
504#define my_b_inited(info) (info)->buffer
505#define my_b_EOF INT_MIN
506
507#define my_b_read(info,Buffer,Count) \
508  ((info)->read_pos + (Count) <= (info)->read_end ?\
509   (memcpy(Buffer,(info)->read_pos,(size_t) (Count)), \
510    ((info)->read_pos+=(Count)),0) :\
511   (*(info)->read_function)((info),Buffer,Count))
512
513#define my_b_write(info,Buffer,Count) \
514 ((info)->write_pos + (Count) <=(info)->write_end ?\
515  (memcpy((info)->write_pos, (Buffer), (size_t)(Count)),\
516   ((info)->write_pos+=(Count)),0) : \
517   (*(info)->write_function)((info),(Buffer),(Count)))
518
519#define my_b_get(info) \
520  ((info)->read_pos != (info)->read_end ?\
521   ((info)->read_pos++, (int) (uchar) (info)->read_pos[-1]) :\
522   _my_b_get(info))
523
524	/* my_b_write_byte dosn't have any err-check */
525#define my_b_write_byte(info,chr) \
526  (((info)->write_pos < (info)->write_end) ?\
527   ((*(info)->write_pos++)=(chr)) :\
528   (_my_b_write(info,0,0) , ((*(info)->write_pos++)=(chr))))
529
530#define my_b_fill_cache(info) \
531  (((info)->read_end=(info)->read_pos),(*(info)->read_function)(info,0,0))
532
533#define my_b_tell(info) ((info)->pos_in_file + \
534			 (size_t) (*(info)->current_pos - (info)->request_pos))
535
536#define my_b_get_buffer_start(info) (info)->request_pos 
537#define my_b_get_bytes_in_buffer(info) (char*) (info)->read_end -   \
538  (char*) my_b_get_buffer_start(info)
539#define my_b_get_pos_in_file(info) (info)->pos_in_file
540
541/* tell write offset in the SEQ_APPEND cache */
542int      my_b_copy_to_file(IO_CACHE *cache, FILE *file);
543my_off_t my_b_append_tell(IO_CACHE* info);
544my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
545
546#define my_b_bytes_in_cache(info) (size_t) (*(info)->current_end - \
547					  *(info)->current_pos)
548
549typedef uint32 ha_checksum;
550
551/* Define the type of function to be passed to process_default_option_files */
552typedef int (*Process_option_func)(void *ctx, const char *group_name,
553                                   const char *option);
554
555#include <my_alloc.h>
556
557
558	/* Prototypes for mysys and my_func functions */
559
560extern int my_copy(const char *from,const char *to,myf MyFlags);
561extern int my_append(const char *from,const char *to,myf MyFlags);
562extern int my_delete(const char *name,myf MyFlags);
563extern int my_getwd(char * buf,size_t size,myf MyFlags);
564extern int my_setwd(const char *dir,myf MyFlags);
565extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags);
566extern void *my_once_alloc(size_t Size,myf MyFlags);
567extern void my_once_free(void);
568extern char *my_once_strdup(const char *src,myf myflags);
569extern void *my_once_memdup(const void *src, size_t len, myf myflags);
570extern File my_open(const char *FileName,int Flags,myf MyFlags);
571extern File my_register_filename(File fd, const char *FileName,
572				 enum file_type type_of_file,
573				 uint error_message_number, myf MyFlags);
574extern File my_create(const char *FileName,int CreateFlags,
575		      int AccessFlags, myf MyFlags);
576extern int my_close(File Filedes,myf MyFlags);
577extern File my_dup(File file, myf MyFlags);
578extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
579extern int my_readlink(char *to, const char *filename, myf MyFlags);
580extern int my_is_symlink(const char *filename);
581extern int my_realpath(char *to, const char *filename, myf MyFlags);
582extern File my_create_with_symlink(const char *linkname, const char *filename,
583				   int createflags, int access_flags,
584				   myf MyFlags);
585extern int my_delete_with_symlink(const char *name, myf MyFlags);
586extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags);
587extern int my_symlink(const char *content, const char *linkname, myf MyFlags);
588extern size_t my_read(File Filedes,uchar *Buffer,size_t Count,myf MyFlags);
589extern size_t my_pread(File Filedes,uchar *Buffer,size_t Count,my_off_t offset,
590		     myf MyFlags);
591extern int my_rename(const char *from,const char *to,myf MyFlags);
592extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags);
593extern my_off_t my_tell(File fd,myf MyFlags);
594extern size_t my_write(File Filedes,const uchar *Buffer,size_t Count,
595		     myf MyFlags);
596extern size_t my_pwrite(File Filedes,const uchar *Buffer,size_t Count,
597		      my_off_t offset,myf MyFlags);
598extern size_t my_fread(FILE *stream,uchar *Buffer,size_t Count,myf MyFlags);
599extern size_t my_fwrite(FILE *stream,const uchar *Buffer,size_t Count,
600		      myf MyFlags);
601extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags);
602extern my_off_t my_ftell(FILE *stream,myf MyFlags);
603extern void *_mymalloc(size_t uSize,const char *sFile,
604                       uint uLine, myf MyFlag);
605extern void *_myrealloc(void *pPtr,size_t uSize,const char *sFile,
606		       uint uLine, myf MyFlag);
607extern void * my_multi_malloc _VARARGS((myf MyFlags, ...));
608extern void _myfree(void *pPtr,const char *sFile,uint uLine, myf MyFlag);
609extern int _sanity(const char *sFile, uint uLine);
610extern void *_my_memdup(const void *from, size_t length,
611                        const char *sFile, uint uLine,myf MyFlag);
612extern char * _my_strdup(const char *from, const char *sFile, uint uLine,
613                         myf MyFlag);
614extern char *_my_strndup(const char *from, size_t length,
615                         const char *sFile, uint uLine,
616                         myf MyFlag);
617
618/* implemented in my_memmem.c */
619extern void *my_memmem(const void *haystack, size_t haystacklen,
620                       const void *needle, size_t needlelen);
621
622
623#ifdef __WIN__
624extern int my_access(const char *path, int amode);
625extern File my_sopen(const char *path, int oflag, int shflag, int pmode);
626#else
627#define my_access access
628#endif
629extern int check_if_legal_filename(const char *path);
630extern int check_if_legal_tablename(const char *path);
631
632#if defined(__WIN__) && defined(__NT__)
633extern int nt_share_delete(const char *name,myf MyFlags);
634#define my_delete_allow_opened(fname,flags)  nt_share_delete((fname),(flags))
635#else
636#define my_delete_allow_opened(fname,flags)  my_delete((fname),(flags))
637#endif
638
639#ifndef TERMINATE
640extern void TERMINATE(FILE *file, uint flag);
641#endif
642extern void init_glob_errs(void);
643extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
644extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
645extern int my_fclose(FILE *fd,myf MyFlags);
646extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
647extern int my_sync(File fd, myf my_flags);
648extern int my_sync_dir(const char *dir_name, myf my_flags);
649extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
650extern int my_error _VARARGS((int nr,myf MyFlags, ...));
651extern int my_printf_error _VARARGS((uint my_err, const char *format,
652				     myf MyFlags, ...))
653				    ATTRIBUTE_FORMAT(printf, 2, 4);
654extern int my_error_register(const char **errmsgs, int first, int last);
655extern const char **my_error_unregister(int first, int last);
656extern int my_message(uint my_err, const char *str,myf MyFlags);
657extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags);
658extern int my_message_curses(uint my_err, const char *str,myf MyFlags);
659extern my_bool my_init(void);
660extern void my_end(int infoflag);
661extern int my_redel(const char *from, const char *to, int MyFlags);
662extern int my_copystat(const char *from, const char *to, int MyFlags);
663extern char * my_filename(File fd);
664
665#ifndef THREAD
666extern void dont_break(void);
667extern void allow_break(void);
668#else
669#define dont_break()
670#define allow_break()
671#endif
672
673#ifdef EXTRA_DEBUG
674void my_print_open_files(void);
675#else
676#define my_print_open_files()
677#endif
678
679extern my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist);
680extern char *my_tmpdir(MY_TMPDIR *tmpdir);
681extern void free_tmpdir(MY_TMPDIR *tmpdir);
682
683extern void my_remember_signal(int signal_number,sig_handler (*func)(int));
684extern size_t dirname_part(char * to,const char *name, size_t *to_res_length);
685extern size_t dirname_length(const char *name);
686#define base_name(A) (A+dirname_length(A))
687extern int test_if_hard_path(const char *dir_name);
688extern my_bool has_path(const char *name);
689extern char *convert_dirname(char *to, const char *from, const char *from_end);
690extern void to_unix_path(char * name);
691extern char * fn_ext(const char *name);
692extern char * fn_same(char * toname,const char *name,int flag);
693extern char * fn_format(char * to,const char *name,const char *dir,
694			   const char *form, uint flag);
695extern size_t strlength(const char *str);
696extern void pack_dirname(char * to,const char *from);
697extern size_t normalize_dirname(char * to, const char *from);
698extern size_t unpack_dirname(char * to,const char *from);
699extern size_t cleanup_dirname(char * to,const char *from);
700extern size_t system_filename(char * to,const char *from);
701extern size_t unpack_filename(char * to,const char *from);
702extern char * intern_filename(char * to,const char *from);
703extern char * directory_file_name(char * dst, const char *src);
704extern int pack_filename(char * to, const char *name, size_t max_length);
705extern char * my_path(char * to,const char *progname,
706			 const char *own_pathname_part);
707extern char * my_load_path(char * to, const char *path,
708			      const char *own_path_prefix);
709extern int wild_compare(const char *str,const char *wildstr,
710                        pbool str_is_pattern);
711extern WF_PACK *wf_comp(char * str);
712extern int wf_test(struct wild_file_pack *wf_pack,const char *name);
713extern void wf_end(struct wild_file_pack *buffer);
714extern size_t strip_sp(char * str);
715extern my_bool array_append_string_unique(const char *str,
716                                          const char **array, size_t size);
717extern void get_date(char * to,int timeflag,time_t use_time);
718extern void soundex(CHARSET_INFO *, char * out_pntr, char * in_pntr,
719                    pbool remove_garbage);
720extern int init_record_cache(RECORD_CACHE *info,size_t cachesize,File file,
721			     size_t reclength,enum cache_type type,
722			     pbool use_async_io);
723extern int read_cache_record(RECORD_CACHE *info,uchar *to);
724extern int end_record_cache(RECORD_CACHE *info);
725extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos,
726			      const uchar *record,size_t length);
727extern int flush_write_cache(RECORD_CACHE *info);
728extern long my_clock(void);
729extern sig_handler sigtstp_handler(int signal_number);
730extern void handle_recived_signals(void);
731
732extern sig_handler my_set_alarm_variable(int signo);
733extern void my_string_ptr_sort(uchar *base,uint items,size_t size);
734extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
735				  size_t size_of_element,uchar *buffer[]);
736extern qsort_t my_qsort(void *base_ptr, size_t total_elems, size_t size,
737                        qsort_cmp cmp);
738extern qsort_t my_qsort2(void *base_ptr, size_t total_elems, size_t size,
739                         qsort2_cmp cmp, void *cmp_argument);
740extern qsort2_cmp get_ptr_compare(size_t);
741void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos);
742my_off_t my_get_ptr(uchar *ptr, size_t pack_length);
743extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
744			 enum cache_type type,my_off_t seek_offset,
745			 pbool use_async_io, myf cache_myflags);
746extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
747			       my_off_t seek_offset,pbool use_async_io,
748			       pbool clear_cache);
749extern void setup_io_cache(IO_CACHE* info);
750extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count);
751#ifdef THREAD
752extern int _my_b_read_r(IO_CACHE *info,uchar *Buffer,size_t Count);
753extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
754                                IO_CACHE *write_cache, uint num_threads);
755extern void remove_io_thread(IO_CACHE *info);
756#endif
757extern int _my_b_seq_read(IO_CACHE *info,uchar *Buffer,size_t Count);
758extern int _my_b_net_read(IO_CACHE *info,uchar *Buffer,size_t Count);
759extern int _my_b_get(IO_CACHE *info);
760extern int _my_b_async_read(IO_CACHE *info,uchar *Buffer,size_t Count);
761extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
762extern int my_b_append(IO_CACHE *info,const uchar *Buffer,size_t Count);
763extern int my_b_safe_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
764
765extern int my_block_write(IO_CACHE *info, const uchar *Buffer,
766			  size_t Count, my_off_t pos);
767extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
768
769#define flush_io_cache(info) my_b_flush_io_cache((info),1)
770
771extern int end_io_cache(IO_CACHE *info);
772extern size_t my_b_fill(IO_CACHE *info);
773extern void my_b_seek(IO_CACHE *info,my_off_t pos);
774extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
775extern my_off_t my_b_filelength(IO_CACHE *info);
776extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...);
777extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
778extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
779				 const char *prefix, size_t cache_size,
780				 myf cache_myflags);
781extern my_bool real_open_cached_file(IO_CACHE *cache);
782extern void close_cached_file(IO_CACHE *cache);
783File create_temp_file(char *to, const char *dir, const char *pfx,
784		      int mode, myf MyFlags);
785#define my_init_dynamic_array(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D CALLER_INFO)
786#define my_init_dynamic_array_ci(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D ORIG_CALLER_INFO)
787#define my_init_dynamic_array2(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E CALLER_INFO)
788#define my_init_dynamic_array2_ci(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E ORIG_CALLER_INFO)
789extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array,uint element_size,
790                                   void *init_buffer, uint init_alloc, 
791                                   uint alloc_increment
792                                   CALLER_INFO_PROTO);
793/* init_dynamic_array() function is deprecated */
794extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size,
795                                  uint init_alloc,uint alloc_increment
796                                  CALLER_INFO_PROTO);
797extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,uchar * element);
798extern uchar *alloc_dynamic(DYNAMIC_ARRAY *array);
799extern uchar *pop_dynamic(DYNAMIC_ARRAY*);
800extern my_bool set_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
801extern my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements);
802extern void get_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
803extern void delete_dynamic(DYNAMIC_ARRAY *array);
804extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index);
805extern void freeze_size(DYNAMIC_ARRAY *array);
806extern int  get_index_dynamic(DYNAMIC_ARRAY *array, uchar * element);
807#define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element)
808#define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index))
809#define push_dynamic(A,B) insert_dynamic((A),(B))
810#define reset_dynamic(array) ((array)->elements= 0)
811#define sort_dynamic(A,cmp) my_qsort((A)->buffer, (A)->elements, (A)->size_of_element, (cmp))
812
813extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
814				   size_t init_alloc,size_t alloc_increment);
815extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append);
816my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
817			  size_t length);
818extern my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append,
819                                       ...);
820extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str);
821extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size);
822extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n);
823extern void dynstr_free(DYNAMIC_STRING *str);
824#ifdef HAVE_MLOCK
825extern void *my_malloc_lock(size_t length,myf flags);
826extern void my_free_lock(void *ptr,myf flags);
827#else
828#define my_malloc_lock(A,B) my_malloc((A),(B))
829#define my_free_lock(A,B) my_free((A),(B))
830#endif
831#define alloc_root_inited(A) ((A)->min_malloc != 0)
832#define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
833#define clear_alloc_root(A) do { (A)->free= (A)->used= (A)->pre_alloc= 0; (A)->min_malloc=0;} while(0)
834extern void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
835			    size_t pre_alloc_size);
836extern void *alloc_root(MEM_ROOT *mem_root, size_t Size);
837extern void *multi_alloc_root(MEM_ROOT *mem_root, ...);
838extern void free_root(MEM_ROOT *root, myf MyFLAGS);
839extern void set_prealloc_root(MEM_ROOT *root, char *ptr);
840extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
841                                size_t prealloc_size);
842extern char *strdup_root(MEM_ROOT *root,const char *str);
843extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
844extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
845extern int get_defaults_options(int argc, char **argv,
846                                char **defaults, char **extra_defaults,
847                                char **group_suffix);
848extern int load_defaults(const char *conf_file, const char **groups,
849			 int *argc, char ***argv);
850extern int modify_defaults_file(const char *file_location, const char *option,
851                                const char *option_value,
852                                const char *section_name, int remove_option);
853extern int my_search_option_files(const char *conf_file, int *argc,
854                                  char ***argv, uint *args_used,
855                                  Process_option_func func, void *func_ctx);
856extern void free_defaults(char **argv);
857extern void my_print_default_files(const char *conf_file);
858extern void print_defaults(const char *conf_file, const char **groups);
859extern my_bool my_compress(uchar *, size_t *, size_t *);
860extern my_bool my_uncompress(uchar *, size_t , size_t *);
861extern uchar *my_compress_alloc(const uchar *packet, size_t *len,
862                                size_t *complen);
863extern int packfrm(uchar *, size_t, uchar **, size_t *);
864extern int unpackfrm(uchar **, size_t *, const uchar *);
865
866extern ha_checksum my_checksum(ha_checksum crc, const uchar *mem,
867                               size_t count);
868extern void my_sleep(ulong m_seconds);
869extern ulong crc32(ulong crc, const uchar *buf, uint len);
870extern uint my_set_max_open_files(uint files);
871void my_free_open_file_info(void);
872
873extern time_t my_time(myf flags);
874extern ulonglong my_getsystime(void);
875extern ulonglong my_micro_time();
876extern ulonglong my_micro_time_and_time(time_t *time_arg);
877time_t my_time_possible_from_micro(ulonglong microtime);
878extern my_bool my_gethwaddr(uchar *to);
879extern int my_getncpus();
880
881#ifdef HAVE_SYS_MMAN_H
882#include <sys/mman.h>
883
884#ifndef MAP_NOSYNC
885#define MAP_NOSYNC      0
886#endif
887#ifndef MAP_NORESERVE
888#define MAP_NORESERVE 0         /* For irix and AIX */
889#endif
890
891#ifdef HAVE_MMAP64
892#define my_mmap(a,b,c,d,e,f)    mmap64(a,b,c,d,e,f)
893#else
894#define my_mmap(a,b,c,d,e,f)    mmap(a,b,c,d,e,f)
895#endif
896#define my_munmap(a,b)          munmap((a),(b))
897
898#else
899/* not a complete set of mmap() flags, but only those that nesessary */
900#define PROT_READ        1
901#define PROT_WRITE       2
902#define MAP_NORESERVE    0
903#define MAP_SHARED       0x0001
904#define MAP_PRIVATE      0x0002
905#define MAP_NOSYNC       0x0800
906#define MAP_FAILED       ((void *)-1)
907#define MS_SYNC          0x0000
908
909#ifndef __NETWARE__
910#define HAVE_MMAP
911#endif
912
913void *my_mmap(void *, size_t, int, int, int, my_off_t);
914int my_munmap(void *, size_t);
915#endif
916
917/* my_getpagesize */
918#ifdef HAVE_GETPAGESIZE
919#define my_getpagesize()        getpagesize()
920#else
921int my_getpagesize(void);
922#endif
923
924int my_msync(int, void *, size_t, int);
925
926/* character sets */
927extern uint get_charset_number(const char *cs_name, uint cs_flags);
928extern uint get_collation_number(const char *name);
929extern const char *get_charset_name(uint cs_number);
930
931extern CHARSET_INFO *get_charset(uint cs_number, myf flags);
932extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags);
933extern CHARSET_INFO *get_charset_by_csname(const char *cs_name,
934					   uint cs_flags, myf my_flags);
935
936extern my_bool resolve_charset(const char *cs_name,
937                               CHARSET_INFO *default_cs,
938                               CHARSET_INFO **cs);
939extern my_bool resolve_collation(const char *cl_name,
940                                 CHARSET_INFO *default_cl,
941                                 CHARSET_INFO **cl);
942
943extern void free_charsets(void);
944extern char *get_charsets_dir(char *buf);
945extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2);
946extern my_bool init_compiled_charsets(myf flags);
947extern void add_compiled_collation(CHARSET_INFO *cs);
948extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info,
949                                      char *to, size_t to_length,
950                                      const char *from, size_t length);
951#ifdef __WIN__
952#define BACKSLASH_MBTAIL
953/* File system character set */
954extern CHARSET_INFO *fs_character_set(void);
955#endif
956extern size_t escape_quotes_for_mysql(CHARSET_INFO *charset_info,
957                                      char *to, size_t to_length,
958                                      const char *from, size_t length);
959
960extern void thd_increment_bytes_sent(ulong length);
961extern void thd_increment_bytes_received(ulong length);
962extern void thd_increment_net_big_packet_count(ulong length);
963
964#ifdef __WIN__
965extern my_bool have_tcpip;		/* Is set if tcpip is used */
966
967/* implemented in my_windac.c */
968
969int my_security_attr_create(SECURITY_ATTRIBUTES **psa, const char **perror,
970                            DWORD owner_rights, DWORD everybody_rights);
971
972void my_security_attr_free(SECURITY_ATTRIBUTES *sa);
973
974/* implemented in my_conio.c */
975char* my_cgets(char *string, size_t clen, size_t* plen);
976
977#endif
978#ifdef __NETWARE__
979void netware_reg_user(const char *ip, const char *user,
980		      const char *application);
981#endif
982
983C_MODE_END
984#endif /* _my_sys_h */