| 1 | /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
|---|
| 2 |
|
|---|
| 3 | This library is free software; you can redistribute it and/or
|
|---|
| 4 | modify it under the terms of the GNU Library General Public
|
|---|
| 5 | License as published by the Free Software Foundation; either
|
|---|
| 6 | version 2 of the License, or (at your option) any later version.
|
|---|
| 7 |
|
|---|
| 8 | This library is distributed in the hope that it will be useful,
|
|---|
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 11 | Library General Public License for more details.
|
|---|
| 12 |
|
|---|
| 13 | You should have received a copy of the GNU Library General Public
|
|---|
| 14 | License along with this library; if not, write to the Free
|
|---|
| 15 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
|---|
| 16 | MA 02111-1307, USA */
|
|---|
| 17 |
|
|---|
| 18 | #ifndef _my_sys_h
|
|---|
| 19 | #define _my_sys_h
|
|---|
| 20 | #ifdef __cplusplus
|
|---|
| 21 | extern "C" {
|
|---|
| 22 | #endif
|
|---|
| 23 |
|
|---|
| 24 | #ifdef HAVE_AIOWAIT
|
|---|
| 25 | #include <sys/asynch.h> /* Used by record-cache */
|
|---|
| 26 | typedef struct my_aio_result {
|
|---|
| 27 | aio_result_t result;
|
|---|
| 28 | int pending;
|
|---|
| 29 | } my_aio_result;
|
|---|
| 30 | #endif
|
|---|
| 31 |
|
|---|
| 32 | #ifndef THREAD
|
|---|
| 33 | extern int NEAR my_errno; /* Last error in mysys */
|
|---|
| 34 | #else
|
|---|
| 35 | #include <my_pthread.h>
|
|---|
| 36 | #endif
|
|---|
| 37 |
|
|---|
| 38 | #ifndef _m_ctype_h
|
|---|
| 39 | #include <m_ctype.h> /* for CHARSET_INFO */
|
|---|
| 40 | #endif
|
|---|
| 41 |
|
|---|
| 42 | #include <stdarg.h>
|
|---|
| 43 |
|
|---|
| 44 | #define MYSYS_PROGRAM_USES_CURSES() { error_handler_hook = my_message_curses; mysys_uses_curses=1; }
|
|---|
| 45 | #define MYSYS_PROGRAM_DONT_USE_CURSES() { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
|
|---|
| 46 | #define MY_INIT(name); { my_progname= name; my_init(); }
|
|---|
| 47 |
|
|---|
| 48 | #define MAXMAPS (4) /* Number of error message maps */
|
|---|
| 49 | #define ERRMOD (1000) /* Max number of errors in a map */
|
|---|
| 50 | #define ERRMSGSIZE (SC_MAXWIDTH) /* Max length of a error message */
|
|---|
| 51 | #define NRERRBUFFS (2) /* Buffers for parameters */
|
|---|
| 52 | #define MY_FILE_ERROR ((uint) ~0)
|
|---|
| 53 |
|
|---|
| 54 | /* General bitmaps for my_func's */
|
|---|
| 55 | #define MY_FFNF 1 /* Fatal if file not found */
|
|---|
| 56 | #define MY_FNABP 2 /* Fatal if not all bytes read/writen */
|
|---|
| 57 | #define MY_NABP 4 /* Error if not all bytes read/writen */
|
|---|
| 58 | #define MY_FAE 8 /* Fatal if any error */
|
|---|
| 59 | #define MY_WME 16 /* Write message on error */
|
|---|
| 60 | #define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */
|
|---|
| 61 | #define MY_RAID 64 /* Support for RAID (not the "Johnson&Johnson"-s one ;) */
|
|---|
| 62 | #define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
|
|---|
| 63 | #define MY_LINK_WARNING 32 /* my_redel() gives warning if links */
|
|---|
| 64 | #define MY_COPYTIME 64 /* my_redel() copys time */
|
|---|
| 65 | #define MY_DELETE_OLD 256 /* my_create_with_symlink() */
|
|---|
| 66 | #define MY_RESOLVE_LINK 128 /* my_realpath(); Only resolve links */
|
|---|
| 67 | #define MY_HOLD_ORIGINAL_MODES 128 /* my_copy() holds to file modes */
|
|---|
| 68 | #define MY_REDEL_MAKE_BACKUP 256
|
|---|
| 69 | #define MY_SEEK_NOT_DONE 32 /* my_lock may have to do a seek */
|
|---|
| 70 | #define MY_DONT_WAIT 64 /* my_lock() don't wait if can't lock */
|
|---|
| 71 | #define MY_ZEROFILL 32 /* my_malloc(), fill array with zero */
|
|---|
| 72 | #define MY_ALLOW_ZERO_PTR 64 /* my_realloc() ; zero ptr -> malloc */
|
|---|
| 73 | #define MY_FREE_ON_ERROR 128 /* my_realloc() ; Free old ptr on error */
|
|---|
| 74 | #define MY_HOLD_ON_ERROR 256 /* my_realloc() ; Return old ptr on error */
|
|---|
| 75 | #define MY_THREADSAFE 128 /* pread/pwrite: Don't allow interrupts */
|
|---|
| 76 |
|
|---|
| 77 | #define MY_CHECK_ERROR 1 /* Params to my_end; Check open-close */
|
|---|
| 78 | #define MY_GIVE_INFO 2 /* Give time info about process*/
|
|---|
| 79 |
|
|---|
| 80 | #define ME_HIGHBYTE 8 /* Shift for colours */
|
|---|
| 81 | #define ME_NOCUR 1 /* Don't use curses message */
|
|---|
| 82 | #define ME_OLDWIN 2 /* Use old window */
|
|---|
| 83 | #define ME_BELL 4 /* Ring bell then printing message */
|
|---|
| 84 | #define ME_HOLDTANG 8 /* Don't delete last keys */
|
|---|
| 85 | #define ME_WAITTOT 16 /* Wait for errtime secs of for a action */
|
|---|
| 86 | #define ME_WAITTANG 32 /* Wait for a user action */
|
|---|
| 87 | #define ME_NOREFRESH 64 /* Dont refresh screen */
|
|---|
| 88 | #define ME_NOINPUT 128 /* Dont use the input libary */
|
|---|
| 89 | #define ME_COLOUR1 ((1 << ME_HIGHBYTE)) /* Possibly error-colours */
|
|---|
| 90 | #define ME_COLOUR2 ((2 << ME_HIGHBYTE))
|
|---|
| 91 | #define ME_COLOUR3 ((3 << ME_HIGHBYTE))
|
|---|
| 92 |
|
|---|
| 93 | /* My seek flags */
|
|---|
| 94 | #define MY_SEEK_SET 0
|
|---|
| 95 | #define MY_SEEK_CUR 1
|
|---|
| 96 | #define MY_SEEK_END 2
|
|---|
| 97 |
|
|---|
| 98 | /* My charsets_list flags */
|
|---|
| 99 | #define MY_NO_SETS 0
|
|---|
| 100 | #define MY_COMPILED_SETS 1 /* show compiled-in sets */
|
|---|
| 101 | #define MY_CONFIG_SETS 2 /* sets that have a *.conf file */
|
|---|
| 102 | #define MY_INDEX_SETS 4 /* all sets listed in the Index file */
|
|---|
| 103 | #define MY_LOADED_SETS 8 /* the sets that are currently loaded */
|
|---|
| 104 |
|
|---|
| 105 | /* Some constants */
|
|---|
| 106 | #define MY_WAIT_FOR_USER_TO_FIX_PANIC 60 /* in seconds */
|
|---|
| 107 | #define MY_WAIT_GIVE_USER_A_MESSAGE 10 /* Every 10 times of prev */
|
|---|
| 108 | #define MIN_COMPRESS_LENGTH 50 /* Don't compress small bl. */
|
|---|
| 109 | #define KEYCACHE_BLOCK_SIZE 1024
|
|---|
| 110 |
|
|---|
| 111 | /* root_alloc flags */
|
|---|
| 112 | #define MY_KEEP_PREALLOC 1
|
|---|
| 113 |
|
|---|
| 114 | /* defines when allocating data */
|
|---|
| 115 |
|
|---|
| 116 | #ifdef SAFEMALLOC
|
|---|
| 117 | #define my_malloc(SZ,FLAG) _mymalloc( SZ, __FILE__, __LINE__, FLAG )
|
|---|
| 118 | #define my_realloc(PTR,SZ,FLAG) _myrealloc( PTR, SZ, __FILE__, __LINE__, FLAG )
|
|---|
| 119 | #define my_checkmalloc() _sanity( __FILE__, __LINE__ )
|
|---|
| 120 | #define my_free(PTR,FLAG) _myfree( PTR, __FILE__, __LINE__,FLAG)
|
|---|
| 121 | #define my_memdup(A,B,C) _my_memdup(A,B,__FILE__,__LINE__,C)
|
|---|
| 122 | #define my_strdup(A,C) _my_strdup(A,__FILE__,__LINE__,C)
|
|---|
| 123 | #define QUICK_SAFEMALLOC sf_malloc_quick=1
|
|---|
| 124 | #define NORMAL_SAFEMALLOC sf_malloc_quick=0
|
|---|
| 125 | extern uint sf_malloc_prehunc,sf_malloc_endhunc,sf_malloc_quick;
|
|---|
| 126 | extern ulonglong safemalloc_mem_limit;
|
|---|
| 127 | #else
|
|---|
| 128 | #define my_checkmalloc() (0)
|
|---|
| 129 | #ifndef OS2
|
|---|
| 130 | #define TERMINATE(A) {}
|
|---|
| 131 | #endif
|
|---|
| 132 | #define QUICK_SAFEMALLOC
|
|---|
| 133 | #define NORMAL_SAFEMALLOC
|
|---|
| 134 | extern gptr my_malloc(uint Size,myf MyFlags);
|
|---|
| 135 | extern gptr my_realloc(gptr oldpoint,uint Size,myf MyFlags);
|
|---|
| 136 | extern void my_no_flags_free(gptr ptr);
|
|---|
| 137 | extern gptr my_memdup(const byte *from,uint length,myf MyFlags);
|
|---|
| 138 | extern my_string my_strdup(const char *from,myf MyFlags);
|
|---|
| 139 | #define my_free(PTR,FG) my_no_flags_free(PTR)
|
|---|
| 140 | #endif
|
|---|
| 141 | #ifdef HAVE_ALLOCA
|
|---|
| 142 | #define my_alloca(SZ) alloca((size_t) (SZ))
|
|---|
| 143 | #define my_afree(PTR) {}
|
|---|
| 144 | #else
|
|---|
| 145 | #define my_alloca(SZ) my_malloc(SZ,MYF(0))
|
|---|
| 146 | #define my_afree(PTR) my_free(PTR,MYF(MY_WME))
|
|---|
| 147 | #endif /* HAVE_ALLOCA */
|
|---|
| 148 | #ifdef MSDOS
|
|---|
| 149 | #ifdef __ZTC__
|
|---|
| 150 | void * __CDECL halloc(long count,size_t length);
|
|---|
| 151 | void __CDECL hfree(void *ptr);
|
|---|
| 152 | #endif
|
|---|
| 153 | #if defined(USE_HALLOC)
|
|---|
| 154 | #if defined(_VCM_) || defined(M_IC80386)
|
|---|
| 155 | #undef USE_HALLOC
|
|---|
| 156 | #endif
|
|---|
| 157 | #endif
|
|---|
| 158 | #ifdef USE_HALLOC
|
|---|
| 159 | #define malloc(a) halloc((long) (a),1)
|
|---|
| 160 | #define free(a) hfree(a)
|
|---|
| 161 | #endif
|
|---|
| 162 | #endif /* MSDOS */
|
|---|
| 163 |
|
|---|
| 164 | #ifdef HAVE_ERRNO_AS_DEFINE
|
|---|
| 165 | #include <errno.h> /* errno is a define */
|
|---|
| 166 | #else
|
|---|
| 167 | extern int errno; /* declare errno */
|
|---|
| 168 | #endif
|
|---|
| 169 | extern const char ** NEAR my_errmsg[];
|
|---|
| 170 | extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
|
|---|
| 171 | extern char *home_dir; /* Home directory for user */
|
|---|
| 172 | extern char *my_progname; /* program-name (printed in errors) */
|
|---|
| 173 | extern char NEAR curr_dir[]; /* Current directory for user */
|
|---|
| 174 | extern int (*error_handler_hook)(uint my_err, const char *str,myf MyFlags);
|
|---|
| 175 | extern int (*fatal_error_handler_hook)(uint my_err, const char *str,
|
|---|
| 176 | myf MyFlags);
|
|---|
| 177 |
|
|---|
| 178 | /* charsets */
|
|---|
| 179 | extern uint get_charset_number(const char *cs_name);
|
|---|
| 180 | extern const char *get_charset_name(uint cs_number);
|
|---|
| 181 | extern CHARSET_INFO *get_charset(uint cs_number, myf flags);
|
|---|
| 182 | extern my_bool set_default_charset(uint cs, myf flags);
|
|---|
| 183 | extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags);
|
|---|
| 184 | extern my_bool set_default_charset_by_name(const char *cs_name, myf flags);
|
|---|
| 185 | extern void free_charsets(void);
|
|---|
| 186 | extern char *list_charsets(myf want_flags); /* my_free() this string... */
|
|---|
| 187 | extern char *get_charsets_dir(char *buf);
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 | /* statistics */
|
|---|
| 191 | extern ulong _my_cache_w_requests,_my_cache_write,_my_cache_r_requests,
|
|---|
| 192 | _my_cache_read;
|
|---|
| 193 | extern ulong _my_blocks_used,_my_blocks_changed;
|
|---|
| 194 | extern ulong my_file_opened,my_stream_opened, my_tmp_file_created;
|
|---|
| 195 | extern my_bool key_cache_inited;
|
|---|
| 196 |
|
|---|
| 197 | /* Point to current my_message() */
|
|---|
| 198 | extern void (*my_sigtstp_cleanup)(void),
|
|---|
| 199 | /* Executed before jump to shell */
|
|---|
| 200 | (*my_sigtstp_restart)(void),
|
|---|
| 201 | (*my_abort_hook)(int);
|
|---|
| 202 | /* Executed when comming from shell */
|
|---|
| 203 | extern int NEAR my_umask, /* Default creation mask */
|
|---|
| 204 | NEAR my_umask_dir,
|
|---|
| 205 | NEAR my_recived_signals, /* Signals we have got */
|
|---|
| 206 | NEAR my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */
|
|---|
| 207 | NEAR my_dont_interrupt; /* call remember_intr when set */
|
|---|
| 208 | extern my_bool NEAR mysys_uses_curses, my_use_symdir;
|
|---|
| 209 | extern long lCurMemory,lMaxMemory; /* from safemalloc */
|
|---|
| 210 |
|
|---|
| 211 | extern ulong my_default_record_cache_size;
|
|---|
| 212 | extern my_bool NEAR my_disable_locking,NEAR my_disable_async_io,
|
|---|
| 213 | NEAR my_disable_flush_key_blocks, NEAR my_disable_symlinks;
|
|---|
| 214 | extern char wild_many,wild_one,wild_prefix;
|
|---|
| 215 | extern const char *charsets_dir;
|
|---|
| 216 | extern char *defaults_extra_file;
|
|---|
| 217 |
|
|---|
| 218 | typedef struct wild_file_pack /* Struct to hold info when selecting files */
|
|---|
| 219 | {
|
|---|
| 220 | uint wilds; /* How many wildcards */
|
|---|
| 221 | uint not_pos; /* Start of not-theese-files */
|
|---|
| 222 | my_string *wild; /* Pointer to wildcards */
|
|---|
| 223 | } WF_PACK;
|
|---|
| 224 |
|
|---|
| 225 | typedef struct st_typelib { /* Different types saved here */
|
|---|
| 226 | uint count; /* How many types */
|
|---|
| 227 | const char *name; /* Name of typelib */
|
|---|
| 228 | const char **type_names;
|
|---|
| 229 | } TYPELIB;
|
|---|
| 230 |
|
|---|
| 231 | enum cache_type {READ_CACHE,WRITE_CACHE,READ_FIFO,READ_NET,WRITE_NET};
|
|---|
| 232 | enum flush_type { FLUSH_KEEP, FLUSH_RELEASE, FLUSH_IGNORE_CHANGED,
|
|---|
| 233 | FLUSH_FORCE_WRITE};
|
|---|
| 234 |
|
|---|
| 235 | typedef struct st_record_cache /* Used when cacheing records */
|
|---|
| 236 | {
|
|---|
| 237 | File file;
|
|---|
| 238 | int rc_seek,error,inited;
|
|---|
| 239 | uint rc_length,read_length,reclength;
|
|---|
| 240 | my_off_t rc_record_pos,end_of_file;
|
|---|
| 241 | byte *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos;
|
|---|
| 242 | #ifdef HAVE_AIOWAIT
|
|---|
| 243 | int use_async_io;
|
|---|
| 244 | my_aio_result aio_result;
|
|---|
| 245 | #endif
|
|---|
| 246 | enum cache_type type;
|
|---|
| 247 | } RECORD_CACHE;
|
|---|
| 248 |
|
|---|
| 249 | enum file_type { UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE,
|
|---|
| 250 | STREAM_BY_FOPEN, STREAM_BY_FDOPEN, FILE_BY_MKSTEMP };
|
|---|
| 251 |
|
|---|
| 252 | extern struct my_file_info
|
|---|
| 253 | {
|
|---|
| 254 | my_string name;
|
|---|
| 255 | enum file_type type;
|
|---|
| 256 | #if defined(THREAD) && !defined(HAVE_PREAD)
|
|---|
| 257 | pthread_mutex_t mutex;
|
|---|
| 258 | #endif
|
|---|
| 259 | } my_file_info[MY_NFILE];
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 | typedef struct st_dynamic_array {
|
|---|
| 263 | char *buffer;
|
|---|
| 264 | uint elements,max_element;
|
|---|
| 265 | uint alloc_increment;
|
|---|
| 266 | uint size_of_element;
|
|---|
| 267 | } DYNAMIC_ARRAY;
|
|---|
| 268 |
|
|---|
| 269 | typedef struct st_dynamic_string {
|
|---|
| 270 | char *str;
|
|---|
| 271 | uint length,max_length,alloc_increment;
|
|---|
| 272 | } DYNAMIC_STRING;
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 | typedef struct st_io_cache /* Used when cacheing files */
|
|---|
| 276 | {
|
|---|
| 277 | my_off_t pos_in_file,end_of_file;
|
|---|
| 278 | byte *rc_pos,*rc_end,*buffer,*rc_request_pos;
|
|---|
| 279 | int (*read_function)(struct st_io_cache *,byte *,uint);
|
|---|
| 280 | char *file_name; /* if used with 'open_cached_file' */
|
|---|
| 281 | char *dir,*prefix;
|
|---|
| 282 | File file;
|
|---|
| 283 | int seek_not_done,error;
|
|---|
| 284 | uint buffer_length,read_length;
|
|---|
| 285 | myf myflags; /* Flags used to my_read/my_write */
|
|---|
| 286 | enum cache_type type;
|
|---|
| 287 | #ifdef HAVE_AIOWAIT
|
|---|
| 288 | uint inited;
|
|---|
| 289 | my_off_t aio_read_pos;
|
|---|
| 290 | my_aio_result aio_result;
|
|---|
| 291 | #endif
|
|---|
| 292 | } IO_CACHE;
|
|---|
| 293 |
|
|---|
| 294 | typedef int (*qsort2_cmp)(const void *, const void *, const void *);
|
|---|
| 295 |
|
|---|
| 296 | /* defines for mf_iocache */
|
|---|
| 297 |
|
|---|
| 298 | /* Test if buffer is inited */
|
|---|
| 299 | #define my_b_clear(info) (info)->buffer=0
|
|---|
| 300 | #define my_b_inited(info) (info)->buffer
|
|---|
| 301 | #define my_b_EOF INT_MIN
|
|---|
| 302 |
|
|---|
| 303 | #define my_b_read(info,Buffer,Count) \
|
|---|
| 304 | ((info)->rc_pos + (Count) <= (info)->rc_end ?\
|
|---|
| 305 | (memcpy(Buffer,(info)->rc_pos,(size_t) (Count)), \
|
|---|
| 306 | ((info)->rc_pos+=(Count)),0) :\
|
|---|
| 307 | (*(info)->read_function)((info),Buffer,Count))
|
|---|
| 308 |
|
|---|
| 309 | #define my_b_get(info) \
|
|---|
| 310 | ((info)->rc_pos != (info)->rc_end ?\
|
|---|
| 311 | ((info)->rc_pos++, (int) (uchar) (info)->rc_pos[-1]) :\
|
|---|
| 312 | _my_b_get(info))
|
|---|
| 313 |
|
|---|
| 314 | #define my_b_write(info,Buffer,Count) \
|
|---|
| 315 | ((info)->rc_pos + (Count) <= (info)->rc_end ?\
|
|---|
| 316 | (memcpy((info)->rc_pos,Buffer,(size_t) (Count)), \
|
|---|
| 317 | ((info)->rc_pos+=(Count)),0) :\
|
|---|
| 318 | _my_b_write(info,Buffer,Count))
|
|---|
| 319 |
|
|---|
| 320 | /* my_b_write_byte dosn't have any err-check */
|
|---|
| 321 | #define my_b_write_byte(info,chr) \
|
|---|
| 322 | (((info)->rc_pos < (info)->rc_end) ?\
|
|---|
| 323 | ((*(info)->rc_pos++)=(chr)) :\
|
|---|
| 324 | (_my_b_write(info,0,0) , ((*(info)->rc_pos++)=(chr))))
|
|---|
| 325 |
|
|---|
| 326 | #define my_b_fill_cache(info) \
|
|---|
| 327 | (((info)->rc_end=(info)->rc_pos),(*(info)->read_function)(info,0,0))
|
|---|
| 328 |
|
|---|
| 329 | #define my_b_tell(info) ((info)->pos_in_file + \
|
|---|
| 330 | ((info)->rc_pos - (info)->rc_request_pos))
|
|---|
| 331 |
|
|---|
| 332 | #define my_b_bytes_in_cache(info) ((uint) ((info)->rc_end - (info)->rc_pos))
|
|---|
| 333 |
|
|---|
| 334 | typedef struct st_changeable_var {
|
|---|
| 335 | const char *name; /* Name of variable */
|
|---|
| 336 | long *varptr; /* Pointer to variable */
|
|---|
| 337 | long def_value, /* Default value */
|
|---|
| 338 | min_value, /* Min allowed value */
|
|---|
| 339 | max_value, /* Max allowed value */
|
|---|
| 340 | sub_size, /* Subtract this from given value */
|
|---|
| 341 | block_size; /* Value should be a mult. of this */
|
|---|
| 342 | } CHANGEABLE_VAR;
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 | /* structs for alloc_root */
|
|---|
| 346 |
|
|---|
| 347 | #ifndef ST_USED_MEM_DEFINED
|
|---|
| 348 | #define ST_USED_MEM_DEFINED
|
|---|
| 349 | typedef struct st_used_mem { /* struct for once_alloc */
|
|---|
| 350 | struct st_used_mem *next; /* Next block in use */
|
|---|
| 351 | unsigned int left; /* memory left in block */
|
|---|
| 352 | unsigned int size; /* Size of block */
|
|---|
| 353 | } USED_MEM;
|
|---|
| 354 |
|
|---|
| 355 | typedef struct st_mem_root {
|
|---|
| 356 | USED_MEM *free;
|
|---|
| 357 | USED_MEM *used;
|
|---|
| 358 | USED_MEM *pre_alloc;
|
|---|
| 359 | unsigned int min_malloc;
|
|---|
| 360 | unsigned int block_size;
|
|---|
| 361 |
|
|---|
| 362 | void (*error_handler)(void);
|
|---|
| 363 | } MEM_ROOT;
|
|---|
| 364 | #endif
|
|---|
| 365 |
|
|---|
| 366 | /* Prototypes for mysys and my_func functions */
|
|---|
| 367 |
|
|---|
| 368 | extern int my_copy(const char *from,const char *to,myf MyFlags);
|
|---|
| 369 | extern int my_append(const char *from,const char *to,myf MyFlags);
|
|---|
| 370 | extern int my_delete(const char *name,myf MyFlags);
|
|---|
| 371 | extern int my_getwd(my_string buf,uint size,myf MyFlags);
|
|---|
| 372 | extern int my_setwd(const char *dir,myf MyFlags);
|
|---|
| 373 | extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags);
|
|---|
| 374 | extern gptr my_once_alloc(uint Size,myf MyFlags);
|
|---|
| 375 | extern void my_once_free(void);
|
|---|
| 376 | extern my_string my_tempnam(const char *dir,const char *pfx,myf MyFlags);
|
|---|
| 377 | extern File my_open(const char *FileName,int Flags,myf MyFlags);
|
|---|
| 378 | extern File my_register_filename(File fd, const char *FileName,
|
|---|
| 379 | enum file_type type_of_file,
|
|---|
| 380 | uint error_message_number, myf MyFlags);
|
|---|
| 381 | extern File my_create(const char *FileName,int CreateFlags,
|
|---|
| 382 | int AccsesFlags, myf MyFlags);
|
|---|
| 383 | extern int my_close(File Filedes,myf MyFlags);
|
|---|
| 384 | extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
|
|---|
| 385 | extern int my_readlink(char *to, const char *filename, myf MyFlags);
|
|---|
| 386 | extern int my_realpath(char *to, const char *filename, myf MyFlags);
|
|---|
| 387 | extern File my_create_with_symlink(const char *linkname, const char *filename,
|
|---|
| 388 | int createflags, int access_flags,
|
|---|
| 389 | myf MyFlags);
|
|---|
| 390 | extern int my_delete_with_symlink(const char *name, myf MyFlags);
|
|---|
| 391 | extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags);
|
|---|
| 392 | extern int my_symlink(const char *content, const char *linkname, myf MyFlags);
|
|---|
| 393 | extern uint my_read(File Filedes,byte *Buffer,uint Count,myf MyFlags);
|
|---|
| 394 | extern uint my_pread(File Filedes,byte *Buffer,uint Count,my_off_t offset,
|
|---|
| 395 | myf MyFlags);
|
|---|
| 396 | extern int my_rename(const char *from,const char *to,myf MyFlags);
|
|---|
| 397 | extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags);
|
|---|
| 398 | extern my_off_t my_tell(File fd,myf MyFlags);
|
|---|
| 399 | extern uint my_write(File Filedes,const byte *Buffer,uint Count,
|
|---|
| 400 | myf MyFlags);
|
|---|
| 401 | extern uint my_pwrite(File Filedes,const byte *Buffer,uint Count,
|
|---|
| 402 | my_off_t offset,myf MyFlags);
|
|---|
| 403 | extern uint my_fread(FILE *stream,byte *Buffer,uint Count,myf MyFlags);
|
|---|
| 404 | extern uint my_fwrite(FILE *stream,const byte *Buffer,uint Count,
|
|---|
| 405 | myf MyFlags);
|
|---|
| 406 | extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags);
|
|---|
| 407 | extern my_off_t my_ftell(FILE *stream,myf MyFlags);
|
|---|
| 408 | extern gptr _mymalloc(uint uSize,const char *sFile,
|
|---|
| 409 | uint uLine, myf MyFlag);
|
|---|
| 410 | extern gptr _myrealloc(gptr pPtr,uint uSize,const char *sFile,
|
|---|
| 411 | uint uLine, myf MyFlag);
|
|---|
| 412 | extern gptr my_multi_malloc _VARARGS((myf MyFlags, ...));
|
|---|
| 413 | extern void _myfree(gptr pPtr,const char *sFile,uint uLine, myf MyFlag);
|
|---|
| 414 | extern int _sanity(const char *sFile,unsigned int uLine);
|
|---|
| 415 | extern gptr _my_memdup(const byte *from,uint length,
|
|---|
| 416 | const char *sFile, uint uLine,myf MyFlag);
|
|---|
| 417 | extern my_string _my_strdup(const char *from, const char *sFile, uint uLine,
|
|---|
| 418 | myf MyFlag);
|
|---|
| 419 | #ifndef TERMINATE
|
|---|
| 420 | extern void TERMINATE(FILE *file);
|
|---|
| 421 | #endif
|
|---|
| 422 | extern void init_glob_errs(void);
|
|---|
| 423 | extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
|
|---|
| 424 | extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
|
|---|
| 425 | extern int my_fclose(FILE *fd,myf MyFlags);
|
|---|
| 426 | extern int my_chsize(File fd,my_off_t newlength,myf MyFlags);
|
|---|
| 427 | extern int my_error _VARARGS((int nr,myf MyFlags, ...));
|
|---|
| 428 | extern int my_printf_error _VARARGS((uint my_err, const char *format,
|
|---|
| 429 | myf MyFlags, ...)
|
|---|
| 430 | __attribute__ ((format (printf, 2, 4))));
|
|---|
| 431 | extern int my_vsnprintf( char *str, size_t n,
|
|---|
| 432 | const char *format, va_list ap );
|
|---|
| 433 | extern int my_snprintf(char* to, size_t n, const char* fmt, ...);
|
|---|
| 434 | extern int my_message(uint my_err, const char *str,myf MyFlags);
|
|---|
| 435 | extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags);
|
|---|
| 436 | extern int my_message_curses(uint my_err, const char *str,myf MyFlags);
|
|---|
| 437 | extern void my_init(void);
|
|---|
| 438 | extern void my_end(int infoflag);
|
|---|
| 439 | extern int my_redel(const char *from, const char *to, int MyFlags);
|
|---|
| 440 | extern int my_copystat(const char *from, const char *to, int MyFlags);
|
|---|
| 441 | extern my_string my_filename(File fd);
|
|---|
| 442 |
|
|---|
| 443 | #ifndef THREAD
|
|---|
| 444 | extern void dont_break(void);
|
|---|
| 445 | extern void allow_break(void);
|
|---|
| 446 | #else
|
|---|
| 447 | #define dont_break()
|
|---|
| 448 | #define allow_break()
|
|---|
| 449 | #endif
|
|---|
| 450 |
|
|---|
| 451 | extern void my_remember_signal(int signal_number,sig_handler (*func)(int));
|
|---|
| 452 | extern void caseup(my_string str,uint length);
|
|---|
| 453 | extern void casedn(my_string str,uint length);
|
|---|
| 454 | extern void caseup_str(my_string str);
|
|---|
| 455 | extern void casedn_str(my_string str);
|
|---|
| 456 | extern void case_sort(my_string str,uint length);
|
|---|
| 457 | extern uint dirname_part(my_string to,const char *name);
|
|---|
| 458 | extern uint dirname_length(const char *name);
|
|---|
| 459 | #define base_name(A) (A+dirname_length(A))
|
|---|
| 460 | extern int test_if_hard_path(const char *dir_name);
|
|---|
| 461 | extern char *convert_dirname(my_string name);
|
|---|
| 462 | extern void to_unix_path(my_string name);
|
|---|
| 463 | extern my_string fn_ext(const char *name);
|
|---|
| 464 | extern my_string fn_same(my_string toname,const char *name,int flag);
|
|---|
| 465 | extern my_string fn_format(my_string to,const char *name,const char *dsk,
|
|---|
| 466 | const char *form,int flag);
|
|---|
| 467 | extern size_s strlength(const char *str);
|
|---|
| 468 | extern void pack_dirname(my_string to,const char *from);
|
|---|
| 469 | extern uint unpack_dirname(my_string to,const char *from);
|
|---|
| 470 | extern uint cleanup_dirname(my_string to,const char *from);
|
|---|
| 471 | extern uint system_filename(my_string to,const char *from);
|
|---|
| 472 | extern my_string unpack_filename(my_string to,const char *from);
|
|---|
| 473 | extern my_string intern_filename(my_string to,const char *from);
|
|---|
| 474 | extern my_string directory_file_name(my_string dst, const char *src);
|
|---|
| 475 | extern int pack_filename(my_string to, const char *name, size_s max_length);
|
|---|
| 476 | extern my_string my_path(my_string to,const char *progname,
|
|---|
| 477 | const char *own_pathname_part);
|
|---|
| 478 | extern my_string my_load_path(my_string to, const char *path,
|
|---|
| 479 | const char *own_path_prefix);
|
|---|
| 480 | extern int wild_compare(const char *str,const char *wildstr);
|
|---|
| 481 | extern my_string my_strcasestr(const char *src,const char *suffix);
|
|---|
| 482 | extern int my_strcasecmp(const char *s,const char *t);
|
|---|
| 483 | extern int my_strsortcmp(const char *s,const char *t);
|
|---|
| 484 | extern int my_casecmp(const char *s,const char *t,uint length);
|
|---|
| 485 | extern int my_sortcmp(const char *s,const char *t,uint length);
|
|---|
| 486 | extern int my_sortncmp(const char *s,uint s_len, const char *t,uint t_len);
|
|---|
| 487 | extern WF_PACK *wf_comp(my_string str);
|
|---|
| 488 | extern int wf_test(struct wild_file_pack *wf_pack,const char *name);
|
|---|
| 489 | extern void wf_end(struct wild_file_pack *buffer);
|
|---|
| 490 | extern size_s stripp_sp(my_string str);
|
|---|
| 491 | extern void get_date(my_string to,int timeflag,time_t use_time);
|
|---|
| 492 | extern void soundex(my_string out_pntr, my_string in_pntr,pbool remove_garbage);
|
|---|
| 493 | extern int init_record_cache(RECORD_CACHE *info,uint cachesize,File file,
|
|---|
| 494 | uint reclength,enum cache_type type,
|
|---|
| 495 | pbool use_async_io);
|
|---|
| 496 | extern int read_cache_record(RECORD_CACHE *info,byte *to);
|
|---|
| 497 | extern int end_record_cache(RECORD_CACHE *info);
|
|---|
| 498 | extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos,
|
|---|
| 499 | const byte *record,uint length);
|
|---|
| 500 | extern int flush_write_cache(RECORD_CACHE *info);
|
|---|
| 501 | extern long my_clock(void);
|
|---|
| 502 | extern sig_handler sigtstp_handler(int signal_number);
|
|---|
| 503 | extern void handle_recived_signals(void);
|
|---|
| 504 | extern int init_key_cache(ulong use_mem,ulong leave_this_much_mem);
|
|---|
| 505 | extern byte *key_cache_read(File file,my_off_t filepos,byte* buff,uint length,
|
|---|
| 506 | uint block_length,int return_buffer);
|
|---|
| 507 | extern int key_cache_write(File file,my_off_t filepos,byte* buff,uint length,
|
|---|
| 508 | uint block_length,int force_write);
|
|---|
| 509 | extern int flush_key_blocks(int file, enum flush_type type);
|
|---|
| 510 | extern void end_key_cache(void);
|
|---|
| 511 | extern sig_handler my_set_alarm_variable(int signo);
|
|---|
| 512 | extern void my_string_ptr_sort(void *base,uint items,size_s size);
|
|---|
| 513 | extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
|
|---|
| 514 | size_s size_of_element,uchar *buffer[]);
|
|---|
| 515 | extern qsort_t qsort2(void *base_ptr, size_t total_elems, size_t size,
|
|---|
| 516 | qsort2_cmp cmp, void *cmp_argument);
|
|---|
| 517 | extern qsort2_cmp get_ptr_compare(uint);
|
|---|
| 518 | extern int init_io_cache(IO_CACHE *info,File file,uint cachesize,
|
|---|
| 519 | enum cache_type type,my_off_t seek_offset,
|
|---|
| 520 | pbool use_async_io, myf cache_myflags);
|
|---|
| 521 | extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
|
|---|
| 522 | my_off_t seek_offset,pbool use_async_io,
|
|---|
| 523 | pbool clear_cache);
|
|---|
| 524 | extern int _my_b_read(IO_CACHE *info,byte *Buffer,uint Count);
|
|---|
| 525 | extern int _my_b_net_read(IO_CACHE *info,byte *Buffer,uint Count);
|
|---|
| 526 | extern int _my_b_get(IO_CACHE *info);
|
|---|
| 527 | extern int _my_b_async_read(IO_CACHE *info,byte *Buffer,uint Count);
|
|---|
| 528 | extern int _my_b_write(IO_CACHE *info,const byte *Buffer,uint Count);
|
|---|
| 529 | extern int my_block_write(IO_CACHE *info, const byte *Buffer,
|
|---|
| 530 | uint Count, my_off_t pos);
|
|---|
| 531 | extern int flush_io_cache(IO_CACHE *info);
|
|---|
| 532 | extern int end_io_cache(IO_CACHE *info);
|
|---|
| 533 | extern uint my_b_fill(IO_CACHE *info);
|
|---|
| 534 | extern void my_b_seek(IO_CACHE *info,my_off_t pos);
|
|---|
| 535 | extern uint my_b_gets(IO_CACHE *info, char *to, uint max_length);
|
|---|
| 536 | extern uint my_b_printf(IO_CACHE *info, const char* fmt, ...);
|
|---|
| 537 | extern uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
|
|---|
| 538 | extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
|
|---|
| 539 | const char *prefix, uint cache_size,
|
|---|
| 540 | myf cache_myflags);
|
|---|
| 541 | extern my_bool real_open_cached_file(IO_CACHE *cache);
|
|---|
| 542 | extern void close_cached_file(IO_CACHE *cache);
|
|---|
| 543 | File create_temp_file(char *to, const char *dir, const char *pfx,
|
|---|
| 544 | int mode, myf MyFlags);
|
|---|
| 545 | extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size,
|
|---|
| 546 | uint init_alloc,uint alloc_increment);
|
|---|
| 547 | extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,gptr element);
|
|---|
| 548 | extern byte *alloc_dynamic(DYNAMIC_ARRAY *array);
|
|---|
| 549 | extern byte *pop_dynamic(DYNAMIC_ARRAY*);
|
|---|
| 550 | extern my_bool set_dynamic(DYNAMIC_ARRAY *array,gptr element,uint array_index);
|
|---|
| 551 | extern void get_dynamic(DYNAMIC_ARRAY *array,gptr element,uint array_index);
|
|---|
| 552 | extern void delete_dynamic(DYNAMIC_ARRAY *array);
|
|---|
| 553 | extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index);
|
|---|
| 554 | extern void freeze_size(DYNAMIC_ARRAY *array);
|
|---|
| 555 | #define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element)
|
|---|
| 556 | #define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index))
|
|---|
| 557 | #define push_dynamic(A,B) insert_dynamic(A,B)
|
|---|
| 558 |
|
|---|
| 559 | extern int find_type(my_string x,TYPELIB *typelib,uint full_name);
|
|---|
| 560 | extern void make_type(my_string to,uint nr,TYPELIB *typelib);
|
|---|
| 561 | extern const char *get_type(TYPELIB *typelib,uint nr);
|
|---|
| 562 | extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
|
|---|
| 563 | uint init_alloc,uint alloc_increment);
|
|---|
| 564 | extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append);
|
|---|
| 565 | my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
|
|---|
| 566 | uint length);
|
|---|
| 567 | extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str);
|
|---|
| 568 | extern my_bool dynstr_realloc(DYNAMIC_STRING *str, ulong additional_size);
|
|---|
| 569 | extern void dynstr_free(DYNAMIC_STRING *str);
|
|---|
| 570 | void set_all_changeable_vars(CHANGEABLE_VAR *vars);
|
|---|
| 571 | my_bool set_changeable_var(my_string str,CHANGEABLE_VAR *vars);
|
|---|
| 572 | my_bool set_changeable_varval(const char *var, ulong val,
|
|---|
| 573 | CHANGEABLE_VAR *vars);
|
|---|
| 574 | #ifdef HAVE_MLOCK
|
|---|
| 575 | extern byte *my_malloc_lock(uint length,myf flags);
|
|---|
| 576 | extern void my_free_lock(byte *ptr,myf flags);
|
|---|
| 577 | #else
|
|---|
| 578 | #define my_malloc_lock(A,B) my_malloc((A),(B))
|
|---|
| 579 | #define my_free_lock(A,B) my_free((A),(B))
|
|---|
| 580 | #endif
|
|---|
| 581 | #define alloc_root_inited(A) ((A)->min_malloc != 0)
|
|---|
| 582 | void init_alloc_root(MEM_ROOT *mem_root, uint block_size, uint pre_alloc_size);
|
|---|
| 583 | gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size);
|
|---|
| 584 | void free_root(MEM_ROOT *root, myf MyFLAGS);
|
|---|
| 585 | char *strdup_root(MEM_ROOT *root,const char *str);
|
|---|
| 586 | char *memdup_root(MEM_ROOT *root,const char *str,uint len);
|
|---|
| 587 | void load_defaults(const char *conf_file, const char **groups,
|
|---|
| 588 | int *argc, char ***argv);
|
|---|
| 589 | void free_defaults(char **argv);
|
|---|
| 590 | void print_defaults(const char *conf_file, const char **groups);
|
|---|
| 591 | my_bool my_compress(byte *, ulong *, ulong *);
|
|---|
| 592 | my_bool my_uncompress(byte *, ulong *, ulong *);
|
|---|
| 593 | byte *my_compress_alloc(const byte *packet, ulong *len, ulong *complen);
|
|---|
| 594 | ulong checksum(const byte *mem, uint count);
|
|---|
| 595 |
|
|---|
| 596 | #if defined(_MSC_VER) && !defined(__WIN__)
|
|---|
| 597 | extern void sleep(int sec);
|
|---|
| 598 | #endif
|
|---|
| 599 | #ifdef __WIN__
|
|---|
| 600 | extern my_bool have_tcpip; /* Is set if tcpip is used */
|
|---|
| 601 | #endif
|
|---|
| 602 |
|
|---|
| 603 | #ifdef __cplusplus
|
|---|
| 604 | }
|
|---|
| 605 | #endif
|
|---|
| 606 | #include "raid.h"
|
|---|
| 607 | #endif /* _my_sys_h */
|
|---|