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

