1
/* Copyright (C) 2000-2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21
#include <sys/asynch.h> /* Used by record-cache */
22
typedef struct my_aio_result {
29
extern int my_errno; /* Last error in mysys */
31
#include <my_pthread.h>
34
#include <m_ctype.h> /* for CHARSET_INFO */
38
#define MYSYS_PROGRAM_DONT_USE_CURSES() { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
39
#define MY_INIT(name); { my_progname= name; my_init(); }
41
#define ERRMSGSIZE (SC_MAXWIDTH) /* Max length of a error message */
42
#define NRERRBUFFS (2) /* Buffers for parameters */
43
#define MY_FILE_ERROR ((size_t) -1)
45
/* General bitmaps for my_func's */
46
#define MY_FFNF 1 /* Fatal if file not found */
47
#define MY_FNABP 2 /* Fatal if not all bytes read/writen */
48
#define MY_NABP 4 /* Error if not all bytes read/writen */
49
#define MY_FAE 8 /* Fatal if any error */
50
#define MY_WME 16 /* Write message on error */
51
#define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */
52
#define MY_IGNORE_BADFD 32 /* my_sync: ignore 'bad descriptor' errors */
53
#define MY_SYNC_DIR 1024 /* my_create/delete/rename: sync directory */
54
#define MY_RAID 64 /* Support for RAID */
55
#define MY_FULL_IO 512 /* For my_read - loop intil I/O is complete */
56
#define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
57
#define MY_LINK_WARNING 32 /* my_redel() gives warning if links */
58
#define MY_COPYTIME 64 /* my_redel() copys time */
59
#define MY_DELETE_OLD 256 /* my_create_with_symlink() */
60
#define MY_RESOLVE_LINK 128 /* my_realpath(); Only resolve links */
61
#define MY_HOLD_ORIGINAL_MODES 128 /* my_copy() holds to file modes */
62
#define MY_REDEL_MAKE_BACKUP 256
63
#define MY_SEEK_NOT_DONE 32 /* my_lock may have to do a seek */
64
#define MY_DONT_WAIT 64 /* my_lock() don't wait if can't lock */
65
#define MY_ZEROFILL 32 /* my_malloc(), fill array with zero */
66
#define MY_ALLOW_ZERO_PTR 64 /* my_realloc() ; zero ptr -> malloc */
67
#define MY_FREE_ON_ERROR 128 /* my_realloc() ; Free old ptr on error */
68
#define MY_HOLD_ON_ERROR 256 /* my_realloc() ; Return old ptr on error */
69
#define MY_DONT_OVERWRITE_FILE 1024 /* my_copy: Don't overwrite file */
70
#define MY_THREADSAFE 2048 /* my_seek(): lock fd mutex */
72
#define MY_CHECK_ERROR 1 /* Params to my_end; Check open-close */
73
#define MY_GIVE_INFO 2 /* Give time info about process*/
74
#define MY_DONT_FREE_DBUG 4 /* Do not call DBUG_END() in my_end() */
76
#define MY_REMOVE_NONE 0 /* Params for modify_defaults_file */
77
#define MY_REMOVE_OPTION 1
78
#define MY_REMOVE_SECTION 2
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
#define ME_FATALERROR 1024 /* Fatal statement error */
94
/* Bits in last argument to fn_format */
95
#define MY_REPLACE_DIR 1 /* replace dir in name with 'dir' */
96
#define MY_REPLACE_EXT 2 /* replace extension with 'ext' */
97
#define MY_UNPACK_FILENAME 4 /* Unpack name (~ -> home) */
98
#define MY_PACK_FILENAME 8 /* Pack name (home -> ~) */
99
#define MY_RESOLVE_SYMLINKS 16 /* Resolve all symbolic links */
100
#define MY_RETURN_REAL_PATH 32 /* return full path for file */
101
#define MY_SAFE_PATH 64 /* Return NULL if too long path */
102
#define MY_RELATIVE_PATH 128 /* name is relative to 'dir' */
103
#define MY_APPEND_EXT 256 /* add 'ext' as additional extension*/
107
#define MY_SEEK_SET 0
108
#define MY_SEEK_CUR 1
109
#define MY_SEEK_END 2
112
#define MY_WAIT_FOR_USER_TO_FIX_PANIC 60 /* in seconds */
113
#define MY_WAIT_GIVE_USER_A_MESSAGE 10 /* Every 10 times of prev */
114
#define MIN_COMPRESS_LENGTH 50 /* Don't compress small bl. */
115
#define DFLT_INIT_HITS 3
117
/* root_alloc flags */
118
#define MY_KEEP_PREALLOC 1
119
#define MY_MARK_BLOCKS_FREE 2 /* move used to free list and reuse them */
121
/* Internal error numbers (for assembler functions) */
122
#define MY_ERRNO_EDOM 33
123
#define MY_ERRNO_ERANGE 34
125
/* Bits for get_date timeflag */
126
#define GETDATE_DATE_TIME 1
127
#define GETDATE_SHORT_DATE 2
128
#define GETDATE_HHMMSSTIME 4
129
#define GETDATE_GMT 8
130
#define GETDATE_FIXEDLENGTH 16
132
/* defines when allocating data */
135
#define my_checkmalloc()
137
#define TERMINATE(A,B) {}
138
#define QUICK_SAFEMALLOC
139
#define NORMAL_SAFEMALLOC
140
extern void *my_malloc(size_t Size,myf MyFlags);
141
#define my_malloc_ci(SZ,FLAG) my_malloc( SZ, FLAG )
142
extern void *my_realloc(void *oldpoint, size_t Size, myf MyFlags);
143
extern void my_no_flags_free(void *ptr);
144
extern void *my_memdup(const void *from,size_t length,myf MyFlags);
145
extern char *my_strdup(const char *from,myf MyFlags);
146
extern char *my_strndup(const char *from, size_t length,
148
/* we do use FG (as a no-op) in below so that a typo on FG is caught */
149
#define my_free(PTR,FG) ((void)FG,my_no_flags_free(PTR))
150
#define CALLER_INFO_PROTO /* nothing */
151
#define CALLER_INFO /* nothing */
152
#define ORIG_CALLER_INFO /* nothing */
153
#define TRASH(A,B) /* nothing */
156
#ifdef HAVE_LARGE_PAGES
157
extern uint my_get_large_page_size(void);
158
extern uchar * my_large_malloc(size_t size, myf my_flags);
159
extern void my_large_free(uchar * ptr, myf my_flags);
161
#define my_get_large_page_size() (0)
162
#define my_large_malloc(A,B) my_malloc_lock((A),(B))
163
#define my_large_free(A,B) my_free_lock((A),(B))
164
#endif /* HAVE_LARGE_PAGES */
167
#if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) && ! defined(alloca)
168
#define alloca __builtin_alloca
170
#define my_alloca(SZ) alloca((size_t) (SZ))
171
#define my_afree(PTR) {}
173
#define my_alloca(SZ) my_malloc(SZ,MYF(0))
174
#define my_afree(PTR) my_free(PTR,MYF(MY_WME))
175
#endif /* HAVE_ALLOCA */
177
#ifndef errno /* did we already get it? */
178
#ifdef HAVE_ERRNO_AS_DEFINE
179
#include <errno.h> /* errno is a define */
181
extern int errno; /* declare errno */
183
#endif /* #ifndef errno */
184
extern char errbuff[NRERRBUFFS][ERRMSGSIZE];
185
extern char *home_dir; /* Home directory for user */
186
extern const char *my_progname; /* program-name (printed in errors) */
187
extern char curr_dir[]; /* Current directory for user */
188
extern void (*error_handler_hook)(uint my_err, const char *str,myf MyFlags);
189
extern void (*fatal_error_handler_hook)(uint my_err, const char *str,
191
extern uint my_file_limit;
192
extern ulong my_thread_stack_size;
194
#ifdef HAVE_LARGE_PAGES
195
extern my_bool my_use_large_pages;
196
extern uint my_large_page_size;
200
extern CHARSET_INFO *default_charset_info;
201
extern CHARSET_INFO *all_charsets[256];
202
extern CHARSET_INFO compiled_charsets[];
205
extern ulong my_file_opened,my_stream_opened, my_tmp_file_created;
206
extern ulong my_file_total_opened;
207
extern uint mysys_usage_id;
208
extern my_bool my_init_done;
210
/* Point to current my_message() */
211
extern void (*my_sigtstp_cleanup)(void),
212
/* Executed before jump to shell */
213
(*my_sigtstp_restart)(void),
214
(*my_abort_hook)(int);
215
/* Executed when comming from shell */
216
extern int my_umask, /* Default creation mask */
218
my_recived_signals, /* Signals we have got */
219
my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */
220
my_dont_interrupt; /* call remember_intr when set */
221
extern my_bool mysys_uses_curses, my_use_symdir;
222
extern ulong sf_malloc_cur_memory, sf_malloc_max_memory;
224
extern ulong my_default_record_cache_size;
225
extern my_bool my_disable_locking, my_disable_async_io,
226
my_disable_flush_key_blocks, my_disable_symlinks;
227
extern char wild_many, wild_one, wild_prefix;
228
extern const char *charsets_dir;
230
extern char *my_defaults_extra_file;
231
extern const char *my_defaults_group_suffix;
232
extern const char *my_defaults_file;
234
extern my_bool timed_mutexes;
236
typedef struct wild_file_pack /* Struct to hold info when selecting files */
238
uint wilds; /* How many wildcards */
239
uint not_pos; /* Start of not-theese-files */
240
char * *wild; /* Pointer to wildcards */
251
TYPE_NOT_SET= 0, READ_CACHE, WRITE_CACHE,
252
SEQ_READ_APPEND /* sequential read or append */,
253
READ_FIFO, READ_NET,WRITE_NET};
257
FLUSH_KEEP, /* flush block and keep it in the cache */
258
FLUSH_RELEASE, /* flush block and remove it from the cache */
259
FLUSH_IGNORE_CHANGED, /* remove block from the cache */
261
As my_disable_flush_pagecache_blocks is always 0, the following option
262
is strictly equivalent to FLUSH_KEEP
267
typedef struct st_record_cache /* Used when cacheing records */
270
int rc_seek,error,inited;
271
uint rc_length,read_length,reclength;
272
my_off_t rc_record_pos,end_of_file;
273
uchar *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos;
276
my_aio_result aio_result;
278
enum cache_type type;
283
UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN,
284
FILE_BY_MKSTEMP, FILE_BY_DUP
287
struct st_my_file_info
291
#if defined(THREAD) && !defined(HAVE_PREAD)
292
pthread_mutex_t mutex;
296
extern struct st_my_file_info *my_file_info;
298
typedef struct st_dynamic_array
301
uint elements,max_element;
302
uint alloc_increment;
303
uint size_of_element;
306
typedef struct st_my_tmpdir
308
DYNAMIC_ARRAY full_list;
312
pthread_mutex_t mutex;
316
typedef struct st_dynamic_string
319
size_t length,max_length,alloc_increment;
323
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
326
typedef struct st_io_cache_share
328
pthread_mutex_t mutex; /* To sync on reads into buffer. */
329
pthread_cond_t cond; /* To wait for signals. */
330
pthread_cond_t cond_writer; /* For a synchronized writer. */
331
/* Offset in file corresponding to the first byte of buffer. */
332
my_off_t pos_in_file;
333
/* If a synchronized write cache is the source of the data. */
334
struct st_io_cache *source_cache;
335
uchar *buffer; /* The read buffer. */
336
uchar *read_end; /* Behind last valid byte of buffer. */
337
int running_threads; /* threads not in lock. */
338
int total_threads; /* threads sharing the cache. */
339
int error; /* Last error. */
340
#ifdef NOT_YET_IMPLEMENTED
341
/* whether the structure should be free'd */
347
typedef struct st_io_cache /* Used when cacheing files */
349
/* Offset in file corresponding to the first byte of uchar* buffer. */
350
my_off_t pos_in_file;
352
The offset of end of file for READ_CACHE and WRITE_CACHE.
353
For SEQ_READ_APPEND it the maximum of the actual end of file and
354
the position represented by read_end.
356
my_off_t end_of_file;
357
/* Points to current read position in the buffer */
359
/* the non-inclusive boundary in the buffer for the currently valid read */
361
uchar *buffer; /* The read buffer */
362
/* Used in ASYNC_IO */
365
/* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
368
Only used in SEQ_READ_APPEND, and points to the current read position
369
in the write buffer. Note that reads in SEQ_READ_APPEND caches can
370
happen from both read buffer (uchar* buffer) and write buffer
371
(uchar* write_buffer).
373
uchar *append_read_pos;
374
/* Points to current write position in the write buffer */
376
/* The non-inclusive boundary of the valid write area */
380
Current_pos and current_end are convenience variables used by
381
my_b_tell() and other routines that need to know the current offset
382
current_pos points to &write_pos, and current_end to &write_end in a
383
WRITE_CACHE, and &read_pos and &read_end respectively otherwise
385
uchar **current_pos, **current_end;
388
The lock is for append buffer used in SEQ_READ_APPEND cache
389
need mutex copying from append buffer to read buffer.
391
pthread_mutex_t append_buffer_lock;
393
The following is used when several threads are reading the
394
same file in parallel. They are synchronized on disk
395
accesses reading the cached part of the file asynchronously.
396
It should be set to NULL to disable the feature. Only
397
READ_CACHE mode is supported.
399
IO_CACHE_SHARE *share;
402
A caller will use my_b_read() macro to read from the cache
403
if the data is already in cache, it will be simply copied with
404
memcpy() and internal variables will be accordinging updated with
405
no functions invoked. However, if the data is not fully in the cache,
406
my_b_read() will call read_function to fetch the data. read_function
407
must never be invoked directly.
409
int (*read_function)(struct st_io_cache *,uchar *,size_t);
411
Same idea as in the case of read_function, except my_b_write() needs to
412
be replaced with my_b_append() for a SEQ_READ_APPEND cache
414
int (*write_function)(struct st_io_cache *,const uchar *,size_t);
416
Specifies the type of the cache. Depending on the type of the cache
417
certain operations might not be available and yield unpredicatable
418
results. Details to be documented later
420
enum cache_type type;
422
Callbacks when the actual read I/O happens. These were added and
423
are currently used for binary logging of LOAD DATA INFILE - when a
424
block is read from the file, we create a block create/append event, and
425
when IO_CACHE is closed, we create an end event. These functions could,
426
of course be used for other things
428
IO_CACHE_CALLBACK pre_read;
429
IO_CACHE_CALLBACK post_read;
430
IO_CACHE_CALLBACK pre_close;
432
Counts the number of times, when we were forced to use disk. We use it to
433
increase the binlog_cache_disk_use status variable.
436
void* arg; /* for use by pre/post_read */
437
char *file_name; /* if used with 'open_cached_file' */
439
File file; /* file descriptor */
441
seek_not_done is set by my_b_seek() to inform the upcoming read/write
442
operation that a seek needs to be preformed prior to the actual I/O
443
error is 0 if the cache operation was successful, -1 if there was a
444
"hard" error, and the actual number of I/O-ed bytes if the read/write was
447
int seek_not_done,error;
448
/* buffer_length is memory size allocated for buffer or write_buffer */
449
size_t buffer_length;
450
/* read_length is the same as buffer_length except when we use async io */
452
myf myflags; /* Flags used to my_read/my_write */
454
alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
455
0 if it was supplied by the user.
456
Currently READ_NET is the only one that will use a buffer allocated
459
my_bool alloced_buffer;
462
As inidicated by ifdef, this is for async I/O, which is not currently
463
used (because it's not reliable on all systems)
466
my_off_t aio_read_pos;
467
my_aio_result aio_result;
471
typedef int (*qsort2_cmp)(const void *, const void *, const void *);
473
/* defines for mf_iocache */
475
/* Test if buffer is inited */
476
#define my_b_clear(info) (info)->buffer=0
477
#define my_b_inited(info) (info)->buffer
478
#define my_b_EOF INT_MIN
480
#define my_b_read(info,Buffer,Count) \
481
((info)->read_pos + (Count) <= (info)->read_end ?\
482
(memcpy(Buffer,(info)->read_pos,(size_t) (Count)), \
483
((info)->read_pos+=(Count)),0) :\
484
(*(info)->read_function)((info),Buffer,Count))
486
#define my_b_write(info,Buffer,Count) \
487
((info)->write_pos + (Count) <=(info)->write_end ?\
488
(memcpy((info)->write_pos, (Buffer), (size_t)(Count)),\
489
((info)->write_pos+=(Count)),0) : \
490
(*(info)->write_function)((info),(Buffer),(Count)))
492
#define my_b_get(info) \
493
((info)->read_pos != (info)->read_end ?\
494
((info)->read_pos++, (int) (uchar) (info)->read_pos[-1]) :\
497
/* my_b_write_byte dosn't have any err-check */
498
#define my_b_write_byte(info,chr) \
499
(((info)->write_pos < (info)->write_end) ?\
500
((*(info)->write_pos++)=(chr)) :\
501
(_my_b_write(info,0,0) , ((*(info)->write_pos++)=(chr))))
503
#define my_b_fill_cache(info) \
504
(((info)->read_end=(info)->read_pos),(*(info)->read_function)(info,0,0))
506
#define my_b_tell(info) ((info)->pos_in_file + \
507
(size_t) (*(info)->current_pos - (info)->request_pos))
509
#define my_b_get_buffer_start(info) (info)->request_pos
510
#define my_b_get_bytes_in_buffer(info) (char*) (info)->read_end - \
511
(char*) my_b_get_buffer_start(info)
512
#define my_b_get_pos_in_file(info) (info)->pos_in_file
514
/* tell write offset in the SEQ_APPEND cache */
515
int my_b_copy_to_file(IO_CACHE *cache, FILE *file);
516
my_off_t my_b_append_tell(IO_CACHE* info);
517
my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
519
#define my_b_bytes_in_cache(info) (size_t) (*(info)->current_end - \
520
*(info)->current_pos)
522
typedef uint32 ha_checksum;
524
/* Define the type of function to be passed to process_default_option_files */
525
typedef int (*Process_option_func)(void *ctx, const char *group_name,
528
#include <my_alloc.h>
531
/* Prototypes for mysys and my_func functions */
533
extern int my_copy(const char *from,const char *to,myf MyFlags);
534
extern int my_append(const char *from,const char *to,myf MyFlags);
535
extern int my_delete(const char *name,myf MyFlags);
536
extern int my_getwd(char * buf,size_t size,myf MyFlags);
537
extern int my_setwd(const char *dir,myf MyFlags);
538
extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags);
539
extern void *my_once_alloc(size_t Size,myf MyFlags);
540
extern void my_once_free(void);
541
extern char *my_once_strdup(const char *src,myf myflags);
542
extern void *my_once_memdup(const void *src, size_t len, myf myflags);
543
extern File my_open(const char *FileName,int Flags,myf MyFlags);
544
extern File my_register_filename(File fd, const char *FileName,
545
enum file_type type_of_file,
546
uint error_message_number, myf MyFlags);
547
extern File my_create(const char *FileName,int CreateFlags,
548
int AccessFlags, myf MyFlags);
549
extern int my_close(File Filedes,myf MyFlags);
550
extern File my_dup(File file, myf MyFlags);
551
extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
552
extern int my_readlink(char *to, const char *filename, myf MyFlags);
553
extern int my_realpath(char *to, const char *filename, myf MyFlags);
554
extern File my_create_with_symlink(const char *linkname, const char *filename,
555
int createflags, int access_flags,
557
extern int my_delete_with_symlink(const char *name, myf MyFlags);
558
extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags);
559
extern int my_symlink(const char *content, const char *linkname, myf MyFlags);
560
extern size_t my_read(File Filedes,uchar *Buffer,size_t Count,myf MyFlags);
561
extern size_t my_pread(File Filedes,uchar *Buffer,size_t Count,my_off_t offset,
563
extern int my_rename(const char *from,const char *to,myf MyFlags);
564
extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags);
565
extern my_off_t my_tell(File fd,myf MyFlags);
566
extern size_t my_write(File Filedes,const uchar *Buffer,size_t Count,
568
extern size_t my_pwrite(File Filedes,const uchar *Buffer,size_t Count,
569
my_off_t offset,myf MyFlags);
570
extern size_t my_fread(FILE *stream,uchar *Buffer,size_t Count,myf MyFlags);
571
extern size_t my_fwrite(FILE *stream,const uchar *Buffer,size_t Count,
573
extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags);
574
extern my_off_t my_ftell(FILE *stream,myf MyFlags);
575
extern void *_mymalloc(size_t uSize,const char *sFile,
576
uint uLine, myf MyFlag);
577
extern void *_myrealloc(void *pPtr,size_t uSize,const char *sFile,
578
uint uLine, myf MyFlag);
579
extern void * my_multi_malloc _VARARGS((myf MyFlags, ...));
580
extern void _myfree(void *pPtr,const char *sFile,uint uLine, myf MyFlag);
581
extern int _sanity(const char *sFile, uint uLine);
582
extern void *_my_memdup(const void *from, size_t length,
583
const char *sFile, uint uLine,myf MyFlag);
584
extern char * _my_strdup(const char *from, const char *sFile, uint uLine,
586
extern char *_my_strndup(const char *from, size_t length,
587
const char *sFile, uint uLine,
590
/* implemented in my_memmem.c */
591
extern void *my_memmem(const void *haystack, size_t haystacklen,
592
const void *needle, size_t needlelen);
595
#define my_access access
596
extern int check_if_legal_filename(const char *path);
597
extern int check_if_legal_tablename(const char *path);
599
#define my_delete_allow_opened(fname,flags) my_delete((fname),(flags))
602
extern void TERMINATE(FILE *file, uint flag);
604
extern void init_glob_errs(void);
605
extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
606
extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
607
extern int my_fclose(FILE *fd,myf MyFlags);
608
extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
609
extern int my_sync(File fd, myf my_flags);
610
extern int my_sync_dir(const char *dir_name, myf my_flags);
611
extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
612
extern void my_error _VARARGS((int nr,myf MyFlags, ...));
613
extern void my_printf_error _VARARGS((uint my_err, const char *format,
615
ATTRIBUTE_FORMAT(printf, 2, 4);
616
extern int my_error_register(const char **errmsgs, int first, int last);
617
extern const char **my_error_unregister(int first, int last);
618
extern void my_message(uint my_err, const char *str,myf MyFlags);
619
extern void my_message_no_curses(uint my_err, const char *str,myf MyFlags);
620
extern my_bool my_init(void);
621
extern void my_end(int infoflag);
622
extern int my_redel(const char *from, const char *to, int MyFlags);
623
extern int my_copystat(const char *from, const char *to, int MyFlags);
624
extern char * my_filename(File fd);
627
extern void dont_break(void);
628
extern void allow_break(void);
631
#define allow_break()
635
void my_print_open_files(void);
637
#define my_print_open_files()
640
extern my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist);
641
extern char *my_tmpdir(MY_TMPDIR *tmpdir);
642
extern void free_tmpdir(MY_TMPDIR *tmpdir);
644
extern void my_remember_signal(int signal_number,sig_handler (*func)(int));
645
extern size_t dirname_part(char * to,const char *name, size_t *to_res_length);
646
extern size_t dirname_length(const char *name);
647
#define base_name(A) (A+dirname_length(A))
648
extern int test_if_hard_path(const char *dir_name);
649
extern my_bool has_path(const char *name);
650
extern char *convert_dirname(char *to, const char *from, const char *from_end);
651
extern void to_unix_path(char * name);
652
extern char * fn_ext(const char *name);
653
extern char * fn_same(char * toname,const char *name,int flag);
654
extern char * fn_format(char * to,const char *name,const char *dir,
655
const char *form, uint flag);
656
extern size_t strlength(const char *str);
657
extern void pack_dirname(char * to,const char *from);
658
extern size_t unpack_dirname(char * to,const char *from);
659
extern size_t cleanup_dirname(char * to,const char *from);
660
extern size_t system_filename(char * to,const char *from);
661
extern size_t unpack_filename(char * to,const char *from);
662
extern char * intern_filename(char * to,const char *from);
663
extern char * directory_file_name(char * dst, const char *src);
664
extern int pack_filename(char * to, const char *name, size_t max_length);
665
extern char * my_path(char * to,const char *progname,
666
const char *own_pathname_part);
667
extern char * my_load_path(char * to, const char *path,
668
const char *own_path_prefix);
669
extern int wild_compare(const char *str,const char *wildstr,
670
pbool str_is_pattern);
671
extern WF_PACK *wf_comp(char * str);
672
extern int wf_test(struct wild_file_pack *wf_pack,const char *name);
673
extern void wf_end(struct wild_file_pack *buffer);
674
extern size_t strip_sp(char * str);
675
extern my_bool array_append_string_unique(const char *str,
676
const char **array, size_t size);
677
extern void get_date(char * to,int timeflag,time_t use_time);
678
extern void soundex(CHARSET_INFO *, char * out_pntr, char * in_pntr,
679
pbool remove_garbage);
680
extern int init_record_cache(RECORD_CACHE *info,size_t cachesize,File file,
681
size_t reclength,enum cache_type type,
683
extern int read_cache_record(RECORD_CACHE *info,uchar *to);
684
extern int end_record_cache(RECORD_CACHE *info);
685
extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos,
686
const uchar *record,size_t length);
687
extern int flush_write_cache(RECORD_CACHE *info);
688
extern long my_clock(void);
689
extern sig_handler sigtstp_handler(int signal_number);
690
extern void handle_recived_signals(void);
692
extern sig_handler my_set_alarm_variable(int signo);
693
extern void my_string_ptr_sort(uchar *base,uint items,size_t size);
694
extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
695
size_t size_of_element,uchar *buffer[]);
696
extern qsort_t my_qsort(void *base_ptr, size_t total_elems, size_t size,
698
extern qsort_t my_qsort2(void *base_ptr, size_t total_elems, size_t size,
699
qsort2_cmp cmp, void *cmp_argument);
700
extern qsort2_cmp get_ptr_compare(size_t);
701
void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos);
702
my_off_t my_get_ptr(uchar *ptr, size_t pack_length);
703
extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
704
enum cache_type type,my_off_t seek_offset,
705
pbool use_async_io, myf cache_myflags);
706
extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
707
my_off_t seek_offset,pbool use_async_io,
709
extern void setup_io_cache(IO_CACHE* info);
710
extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count);
712
extern int _my_b_read_r(IO_CACHE *info,uchar *Buffer,size_t Count);
713
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
714
IO_CACHE *write_cache, uint num_threads);
715
extern void remove_io_thread(IO_CACHE *info);
717
extern int _my_b_seq_read(IO_CACHE *info,uchar *Buffer,size_t Count);
718
extern int _my_b_net_read(IO_CACHE *info,uchar *Buffer,size_t Count);
719
extern int _my_b_get(IO_CACHE *info);
720
extern int _my_b_async_read(IO_CACHE *info,uchar *Buffer,size_t Count);
721
extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
722
extern int my_b_append(IO_CACHE *info,const uchar *Buffer,size_t Count);
723
extern int my_b_safe_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
725
extern int my_block_write(IO_CACHE *info, const uchar *Buffer,
726
size_t Count, my_off_t pos);
727
extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
729
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
731
extern int end_io_cache(IO_CACHE *info);
732
extern size_t my_b_fill(IO_CACHE *info);
733
extern void my_b_seek(IO_CACHE *info,my_off_t pos);
734
extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
735
extern my_off_t my_b_filelength(IO_CACHE *info);
736
extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...);
737
extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
738
extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
739
const char *prefix, size_t cache_size,
741
extern my_bool real_open_cached_file(IO_CACHE *cache);
742
extern void close_cached_file(IO_CACHE *cache);
743
File create_temp_file(char *to, const char *dir, const char *pfx,
744
int mode, myf MyFlags);
745
#define my_init_dynamic_array(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D CALLER_INFO)
746
#define my_init_dynamic_array_ci(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D ORIG_CALLER_INFO)
747
#define my_init_dynamic_array2(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E CALLER_INFO)
748
#define my_init_dynamic_array2_ci(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E ORIG_CALLER_INFO)
749
extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array,uint element_size,
750
void *init_buffer, uint init_alloc,
753
/* init_dynamic_array() function is deprecated */
754
extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size,
755
uint init_alloc,uint alloc_increment
757
extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,uchar * element);
758
extern uchar *alloc_dynamic(DYNAMIC_ARRAY *array);
759
extern uchar *pop_dynamic(DYNAMIC_ARRAY*);
760
extern my_bool set_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
761
extern my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements);
762
extern void get_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
763
extern void delete_dynamic(DYNAMIC_ARRAY *array);
764
extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index);
765
extern void freeze_size(DYNAMIC_ARRAY *array);
766
extern int get_index_dynamic(DYNAMIC_ARRAY *array, uchar * element);
767
#define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element)
768
#define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index))
769
#define push_dynamic(A,B) insert_dynamic((A),(B))
770
#define reset_dynamic(array) ((array)->elements= 0)
771
#define sort_dynamic(A,cmp) my_qsort((A)->buffer, (A)->elements, (A)->size_of_element, (cmp))
773
extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
774
size_t init_alloc,size_t alloc_increment);
775
extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append);
776
my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
778
extern my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append,
780
extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str);
781
extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size);
782
extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n);
783
extern void dynstr_free(DYNAMIC_STRING *str);
785
extern void *my_malloc_lock(size_t length,myf flags);
786
extern void my_free_lock(void *ptr,myf flags);
788
#define my_malloc_lock(A,B) my_malloc((A),(B))
789
#define my_free_lock(A,B) my_free((A),(B))
791
#define alloc_root_inited(A) ((A)->min_malloc != 0)
792
#define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
793
#define clear_alloc_root(A) do { (A)->free= (A)->used= (A)->pre_alloc= 0; (A)->min_malloc=0;} while(0)
794
extern void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
795
size_t pre_alloc_size);
796
extern void *alloc_root(MEM_ROOT *mem_root, size_t Size);
797
extern void *multi_alloc_root(MEM_ROOT *mem_root, ...);
798
extern void free_root(MEM_ROOT *root, myf MyFLAGS);
799
extern void set_prealloc_root(MEM_ROOT *root, char *ptr);
800
extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
801
size_t prealloc_size);
802
extern char *strdup_root(MEM_ROOT *root,const char *str);
803
extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
804
extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
805
extern int get_defaults_options(int argc, char **argv,
806
char **defaults, char **extra_defaults,
807
char **group_suffix);
808
extern int load_defaults(const char *conf_file, const char **groups,
809
int *argc, char ***argv);
810
extern int modify_defaults_file(const char *file_location, const char *option,
811
const char *option_value,
812
const char *section_name, int remove_option);
813
extern int my_search_option_files(const char *conf_file, int *argc,
814
char ***argv, uint *args_used,
815
Process_option_func func, void *func_ctx);
816
extern void free_defaults(char **argv);
817
extern void my_print_default_files(const char *conf_file);
818
extern void print_defaults(const char *conf_file, const char **groups);
819
extern my_bool my_compress(uchar *, size_t *, size_t *);
820
extern my_bool my_uncompress(uchar *, size_t , size_t *);
821
extern uchar *my_compress_alloc(const uchar *packet, size_t *len,
823
extern int packfrm(uchar *, size_t, uchar **, size_t *);
824
extern int unpackfrm(uchar **, size_t *, const uchar *);
826
extern ha_checksum my_checksum(ha_checksum crc, const uchar *mem,
828
extern void my_sleep(ulong m_seconds);
829
extern ulong crc32(ulong crc, const uchar *buf, uint len);
830
extern uint my_set_max_open_files(uint files);
831
void my_free_open_file_info(void);
833
extern time_t my_time(myf flags);
834
extern ulonglong my_getsystime(void);
835
extern ulonglong my_micro_time();
836
extern ulonglong my_micro_time_and_time(time_t *time_arg);
837
time_t my_time_possible_from_micro(ulonglong microtime);
838
extern my_bool my_gethwaddr(uchar *to);
839
extern int my_getncpus();
841
#ifdef HAVE_SYS_MMAN_H
842
#include <sys/mman.h>
847
#ifndef MAP_NORESERVE
848
#define MAP_NORESERVE 0 /* For irix and AIX */
852
#define my_mmap(a,b,c,d,e,f) mmap64(a,b,c,d,e,f)
854
#define my_mmap(a,b,c,d,e,f) mmap(a,b,c,d,e,f)
856
#define my_munmap(a,b) munmap((a),(b))
859
/* not a complete set of mmap() flags, but only those that nesessary */
862
#define MAP_NORESERVE 0
863
#define MAP_SHARED 0x0001
864
#define MAP_PRIVATE 0x0002
865
#define MAP_NOSYNC 0x0800
866
#define MAP_FAILED ((void *)-1)
867
#define MS_SYNC 0x0000
873
void *my_mmap(void *, size_t, int, int, int, my_off_t);
874
int my_munmap(void *, size_t);
878
#ifdef HAVE_GETPAGESIZE
879
#define my_getpagesize() getpagesize()
881
int my_getpagesize(void);
884
int my_msync(int, void *, size_t, int);
887
extern uint get_charset_number(const char *cs_name, uint cs_flags);
888
extern uint get_collation_number(const char *name);
889
extern const char *get_charset_name(uint cs_number);
891
extern CHARSET_INFO *get_charset(uint cs_number, myf flags);
892
extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags);
893
extern CHARSET_INFO *get_charset_by_csname(const char *cs_name,
894
uint cs_flags, myf my_flags);
896
extern my_bool resolve_charset(const char *cs_name,
897
CHARSET_INFO *default_cs,
899
extern my_bool resolve_collation(const char *cl_name,
900
CHARSET_INFO *default_cl,
903
extern void free_charsets(void);
904
extern char *get_charsets_dir(char *buf);
905
extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2);
906
extern my_bool init_compiled_charsets(myf flags);
907
extern void add_compiled_collation(CHARSET_INFO *cs);
908
extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info,
909
char *to, size_t to_length,
910
const char *from, size_t length);
911
extern size_t escape_quotes_for_mysql(CHARSET_INFO *charset_info,
912
char *to, size_t to_length,
913
const char *from, size_t length);
915
extern void thd_increment_bytes_sent(ulong length);
916
extern void thd_increment_bytes_received(ulong length);
917
extern void thd_increment_net_big_packet_count(ulong length);
920
#endif /* _my_sys_h */