root/trunk/dep/include/mysql/my_sys.h @ 2

Revision 2, 36.6 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

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