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