my_sys.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000-2003 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; either version 2 of the License, or
00006    (at your option) any later version.
00007 
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011    GNU General Public License for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; if not, write to the Free Software
00015    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00016 
00017 #ifndef _my_sys_h
00018 #define _my_sys_h
00019 C_MODE_START
00020 
00021 #ifdef HAVE_AIOWAIT
00022 #include <sys/asynch.h>                 /* Used by record-cache */
00023 typedef struct my_aio_result {
00024   aio_result_t result;
00025   int          pending;
00026 } my_aio_result;
00027 #endif
00028 
00029 #ifndef THREAD
00030 extern int NEAR my_errno;               /* Last error in mysys */
00031 #else
00032 #include <my_pthread.h>
00033 #endif
00034 
00035 #ifndef _m_ctype_h
00036 #include <m_ctype.h>                    /* for CHARSET_INFO */
00037 #endif
00038 
00039 #include <stdarg.h>
00040 #include <typelib.h>
00041 
00042 #define MYSYS_PROGRAM_USES_CURSES()  { error_handler_hook = my_message_curses;  mysys_uses_curses=1; }
00043 #define MYSYS_PROGRAM_DONT_USE_CURSES()  { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
00044 #define MY_INIT(name);          { my_progname= name; my_init(); }
00045 
00046 #define MAXMAPS         (4)     /* Number of error message maps */
00047 #define ERRMOD          (1000)  /* Max number of errors in a map */
00048 #define ERRMSGSIZE      (SC_MAXWIDTH)   /* Max length of a error message */
00049 #define NRERRBUFFS      (2)     /* Buffers for parameters */
00050 #define MY_FILE_ERROR   ((uint) ~0)
00051 
00052         /* General bitmaps for my_func's */
00053 #define MY_FFNF         1       /* Fatal if file not found */
00054 #define MY_FNABP        2       /* Fatal if not all bytes read/writen */
00055 #define MY_NABP         4       /* Error if not all bytes read/writen */
00056 #define MY_FAE          8       /* Fatal if any error */
00057 #define MY_WME          16      /* Write message on error */
00058 #define MY_WAIT_IF_FULL 32      /* Wait and try again if disk full error */
00059 #define MY_RAID         64      /* Support for RAID (not the "Johnson&Johnson"-s one ;) */
00060 #define MY_FULL_IO     512      /* For my_read - loop intil I/O
00061                                    is complete
00062                                 */
00063 #define MY_DONT_CHECK_FILESIZE 128      /* Option to init_io_cache() */
00064 #define MY_LINK_WARNING 32      /* my_redel() gives warning if links */
00065 #define MY_COPYTIME     64      /* my_redel() copys time */
00066 #define MY_DELETE_OLD   256     /* my_create_with_symlink() */
00067 #define MY_RESOLVE_LINK 128     /* my_realpath(); Only resolve links */
00068 #define MY_HOLD_ORIGINAL_MODES 128  /* my_copy() holds to file modes */
00069 #define MY_REDEL_MAKE_BACKUP 256
00070 #define MY_SEEK_NOT_DONE 32     /* my_lock may have to do a seek */
00071 #define MY_DONT_WAIT    64      /* my_lock() don't wait if can't lock */
00072 #define MY_ZEROFILL     32      /* my_malloc(), fill array with zero */
00073 #define MY_ALLOW_ZERO_PTR 64    /* my_realloc() ; zero ptr -> malloc */
00074 #define MY_FREE_ON_ERROR 128    /* my_realloc() ; Free old ptr on error */
00075 #define MY_HOLD_ON_ERROR 256    /* my_realloc() ; Return old ptr on error */
00076 #define MY_THREADSAFE   128     /* pread/pwrite:  Don't allow interrupts */
00077 #define MY_DONT_OVERWRITE_FILE 1024     /* my_copy; Don't overwrite file */
00078 
00079 #define MY_CHECK_ERROR  1       /* Params to my_end; Check open-close */
00080 #define MY_GIVE_INFO    2       /* Give time info about process*/
00081 
00082 #define ME_HIGHBYTE     8       /* Shift for colours */
00083 #define ME_NOCUR        1       /* Don't use curses message */
00084 #define ME_OLDWIN       2       /* Use old window */
00085 #define ME_BELL         4       /* Ring bell then printing message */
00086 #define ME_HOLDTANG     8       /* Don't delete last keys */
00087 #define ME_WAITTOT      16      /* Wait for errtime secs of for a action */
00088 #define ME_WAITTANG     32      /* Wait for a user action  */
00089 #define ME_NOREFRESH    64      /* Dont refresh screen */
00090 #define ME_NOINPUT      128     /* Dont use the input libary */
00091 #define ME_COLOUR1      ((1 << ME_HIGHBYTE))    /* Possibly error-colours */
00092 #define ME_COLOUR2      ((2 << ME_HIGHBYTE))
00093 #define ME_COLOUR3      ((3 << ME_HIGHBYTE))
00094 
00095         /* Bits in last argument to fn_format */
00096 #define MY_REPLACE_DIR          1       /* replace dir in name with 'dir' */
00097 #define MY_REPLACE_EXT          2       /* replace extension with 'ext' */
00098 #define MY_UNPACK_FILENAME      4       /* Unpack name (~ -> home) */
00099 #define MY_PACK_FILENAME        8       /* Pack name (home -> ~) */
00100 #define MY_RESOLVE_SYMLINKS     16      /* Resolve all symbolic links */
00101 #define MY_RETURN_REAL_PATH     32      /* return full path for file */
00102 #define MY_SAFE_PATH            64      /* Return NULL if too long path */
00103 #define MY_RELATIVE_PATH        128     /* name is relative to 'dir' */
00104 
00105         /* My seek flags */
00106 #define MY_SEEK_SET     0
00107 #define MY_SEEK_CUR     1
00108 #define MY_SEEK_END     2
00109 
00110         /* Some constants */
00111 #define MY_WAIT_FOR_USER_TO_FIX_PANIC   60      /* in seconds */
00112 #define MY_WAIT_GIVE_USER_A_MESSAGE     10      /* Every 10 times of prev */
00113 #define MIN_COMPRESS_LENGTH             50      /* Don't compress small bl. */
00114 #define DFLT_INIT_HITS  3
00115 
00116         /* root_alloc flags */
00117 #define MY_KEEP_PREALLOC        1
00118 #define MY_MARK_BLOCKS_FREE     2  /* move used to free list and reuse them */
00119 
00120         /* Internal error numbers (for assembler functions) */
00121 #define MY_ERRNO_EDOM           33
00122 #define MY_ERRNO_ERANGE         34
00123 
00124         /* Bits for get_date timeflag */
00125 #define GETDATE_DATE_TIME       1
00126 #define GETDATE_SHORT_DATE      2
00127 #define GETDATE_HHMMSSTIME      4
00128 #define GETDATE_GMT             8
00129 #define GETDATE_FIXEDLENGTH     16
00130 
00131         /* defines when allocating data */
00132 #ifdef SAFEMALLOC
00133 #define my_malloc(SZ,FLAG) _mymalloc((SZ), __FILE__, __LINE__, FLAG )
00134 #define my_malloc_ci(SZ,FLAG) _mymalloc((SZ), sFile, uLine, FLAG )
00135 #define my_realloc(PTR,SZ,FLAG) _myrealloc((PTR), (SZ), __FILE__, __LINE__, FLAG )
00136 #define my_checkmalloc() _sanity( __FILE__, __LINE__ )
00137 #define my_free(PTR,FLAG) _myfree((PTR), __FILE__, __LINE__,FLAG)
00138 #define my_memdup(A,B,C) _my_memdup((A),(B), __FILE__,__LINE__,C)
00139 #define my_strdup(A,C) _my_strdup((A), __FILE__,__LINE__,C)
00140 #define my_strdup_with_length(A,B,C) _my_strdup_with_length((A),(B),__FILE__,__LINE__,C)
00141 #define TRASH(A,B) bfill(A, B, 0x8F)
00142 #define QUICK_SAFEMALLOC sf_malloc_quick=1
00143 #define NORMAL_SAFEMALLOC sf_malloc_quick=0
00144 extern uint sf_malloc_prehunc,sf_malloc_endhunc,sf_malloc_quick;
00145 extern ulonglong sf_malloc_mem_limit;
00146 
00147 #define CALLER_INFO_PROTO   , const char *sFile, uint uLine
00148 #define CALLER_INFO         , __FILE__, __LINE__
00149 #define ORIG_CALLER_INFO    , sFile, uLine
00150 #else
00151 #define my_checkmalloc()
00152 #undef TERMINATE
00153 #define TERMINATE(A) {}
00154 #define QUICK_SAFEMALLOC
00155 #define NORMAL_SAFEMALLOC
00156 extern gptr my_malloc(uint Size,myf MyFlags);
00157 #define my_malloc_ci(SZ,FLAG) my_malloc( SZ, FLAG )
00158 extern gptr my_realloc(gptr oldpoint,uint Size,myf MyFlags);
00159 extern void my_no_flags_free(gptr ptr);
00160 extern gptr my_memdup(const byte *from,uint length,myf MyFlags);
00161 extern char *my_strdup(const char *from,myf MyFlags);
00162 extern char *my_strdup_with_length(const byte *from, uint length,
00163                                    myf MyFlags);
00164 #define my_free(PTR,FG) my_no_flags_free(PTR)
00165 #define CALLER_INFO_PROTO   /* nothing */
00166 #define CALLER_INFO         /* nothing */
00167 #define ORIG_CALLER_INFO    /* nothing */
00168 #define TRASH(A,B) /* nothing */
00169 #endif
00170 
00171 #ifdef HAVE_ALLOCA
00172 #if defined(_AIX) && !defined(__GNUC__) && !defined(_AIX43)
00173 #pragma alloca
00174 #endif /* _AIX */
00175 #if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) && ! defined(alloca)
00176 #define alloca __builtin_alloca
00177 #endif /* GNUC */
00178 #define my_alloca(SZ) alloca((size_t) (SZ))
00179 #define my_afree(PTR) {}
00180 #else
00181 #define my_alloca(SZ) my_malloc(SZ,MYF(0))
00182 #define my_afree(PTR) my_free(PTR,MYF(MY_WME))
00183 #endif /* HAVE_ALLOCA */
00184 
00185 #ifdef MSDOS
00186 #ifdef __ZTC__
00187 void * __CDECL halloc(long count,size_t length);
00188 void   __CDECL hfree(void *ptr);
00189 #endif
00190 #if defined(USE_HALLOC)
00191 #if defined(_VCM_) || defined(M_IC80386)
00192 #undef USE_HALLOC
00193 #endif
00194 #endif
00195 #ifdef USE_HALLOC
00196 #define malloc(a) halloc((long) (a),1)
00197 #define free(a) hfree(a)
00198 #endif
00199 #endif /* MSDOS */
00200 
00201 #ifdef HAVE_ERRNO_AS_DEFINE
00202 #include <errno.h>                      /* errno is a define */
00203 #else
00204 extern int errno;                       /* declare errno */
00205 #endif
00206 extern const char ** NEAR my_errmsg[];
00207 extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
00208 extern char *home_dir;                  /* Home directory for user */
00209 extern char *my_progname;               /* program-name (printed in errors) */
00210 extern char NEAR curr_dir[];            /* Current directory for user */
00211 extern int (*error_handler_hook)(uint my_err, const char *str,myf MyFlags);
00212 extern int (*fatal_error_handler_hook)(uint my_err, const char *str,
00213                                        myf MyFlags);
00214 extern uint my_file_limit;
00215 
00216 /* charsets */
00217 extern CHARSET_INFO *default_charset_info;
00218 extern CHARSET_INFO *all_charsets[256];
00219 extern CHARSET_INFO compiled_charsets[];
00220 
00221 /* statistics */
00222 extern ulong    my_cache_w_requests, my_cache_write, my_cache_r_requests,
00223                 my_cache_read;
00224 extern ulong    my_blocks_used, my_blocks_changed;
00225 extern ulong    my_file_opened,my_stream_opened, my_tmp_file_created;
00226 extern uint     mysys_usage_id;
00227 extern my_bool  my_init_done;
00228 
00229                                         /* Point to current my_message() */
00230 extern void (*my_sigtstp_cleanup)(void),
00231                                         /* Executed before jump to shell */
00232             (*my_sigtstp_restart)(void),
00233             (*my_abort_hook)(int);
00234                                         /* Executed when comming from shell */
00235 extern int NEAR my_umask,               /* Default creation mask  */
00236            NEAR my_umask_dir,
00237            NEAR my_recived_signals,     /* Signals we have got */
00238            NEAR my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */
00239            NEAR my_dont_interrupt;      /* call remember_intr when set */
00240 extern my_bool NEAR mysys_uses_curses, my_use_symdir;
00241 extern ulong sf_malloc_cur_memory, sf_malloc_max_memory;
00242 
00243 extern ulong    my_default_record_cache_size;
00244 extern my_bool NEAR my_disable_locking,NEAR my_disable_async_io,
00245                NEAR my_disable_flush_key_blocks, NEAR my_disable_symlinks;
00246 extern char     wild_many,wild_one,wild_prefix;
00247 extern const char *charsets_dir;
00248 extern char *defaults_extra_file;
00249 
00250 typedef struct wild_file_pack   /* Struct to hold info when selecting files */
00251 {
00252   uint          wilds;          /* How many wildcards */
00253   uint          not_pos;        /* Start of not-theese-files */
00254   my_string     *wild;          /* Pointer to wildcards */
00255 } WF_PACK;
00256 
00257 enum loglevel {
00258    ERROR_LEVEL,
00259    WARNING_LEVEL,
00260    INFORMATION_LEVEL
00261 };
00262 
00263 enum cache_type
00264 {
00265   READ_CACHE,WRITE_CACHE,
00266   SEQ_READ_APPEND               /* sequential read or append */,
00267   READ_FIFO, READ_NET,WRITE_NET};
00268 
00269 enum flush_type
00270 {
00271   FLUSH_KEEP, FLUSH_RELEASE, FLUSH_IGNORE_CHANGED, FLUSH_FORCE_WRITE
00272 };
00273 
00274 typedef struct st_record_cache  /* Used when cacheing records */
00275 {
00276   File file;
00277   int   rc_seek,error,inited;
00278   uint  rc_length,read_length,reclength;
00279   my_off_t rc_record_pos,end_of_file;
00280   byte  *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos;
00281 #ifdef HAVE_AIOWAIT
00282   int   use_async_io;
00283   my_aio_result aio_result;
00284 #endif
00285   enum cache_type type;
00286 } RECORD_CACHE;
00287 
00288 enum file_type
00289 {
00290   UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN,
00291   FILE_BY_MKSTEMP, FILE_BY_DUP
00292 };
00293 
00294 struct st_my_file_info
00295 {
00296   my_string             name;
00297   enum file_type        type;
00298 #if defined(THREAD) && !defined(HAVE_PREAD)
00299   pthread_mutex_t       mutex;
00300 #endif
00301 };
00302 
00303 extern struct st_my_file_info *my_file_info;
00304 
00305 typedef struct st_my_tmpdir
00306 {
00307   char **list;
00308   uint cur, max;
00309 #ifdef THREAD
00310   pthread_mutex_t mutex;
00311 #endif
00312 } MY_TMPDIR;
00313 
00314 typedef struct st_dynamic_array
00315 {
00316   char *buffer;
00317   uint elements,max_element;
00318   uint alloc_increment;
00319   uint size_of_element;
00320 } DYNAMIC_ARRAY;
00321 
00322 typedef struct st_dynamic_string
00323 {
00324   char *str;
00325   uint length,max_length,alloc_increment;
00326 } DYNAMIC_STRING;
00327 
00328 struct st_io_cache;
00329 typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
00330 
00331 #ifdef THREAD
00332 typedef struct st_io_cache_share
00333 {
00334   /* to sync on reads into buffer */
00335   pthread_mutex_t mutex;
00336   pthread_cond_t  cond;
00337   int             count, total;
00338   /* actual IO_CACHE that filled the buffer */
00339   struct st_io_cache *active;
00340 #ifdef NOT_YET_IMPLEMENTED
00341   /* whether the structure should be free'd */
00342   my_bool alloced;
00343 #endif
00344 } IO_CACHE_SHARE;
00345 #endif
00346 
00347 typedef struct st_io_cache              /* Used when cacheing files */
00348 {
00349   /* Offset in file corresponding to the first byte of byte* buffer. */
00350   my_off_t pos_in_file;
00351   /*
00352     The offset of end of file for READ_CACHE and WRITE_CACHE.
00353     For SEQ_READ_APPEND it the maximum of the actual end of file and
00354     the position represented by read_end.
00355   */
00356   my_off_t end_of_file;
00357   /* Points to current read position in the buffer */
00358   byte  *read_pos;
00359   /* the non-inclusive boundary in the buffer for the currently valid read */
00360   byte  *read_end;
00361   byte  *buffer;                                /* The read buffer */
00362   /* Used in ASYNC_IO */
00363   byte  *request_pos;
00364 
00365   /* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
00366   byte  *write_buffer;
00367   /*
00368     Only used in SEQ_READ_APPEND, and points to the current read position
00369     in the write buffer. Note that reads in SEQ_READ_APPEND caches can
00370     happen from both read buffer (byte* buffer) and write buffer
00371     (byte* write_buffer).
00372   */
00373   byte *append_read_pos;
00374   /* Points to current write position in the write buffer */
00375   byte *write_pos;
00376   /* The non-inclusive boundary of the valid write area */
00377   byte *write_end;
00378 
00379   /*
00380     Current_pos and current_end are convenience variables used by
00381     my_b_tell() and other routines that need to know the current offset
00382     current_pos points to &write_pos, and current_end to &write_end in a
00383     WRITE_CACHE, and &read_pos and &read_end respectively otherwise
00384   */
00385   byte  **current_pos, **current_end;
00386 #ifdef THREAD
00387   /*
00388     The lock is for append buffer used in SEQ_READ_APPEND cache
00389     need mutex copying from append buffer to read buffer.
00390   */
00391   pthread_mutex_t append_buffer_lock;
00392   /*
00393     The following is used when several threads are reading the
00394     same file in parallel. They are synchronized on disk
00395     accesses reading the cached part of the file asynchronously.
00396     It should be set to NULL to disable the feature.  Only
00397     READ_CACHE mode is supported.
00398   */
00399   IO_CACHE_SHARE *share;
00400 #endif
00401   /*
00402     A caller will use my_b_read() macro to read from the cache
00403     if the data is already in cache, it will be simply copied with
00404     memcpy() and internal variables will be accordinging updated with
00405     no functions invoked. However, if the data is not fully in the cache,
00406     my_b_read() will call read_function to fetch the data. read_function
00407     must never be invoked directly.
00408   */
00409   int (*read_function)(struct st_io_cache *,byte *,uint);
00410   /*
00411     Same idea as in the case of read_function, except my_b_write() needs to
00412     be replaced with my_b_append() for a SEQ_READ_APPEND cache
00413   */
00414   int (*write_function)(struct st_io_cache *,const byte *,uint);
00415   /*
00416     Specifies the type of the cache. Depending on the type of the cache
00417     certain operations might not be available and yield unpredicatable
00418     results. Details to be documented later
00419   */
00420   enum cache_type type;
00421   /*
00422     Callbacks when the actual read I/O happens. These were added and
00423     are currently used for binary logging of LOAD DATA INFILE - when a
00424     block is read from the file, we create a block create/append event, and
00425     when IO_CACHE is closed, we create an end event. These functions could,
00426     of course be used for other things
00427   */
00428   IO_CACHE_CALLBACK pre_read;
00429   IO_CACHE_CALLBACK post_read;
00430   IO_CACHE_CALLBACK pre_close;
00431   /*
00432     Counts the number of times, when we were forced to use disk. We use it to
00433     increase the binlog_cache_disk_use status variable.
00434   */
00435   ulong disk_writes;
00436   void* arg;                            /* for use by pre/post_read */
00437   char *file_name;                      /* if used with 'open_cached_file' */
00438   char *dir,*prefix;
00439   File file; /* file descriptor */
00440   /*
00441     seek_not_done is set by my_b_seek() to inform the upcoming read/write
00442     operation that a seek needs to be preformed prior to the actual I/O
00443     error is 0 if the cache operation was successful, -1 if there was a
00444     "hard" error, and the actual number of I/O-ed bytes if the read/write was
00445     partial.
00446   */
00447   int   seek_not_done,error;
00448   /* buffer_length is memory size allocated for buffer or write_buffer */
00449   uint  buffer_length;
00450   /* read_length is the same as buffer_length except when we use async io */
00451   uint  read_length;
00452   myf   myflags;                        /* Flags used to my_read/my_write */
00453   /*
00454     alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
00455     0 if it was supplied by the user.
00456     Currently READ_NET is the only one that will use a buffer allocated
00457     somewhere else
00458   */
00459   my_bool alloced_buffer;
00460 #ifdef HAVE_AIOWAIT
00461   /*
00462     As inidicated by ifdef, this is for async I/O, which is not currently
00463     used (because it's not reliable on all systems)
00464   */
00465   uint inited;
00466   my_off_t aio_read_pos;
00467   my_aio_result aio_result;
00468 #endif
00469 } IO_CACHE;
00470 
00471 typedef int (*qsort2_cmp)(const void *, const void *, const void *);
00472 
00473         /* defines for mf_iocache */
00474 
00475         /* Test if buffer is inited */
00476 #define my_b_clear(info) (info)->buffer=0
00477 #define my_b_inited(info) (info)->buffer
00478 #define my_b_EOF INT_MIN
00479 
00480 #define my_b_read(info,Buffer,Count) \
00481   ((info)->read_pos + (Count) <= (info)->read_end ?\
00482    (memcpy(Buffer,(info)->read_pos,(size_t) (Count)), \
00483     ((info)->read_pos+=(Count)),0) :\
00484    (*(info)->read_function)((info),Buffer,Count))
00485 
00486 #define my_b_write(info,Buffer,Count) \
00487  ((info)->write_pos + (Count) <=(info)->write_end ?\
00488   (memcpy((info)->write_pos, (Buffer), (size_t)(Count)),\
00489    ((info)->write_pos+=(Count)),0) : \
00490    (*(info)->write_function)((info),(Buffer),(Count)))
00491 
00492 #define my_b_get(info) \
00493   ((info)->read_pos != (info)->read_end ?\
00494    ((info)->read_pos++, (int) (uchar) (info)->read_pos[-1]) :\
00495    _my_b_get(info))
00496 
00497         /* my_b_write_byte dosn't have any err-check */
00498 #define my_b_write_byte(info,chr) \
00499   (((info)->write_pos < (info)->write_end) ?\
00500    ((*(info)->write_pos++)=(chr)) :\
00501    (_my_b_write(info,0,0) , ((*(info)->write_pos++)=(chr))))
00502 
00503 #define my_b_fill_cache(info) \
00504   (((info)->read_end=(info)->read_pos),(*(info)->read_function)(info,0,0))
00505 
00506 #define my_b_tell(info) ((info)->pos_in_file + \
00507                          (uint) (*(info)->current_pos - (info)->request_pos))
00508 
00509 /* tell write offset in the SEQ_APPEND cache */
00510 my_off_t my_b_append_tell(IO_CACHE* info);
00511 my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
00512 
00513 #define my_b_bytes_in_cache(info) (uint) (*(info)->current_end - \
00514                                           *(info)->current_pos)
00515 
00516 typedef uint32 ha_checksum;
00517 
00518 /* Define the type of function to be passed to process_default_option_files */
00519 typedef int (*Process_option_func)(void *ctx, const char *group_name,
00520                                     const char *option);
00521 
00522 #include <my_alloc.h>
00523 
00524         /* Prototypes for mysys and my_func functions */
00525 
00526 extern int my_copy(const char *from,const char *to,myf MyFlags);
00527 extern int my_append(const char *from,const char *to,myf MyFlags);
00528 extern int my_delete(const char *name,myf MyFlags);
00529 extern int my_getwd(my_string buf,uint size,myf MyFlags);
00530 extern int my_setwd(const char *dir,myf MyFlags);
00531 extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags);
00532 extern gptr my_once_alloc(uint Size,myf MyFlags);
00533 extern void my_once_free(void);
00534 extern char *my_once_strdup(const char *src,myf myflags);
00535 extern char *my_once_memdup(const char *src, uint len, myf myflags);
00536 extern my_string my_tempnam(const char *dir,const char *pfx,myf MyFlags);
00537 extern File my_open(const char *FileName,int Flags,myf MyFlags);
00538 extern File my_register_filename(File fd, const char *FileName,
00539                                  enum file_type type_of_file,
00540                                  uint error_message_number, myf MyFlags);
00541 extern File my_create(const char *FileName,int CreateFlags,
00542                       int AccsesFlags, myf MyFlags);
00543 extern int my_close(File Filedes,myf MyFlags);
00544 extern File my_dup(File file, myf MyFlags);
00545 extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
00546 extern int my_readlink(char *to, const char *filename, myf MyFlags);
00547 extern int my_realpath(char *to, const char *filename, myf MyFlags);
00548 extern File my_create_with_symlink(const char *linkname, const char *filename,
00549                                    int createflags, int access_flags,
00550                                    myf MyFlags);
00551 extern int my_delete_with_symlink(const char *name, myf MyFlags);
00552 extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags);
00553 extern int my_symlink(const char *content, const char *linkname, myf MyFlags);
00554 extern uint my_read(File Filedes,byte *Buffer,uint Count,myf MyFlags);
00555 extern uint my_pread(File Filedes,byte *Buffer,uint Count,my_off_t offset,
00556                      myf MyFlags);
00557 extern int my_rename(const char *from,const char *to,myf MyFlags);
00558 extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags);
00559 extern my_off_t my_tell(File fd,myf MyFlags);
00560 extern uint my_write(File Filedes,const byte *Buffer,uint Count,
00561                      myf MyFlags);
00562 extern uint my_pwrite(File Filedes,const byte *Buffer,uint Count,
00563                       my_off_t offset,myf MyFlags);
00564 extern uint my_fread(FILE *stream,byte *Buffer,uint Count,myf MyFlags);
00565 extern uint my_fwrite(FILE *stream,const byte *Buffer,uint Count,
00566                       myf MyFlags);
00567 extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags);
00568 extern my_off_t my_ftell(FILE *stream,myf MyFlags);
00569 extern gptr _mymalloc(uint uSize,const char *sFile,
00570                       uint uLine, myf MyFlag);
00571 extern gptr _myrealloc(gptr pPtr,uint uSize,const char *sFile,
00572                        uint uLine, myf MyFlag);
00573 extern gptr my_multi_malloc _VARARGS((myf MyFlags, ...));
00574 extern void _myfree(gptr pPtr,const char *sFile,uint uLine, myf MyFlag);
00575 extern int _sanity(const char *sFile,unsigned int uLine);
00576 extern gptr _my_memdup(const byte *from,uint length,
00577                        const char *sFile, uint uLine,myf MyFlag);
00578 extern my_string _my_strdup(const char *from, const char *sFile, uint uLine,
00579                             myf MyFlag);
00580 extern char *_my_strdup_with_length(const byte *from, uint length,
00581                                     const char *sFile, uint uLine,
00582                                     myf MyFlag);
00583 
00584 
00585 #ifndef TERMINATE
00586 extern void TERMINATE(FILE *file);
00587 #endif
00588 extern void init_glob_errs(void);
00589 extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
00590 extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
00591 extern int my_fclose(FILE *fd,myf MyFlags);
00592 extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
00593 extern int my_sync(File fd, myf my_flags);
00594 extern int my_error _VARARGS((int nr,myf MyFlags, ...));
00595 extern int my_printf_error _VARARGS((uint my_err, const char *format,
00596                                      myf MyFlags, ...)
00597                                     __attribute__ ((format (printf, 2, 4))));
00598 extern int my_message(uint my_err, const char *str,myf MyFlags);
00599 extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags);
00600 extern int my_message_curses(uint my_err, const char *str,myf MyFlags);
00601 extern my_bool my_init(void);
00602 extern void my_end(int infoflag);
00603 extern int my_redel(const char *from, const char *to, int MyFlags);
00604 extern int my_copystat(const char *from, const char *to, int MyFlags);
00605 extern my_string my_filename(File fd);
00606 
00607 #ifndef THREAD
00608 extern void dont_break(void);
00609 extern void allow_break(void);
00610 #else
00611 #define dont_break()
00612 #define allow_break()
00613 #endif
00614 
00615 extern my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist);
00616 extern char *my_tmpdir(MY_TMPDIR *tmpdir);
00617 extern void free_tmpdir(MY_TMPDIR *tmpdir);
00618 
00619 extern void my_remember_signal(int signal_number,sig_handler (*func)(int));
00620 extern uint dirname_part(my_string to,const char *name);
00621 extern uint dirname_length(const char *name);
00622 #define base_name(A) (A+dirname_length(A))
00623 extern int test_if_hard_path(const char *dir_name);
00624 extern char *convert_dirname(char *to, const char *from, const char *from_end);
00625 extern void to_unix_path(my_string name);
00626 extern my_string fn_ext(const char *name);
00627 extern my_string fn_same(my_string toname,const char *name,int flag);
00628 extern my_string fn_format(my_string to,const char *name,const char *dir,
00629                            const char *form, uint flag);
00630 extern size_s strlength(const char *str);
00631 extern void pack_dirname(my_string to,const char *from);
00632 extern uint unpack_dirname(my_string to,const char *from);
00633 extern uint cleanup_dirname(my_string to,const char *from);
00634 extern uint system_filename(my_string to,const char *from);
00635 extern uint unpack_filename(my_string to,const char *from);
00636 extern my_string intern_filename(my_string to,const char *from);
00637 extern my_string directory_file_name(my_string dst, const char *src);
00638 extern int pack_filename(my_string to, const char *name, size_s max_length);
00639 extern my_string my_path(my_string to,const char *progname,
00640                          const char *own_pathname_part);
00641 extern my_string my_load_path(my_string to, const char *path,
00642                               const char *own_path_prefix);
00643 extern int wild_compare(const char *str,const char *wildstr,pbool str_is_pattern);
00644 extern WF_PACK *wf_comp(my_string str);
00645 extern int wf_test(struct wild_file_pack *wf_pack,const char *name);
00646 extern void wf_end(struct wild_file_pack *buffer);
00647 extern size_s strip_sp(my_string str);
00648 extern void get_date(my_string to,int timeflag,time_t use_time);
00649 extern void soundex(CHARSET_INFO *, my_string out_pntr, my_string in_pntr,pbool remove_garbage);
00650 extern int init_record_cache(RECORD_CACHE *info,uint cachesize,File file,
00651                              uint reclength,enum cache_type type,
00652                              pbool use_async_io);
00653 extern int read_cache_record(RECORD_CACHE *info,byte *to);
00654 extern int end_record_cache(RECORD_CACHE *info);
00655 extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos,
00656                               const byte *record,uint length);
00657 extern int flush_write_cache(RECORD_CACHE *info);
00658 extern long my_clock(void);
00659 extern sig_handler sigtstp_handler(int signal_number);
00660 extern void handle_recived_signals(void);
00661 
00662 extern sig_handler my_set_alarm_variable(int signo);
00663 extern void my_string_ptr_sort(void *base,uint items,size_s size);
00664 extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
00665                                   size_s size_of_element,uchar *buffer[]);
00666 extern qsort_t qsort2(void *base_ptr, size_t total_elems, size_t size,
00667                       qsort2_cmp cmp, void *cmp_argument);
00668 extern qsort2_cmp get_ptr_compare(uint);
00669 void my_store_ptr(byte *buff, uint pack_length, my_off_t pos);
00670 my_off_t my_get_ptr(byte *ptr, uint pack_length);
00671 extern int init_io_cache(IO_CACHE *info,File file,uint cachesize,
00672                          enum cache_type type,my_off_t seek_offset,
00673                          pbool use_async_io, myf cache_myflags);
00674 extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
00675                                my_off_t seek_offset,pbool use_async_io,
00676                                pbool clear_cache);
00677 extern int _my_b_read(IO_CACHE *info,byte *Buffer,uint Count);
00678 #ifdef THREAD
00679 extern int _my_b_read_r(IO_CACHE *info,byte *Buffer,uint Count);
00680 extern void init_io_cache_share(IO_CACHE *info,
00681                                 IO_CACHE_SHARE *s, uint num_threads);
00682 extern void remove_io_thread(IO_CACHE *info);
00683 #endif
00684 extern int _my_b_seq_read(IO_CACHE *info,byte *Buffer,uint Count);
00685 extern int _my_b_net_read(IO_CACHE *info,byte *Buffer,uint Count);
00686 extern int _my_b_get(IO_CACHE *info);
00687 extern int _my_b_async_read(IO_CACHE *info,byte *Buffer,uint Count);
00688 extern int _my_b_write(IO_CACHE *info,const byte *Buffer,uint Count);
00689 extern int my_b_append(IO_CACHE *info,const byte *Buffer,uint Count);
00690 extern int my_b_safe_write(IO_CACHE *info,const byte *Buffer,uint Count);
00691 
00692 extern int my_block_write(IO_CACHE *info, const byte *Buffer,
00693                           uint Count, my_off_t pos);
00694 extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
00695 
00696 #define flush_io_cache(info) my_b_flush_io_cache((info),1)
00697 
00698 extern int end_io_cache(IO_CACHE *info);
00699 extern uint my_b_fill(IO_CACHE *info);
00700 extern void my_b_seek(IO_CACHE *info,my_off_t pos);
00701 extern uint my_b_gets(IO_CACHE *info, char *to, uint max_length);
00702 extern my_off_t my_b_filelength(IO_CACHE *info);
00703 extern uint my_b_printf(IO_CACHE *info, const char* fmt, ...);
00704 extern uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
00705 extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
00706                                  const char *prefix, uint cache_size,
00707                                  myf cache_myflags);
00708 extern my_bool real_open_cached_file(IO_CACHE *cache);
00709 extern void close_cached_file(IO_CACHE *cache);
00710 File create_temp_file(char *to, const char *dir, const char *pfx,
00711                       int mode, myf MyFlags);
00712 #define my_init_dynamic_array(A,B,C,D) init_dynamic_array(A,B,C,D CALLER_INFO)
00713 #define my_init_dynamic_array_ci(A,B,C,D) init_dynamic_array(A,B,C,D ORIG_CALLER_INFO)
00714 extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size,
00715                                   uint init_alloc,uint alloc_increment
00716                                   CALLER_INFO_PROTO);
00717 extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,gptr element);
00718 extern byte *alloc_dynamic(DYNAMIC_ARRAY *array);
00719 extern byte *pop_dynamic(DYNAMIC_ARRAY*);
00720 extern my_bool set_dynamic(DYNAMIC_ARRAY *array,gptr element,uint array_index);
00721 extern void get_dynamic(DYNAMIC_ARRAY *array,gptr element,uint array_index);
00722 extern void delete_dynamic(DYNAMIC_ARRAY *array);
00723 extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index);
00724 extern void freeze_size(DYNAMIC_ARRAY *array);
00725 #define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element)
00726 #define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index))
00727 #define push_dynamic(A,B) insert_dynamic(A,B)
00728 #define reset_dynamic(array) ((array)->elements= 0)
00729 
00730 extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
00731                                    uint init_alloc,uint alloc_increment);
00732 extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append);
00733 my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
00734                           uint length);
00735 extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str);
00736 extern my_bool dynstr_realloc(DYNAMIC_STRING *str, ulong additional_size);
00737 extern void dynstr_free(DYNAMIC_STRING *str);
00738 #ifdef HAVE_MLOCK
00739 extern byte *my_malloc_lock(uint length,myf flags);
00740 extern void my_free_lock(byte *ptr,myf flags);
00741 #else
00742 #define my_malloc_lock(A,B) my_malloc((A),(B))
00743 #define my_free_lock(A,B) my_free((A),(B))
00744 #endif
00745 #define alloc_root_inited(A) ((A)->min_malloc != 0)
00746 #define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
00747 #define clear_alloc_root(A) do { (A)->free= (A)->used= (A)->pre_alloc= 0; (A)->min_malloc=0;} while(0)
00748 extern void init_alloc_root(MEM_ROOT *mem_root, uint block_size,
00749                             uint pre_alloc_size);
00750 extern gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size);
00751 extern void free_root(MEM_ROOT *root, myf MyFLAGS);
00752 extern void set_prealloc_root(MEM_ROOT *root, char *ptr);
00753 extern void reset_root_defaults(MEM_ROOT *mem_root, uint block_size,
00754                                 uint prealloc_size);
00755 extern char *strdup_root(MEM_ROOT *root,const char *str);
00756 extern char *strmake_root(MEM_ROOT *root,const char *str,uint len);
00757 extern char *memdup_root(MEM_ROOT *root,const char *str,uint len);
00758 extern int load_defaults(const char *conf_file, const char **groups,
00759                          int *argc, char ***argv);
00760 extern int process_default_option_files(const char *conf_file,
00761                                         Process_option_func func,
00762                                         void *func_ctx);
00763 extern void free_defaults(char **argv);
00764 extern void print_defaults(const char *conf_file, const char **groups);
00765 extern my_bool my_compress(byte *, ulong *, ulong *);
00766 extern my_bool my_uncompress(byte *, ulong *, ulong *);
00767 extern byte *my_compress_alloc(const byte *packet, ulong *len, ulong *complen);
00768 extern ha_checksum my_checksum(ha_checksum crc, const byte *mem, uint count);
00769 extern uint my_bit_log2(ulong value);
00770 extern uint my_count_bits(ulonglong v);
00771 extern uint my_count_bits_ushort(ushort v);
00772 extern void my_sleep(ulong m_seconds);
00773 extern ulong crc32(ulong crc, const uchar *buf, uint len);
00774 extern uint my_set_max_open_files(uint files);
00775 void my_free_open_file_info(void);
00776 
00777 ulonglong my_getsystime(void);
00778 my_bool my_gethwaddr(uchar *to);
00779 
00780 #ifdef HAVE_MMAP
00781 #include <sys/mman.h>
00782 
00783 #ifndef MAP_NOSYNC
00784 #define MAP_NOSYNC      0
00785 #endif
00786 
00787 #define my_mmap(a,b,c,d,e,f)    mmap(a,b,c,d,e,f)
00788 #define my_getpagesize()        getpagesize()
00789 #define my_munmap(a,b)          munmap(a,b)
00790 
00791 #else
00792 /* not a complete set of mmap() flags, but only those that nesessary */
00793 #define PROT_READ        1
00794 #define PROT_WRITE       2
00795 #define MAP_NOSYNC       0x800
00796 #define MAP_FAILED       ((void *)-1)
00797 #define MS_SYNC          0x0000
00798 
00799 int my_getpagesize(void);
00800 void *my_mmap(void *, size_t, int, int, int, my_off_t);
00801 int my_munmap(void *, size_t);
00802 #endif
00803 
00804 int my_msync(int, void *, size_t, int);
00805 
00806 /* character sets */
00807 extern uint get_charset_number(const char *cs_name, uint cs_flags);
00808 extern uint get_collation_number(const char *name);
00809 extern const char *get_charset_name(uint cs_number);
00810 
00811 extern CHARSET_INFO *get_charset(uint cs_number, myf flags);
00812 extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags);
00813 extern CHARSET_INFO *get_charset_by_csname(const char *cs_name,
00814                                            uint cs_flags, myf my_flags);
00815 extern void free_charsets(void);
00816 extern char *get_charsets_dir(char *buf);
00817 extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2);
00818 extern my_bool init_compiled_charsets(myf flags);
00819 extern void add_compiled_collation(CHARSET_INFO *cs);
00820 extern ulong escape_string_for_mysql(CHARSET_INFO *charset_info, char *to,
00821                                      const char *from, ulong length);
00822 
00823 extern void thd_increment_bytes_sent(ulong length);
00824 extern void thd_increment_bytes_received(ulong length);
00825 extern void thd_increment_net_big_packet_count(ulong length);
00826 
00827 #ifdef __WIN__
00828 extern my_bool have_tcpip;              /* Is set if tcpip is used */
00829 #endif
00830 #ifdef __NETWARE__
00831 void netware_reg_user(const char *ip, const char *user,
00832                       const char *application);
00833 #endif
00834 
00835 C_MODE_END
00836 #include "raid.h"
00837 #endif /* _my_sys_h */

Generated on Thu Feb 24 10:22:05 2005 for MySQL by  doxygen 1.3.9.1