~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2003 MySQL AB
2
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.
6
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.
11
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 */
15
16
#ifndef _my_sys_h
17
#define _my_sys_h
18
C_MODE_START
19
20
#ifdef HAVE_AIOWAIT
21
#include <sys/asynch.h>			/* Used by record-cache */
22
typedef struct my_aio_result {
23
  aio_result_t result;
24
  int	       pending;
25
} my_aio_result;
26
#endif
27
12.4.2 by Stewart Smith
my_errno => errno
28
#include <errno.h>
29
#define my_errno (errno)
30
1 by brian
clean slate
31
#include <my_pthread.h>
32
33
#include <m_ctype.h>                    /* for CHARSET_INFO */
34
#include <stdarg.h>
35
#include <typelib.h>
36
37
#define MYSYS_PROGRAM_DONT_USE_CURSES()  { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
38
#define MY_INIT(name);		{ my_progname= name; my_init(); }
39
40
#define ERRMSGSIZE	(SC_MAXWIDTH)	/* Max length of a error message */
41
#define NRERRBUFFS	(2)	/* Buffers for parameters */
42
#define MY_FILE_ERROR	((size_t) -1)
43
44
	/* General bitmaps for my_func's */
45
#define MY_FFNF		1	/* Fatal if file not found */
46
#define MY_FNABP	2	/* Fatal if not all bytes read/writen */
47
#define MY_NABP		4	/* Error if not all bytes read/writen */
48
#define MY_FAE		8	/* Fatal if any error */
49
#define MY_WME		16	/* Write message on error */
50
#define MY_WAIT_IF_FULL 32	/* Wait and try again if disk full error */
51
#define MY_IGNORE_BADFD 32      /* my_sync: ignore 'bad descriptor' errors */
52
#define MY_SYNC_DIR     1024    /* my_create/delete/rename: sync directory */
53
#define MY_RAID         64      /* Support for RAID */
54
#define MY_FULL_IO     512      /* For my_read - loop intil I/O is complete */
55
#define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
56
#define MY_LINK_WARNING 32	/* my_redel() gives warning if links */
57
#define MY_COPYTIME	64	/* my_redel() copys time */
58
#define MY_DELETE_OLD	256	/* my_create_with_symlink() */
59
#define MY_RESOLVE_LINK 128	/* my_realpath(); Only resolve links */
60
#define MY_HOLD_ORIGINAL_MODES 128  /* my_copy() holds to file modes */
61
#define MY_REDEL_MAKE_BACKUP 256
62
#define MY_SEEK_NOT_DONE 32	/* my_lock may have to do a seek */
63
#define MY_DONT_WAIT	64	/* my_lock() don't wait if can't lock */
64
#define MY_ZEROFILL	32	/* my_malloc(), fill array with zero */
65
#define MY_ALLOW_ZERO_PTR 64	/* my_realloc() ; zero ptr -> malloc */
66
#define MY_FREE_ON_ERROR 128	/* my_realloc() ; Free old ptr on error */
67
#define MY_HOLD_ON_ERROR 256	/* my_realloc() ; Return old ptr on error */
68
#define MY_DONT_OVERWRITE_FILE 1024	/* my_copy: Don't overwrite file */
69
#define MY_THREADSAFE 2048      /* my_seek(): lock fd mutex */
70
71
#define MY_CHECK_ERROR	1	/* Params to my_end; Check open-close */
72
#define MY_GIVE_INFO	2	/* Give time info about process*/
73
#define MY_DONT_FREE_DBUG 4     /* Do not call DBUG_END() in my_end() */
74
75
#define MY_REMOVE_NONE    0     /* Params for modify_defaults_file */
76
#define MY_REMOVE_OPTION  1
77
#define MY_REMOVE_SECTION 2
78
79
#define ME_HIGHBYTE	8	/* Shift for colours */
80
#define ME_NOCUR	1	/* Don't use curses message */
81
#define ME_OLDWIN	2	/* Use old window */
82
#define ME_BELL		4	/* Ring bell then printing message */
83
#define ME_HOLDTANG	8	/* Don't delete last keys */
84
#define ME_WAITTOT	16	/* Wait for errtime secs of for a action */
85
#define ME_WAITTANG	32	/* Wait for a user action  */
86
#define ME_NOREFRESH	64	/* Dont refresh screen */
87
#define ME_NOINPUT	128	/* Dont use the input libary */
88
#define ME_COLOUR1	((1 << ME_HIGHBYTE))	/* Possibly error-colours */
89
#define ME_COLOUR2	((2 << ME_HIGHBYTE))
90
#define ME_COLOUR3	((3 << ME_HIGHBYTE))
91
#define ME_FATALERROR   1024    /* Fatal statement error */
92
93
	/* Bits in last argument to fn_format */
94
#define MY_REPLACE_DIR		1	/* replace dir in name with 'dir' */
95
#define MY_REPLACE_EXT		2	/* replace extension with 'ext' */
96
#define MY_UNPACK_FILENAME	4	/* Unpack name (~ -> home) */
97
#define MY_PACK_FILENAME	8	/* Pack name (home -> ~) */
98
#define MY_RESOLVE_SYMLINKS	16	/* Resolve all symbolic links */
99
#define MY_RETURN_REAL_PATH	32	/* return full path for file */
100
#define MY_SAFE_PATH		64	/* Return NULL if too long path */
101
#define MY_RELATIVE_PATH	128	/* name is relative to 'dir' */
102
#define MY_APPEND_EXT           256     /* add 'ext' as additional extension*/
103
104
105
	/* My seek flags */
106
#define MY_SEEK_SET	0
107
#define MY_SEEK_CUR	1
108
#define MY_SEEK_END	2
109
110
	/* Some constants */
111
#define MY_WAIT_FOR_USER_TO_FIX_PANIC	60	/* in seconds */
112
#define MY_WAIT_GIVE_USER_A_MESSAGE	10	/* Every 10 times of prev */
113
#define MIN_COMPRESS_LENGTH		50	/* Don't compress small bl. */
114
#define DFLT_INIT_HITS  3
115
116
	/* root_alloc flags */
117
#define MY_KEEP_PREALLOC	1
118
#define MY_MARK_BLOCKS_FREE     2  /* move used to free list and reuse them */
119
120
	/* Internal error numbers (for assembler functions) */
121
#define MY_ERRNO_EDOM		33
122
#define MY_ERRNO_ERANGE		34
123
124
	/* Bits for get_date timeflag */
125
#define GETDATE_DATE_TIME	1
126
#define GETDATE_SHORT_DATE	2
127
#define GETDATE_HHMMSSTIME	4
128
#define GETDATE_GMT		8
129
#define GETDATE_FIXEDLENGTH	16
130
131
	/* defines when allocating data */
132
#ifdef SAFEMALLOC
133
#else
134
#define my_checkmalloc()
135
#undef TERMINATE
136
#define TERMINATE(A,B) {}
137
#define QUICK_SAFEMALLOC
138
#define NORMAL_SAFEMALLOC
139
extern void *my_malloc(size_t Size,myf MyFlags);
140
#define my_malloc_ci(SZ,FLAG) my_malloc( SZ, FLAG )
141
extern void *my_realloc(void *oldpoint, size_t Size, myf MyFlags);
142
extern void my_no_flags_free(void *ptr);
143
extern void *my_memdup(const void *from,size_t length,myf MyFlags);
144
extern char *my_strdup(const char *from,myf MyFlags);
145
extern char *my_strndup(const char *from, size_t length,
146
				   myf MyFlags);
147
/* we do use FG (as a no-op) in below so that a typo on FG is caught */
148
#define my_free(PTR,FG) ((void)FG,my_no_flags_free(PTR))
149
#define CALLER_INFO_PROTO   /* nothing */
150
#define CALLER_INFO         /* nothing */
151
#define ORIG_CALLER_INFO    /* nothing */
152
#define TRASH(A,B) /* nothing */
153
#endif
154
155
#ifdef HAVE_ALLOCA
156
#if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) && ! defined(alloca)
157
#define alloca __builtin_alloca
158
#endif /* GNUC */
159
#define my_alloca(SZ) alloca((size_t) (SZ))
160
#define my_afree(PTR) {}
161
#else
162
#define my_alloca(SZ) my_malloc(SZ,MYF(0))
163
#define my_afree(PTR) my_free(PTR,MYF(MY_WME))
164
#endif /* HAVE_ALLOCA */
165
166
#ifndef errno				/* did we already get it? */
167
#ifdef HAVE_ERRNO_AS_DEFINE
168
#include <errno.h>			/* errno is a define */
169
#else
170
extern int errno;			/* declare errno */
171
#endif
172
#endif					/* #ifndef errno */
173
extern char errbuff[NRERRBUFFS][ERRMSGSIZE];
174
extern char *home_dir;			/* Home directory for user */
175
extern const char *my_progname;		/* program-name (printed in errors) */
176
extern void (*error_handler_hook)(uint my_err, const char *str,myf MyFlags);
177
extern void (*fatal_error_handler_hook)(uint my_err, const char *str,
178
                                        myf MyFlags);
179
extern uint my_file_limit;
180
extern ulong my_thread_stack_size;
181
182
/* charsets */
183
extern CHARSET_INFO *default_charset_info;
184
extern CHARSET_INFO *all_charsets[256];
185
extern CHARSET_INFO compiled_charsets[];
186
187
/* statistics */
188
extern ulong	my_file_opened,my_stream_opened, my_tmp_file_created;
189
extern ulong    my_file_total_opened;
190
extern uint	mysys_usage_id;
191
extern my_bool	my_init_done;
192
193
					/* Point to current my_message() */
194
extern void (*my_sigtstp_cleanup)(void),
195
					/* Executed before jump to shell */
196
	    (*my_sigtstp_restart)(void),
197
	    (*my_abort_hook)(int);
198
					/* Executed when comming from shell */
199
extern int my_umask,		/* Default creation mask  */
200
	   my_umask_dir,
201
	   my_recived_signals,	/* Signals we have got */
202
	   my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */
203
	   my_dont_interrupt;	/* call remember_intr when set */
204
extern my_bool mysys_uses_curses, my_use_symdir;
205
extern ulong sf_malloc_cur_memory, sf_malloc_max_memory;
206
207
extern ulong	my_default_record_cache_size;
208
extern my_bool my_disable_locking, my_disable_async_io,
209
               my_disable_flush_key_blocks, my_disable_symlinks;
210
extern char	wild_many, wild_one, wild_prefix;
211
extern const char *charsets_dir;
212
/* from default.c */
213
extern char *my_defaults_extra_file;
214
extern const char *my_defaults_group_suffix;
215
extern const char *my_defaults_file;
216
217
extern my_bool timed_mutexes;
218
219
typedef struct wild_file_pack	/* Struct to hold info when selecting files */
220
{
221
  uint		wilds;		/* How many wildcards */
222
  uint		not_pos;	/* Start of not-theese-files */
223
  char *	*wild;		/* Pointer to wildcards */
224
} WF_PACK;
225
226
enum loglevel {
227
   ERROR_LEVEL,
228
   WARNING_LEVEL,
229
   INFORMATION_LEVEL
230
};
231
232
enum cache_type
233
{
234
  TYPE_NOT_SET= 0, READ_CACHE, WRITE_CACHE,
235
  SEQ_READ_APPEND		/* sequential read or append */,
236
  READ_FIFO, READ_NET,WRITE_NET};
237
238
typedef struct st_record_cache	/* Used when cacheing records */
239
{
240
  File file;
241
  int	rc_seek,error,inited;
242
  uint	rc_length,read_length,reclength;
243
  my_off_t rc_record_pos,end_of_file;
244
  uchar *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos;
245
#ifdef HAVE_AIOWAIT
246
  int	use_async_io;
247
  my_aio_result aio_result;
248
#endif
249
  enum cache_type type;
250
} RECORD_CACHE;
251
252
enum file_type
253
{
254
  UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN,
255
  FILE_BY_MKSTEMP, FILE_BY_DUP
256
};
257
258
struct st_my_file_info
259
{
260
  char *		name;
261
  enum file_type	type;
28.1.35 by Monty Taylor
Removed all references to THREAD.
262
#if !defined(HAVE_PREAD)
1 by brian
clean slate
263
  pthread_mutex_t	mutex;
264
#endif
265
};
266
267
extern struct st_my_file_info *my_file_info;
268
269
typedef struct st_dynamic_array
270
{
271
  uchar *buffer;
272
  uint elements,max_element;
273
  uint alloc_increment;
274
  uint size_of_element;
275
} DYNAMIC_ARRAY;
276
277
typedef struct st_my_tmpdir
278
{
279
  DYNAMIC_ARRAY full_list;
280
  char **list;
281
  uint cur, max;
282
  pthread_mutex_t mutex;
283
} MY_TMPDIR;
284
285
typedef struct st_dynamic_string
286
{
287
  char *str;
288
  size_t length,max_length,alloc_increment;
289
} DYNAMIC_STRING;
290
291
struct st_io_cache;
292
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
293
294
typedef struct st_io_cache_share
295
{
296
  pthread_mutex_t       mutex;           /* To sync on reads into buffer. */
297
  pthread_cond_t        cond;            /* To wait for signals. */
298
  pthread_cond_t        cond_writer;     /* For a synchronized writer. */
299
  /* Offset in file corresponding to the first byte of buffer. */
300
  my_off_t              pos_in_file;
301
  /* If a synchronized write cache is the source of the data. */
302
  struct st_io_cache    *source_cache;
303
  uchar                 *buffer;         /* The read buffer. */
304
  uchar                 *read_end;       /* Behind last valid byte of buffer. */
305
  int                   running_threads; /* threads not in lock. */
306
  int                   total_threads;   /* threads sharing the cache. */
307
  int                   error;           /* Last error. */
308
#ifdef NOT_YET_IMPLEMENTED
309
  /* whether the structure should be free'd */
310
  my_bool alloced;
311
#endif
312
} IO_CACHE_SHARE;
313
314
typedef struct st_io_cache		/* Used when cacheing files */
315
{
316
  /* Offset in file corresponding to the first byte of uchar* buffer. */
317
  my_off_t pos_in_file;
318
  /*
319
    The offset of end of file for READ_CACHE and WRITE_CACHE.
320
    For SEQ_READ_APPEND it the maximum of the actual end of file and
321
    the position represented by read_end.
322
  */
323
  my_off_t end_of_file;
324
  /* Points to current read position in the buffer */
325
  uchar	*read_pos;
326
  /* the non-inclusive boundary in the buffer for the currently valid read */
327
  uchar  *read_end;
328
  uchar  *buffer;				/* The read buffer */
329
  /* Used in ASYNC_IO */
330
  uchar  *request_pos;
331
332
  /* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
333
  uchar  *write_buffer;
334
  /*
335
    Only used in SEQ_READ_APPEND, and points to the current read position
336
    in the write buffer. Note that reads in SEQ_READ_APPEND caches can
337
    happen from both read buffer (uchar* buffer) and write buffer
338
    (uchar* write_buffer).
339
  */
340
  uchar *append_read_pos;
341
  /* Points to current write position in the write buffer */
342
  uchar *write_pos;
343
  /* The non-inclusive boundary of the valid write area */
344
  uchar *write_end;
345
346
  /*
347
    Current_pos and current_end are convenience variables used by
348
    my_b_tell() and other routines that need to know the current offset
349
    current_pos points to &write_pos, and current_end to &write_end in a
350
    WRITE_CACHE, and &read_pos and &read_end respectively otherwise
351
  */
352
  uchar  **current_pos, **current_end;
353
  /*
354
    The lock is for append buffer used in SEQ_READ_APPEND cache
355
    need mutex copying from append buffer to read buffer.
356
  */
357
  pthread_mutex_t append_buffer_lock;
358
  /*
359
    The following is used when several threads are reading the
360
    same file in parallel. They are synchronized on disk
361
    accesses reading the cached part of the file asynchronously.
362
    It should be set to NULL to disable the feature.  Only
363
    READ_CACHE mode is supported.
364
  */
365
  IO_CACHE_SHARE *share;
366
  /*
367
    A caller will use my_b_read() macro to read from the cache
368
    if the data is already in cache, it will be simply copied with
369
    memcpy() and internal variables will be accordinging updated with
370
    no functions invoked. However, if the data is not fully in the cache,
371
    my_b_read() will call read_function to fetch the data. read_function
372
    must never be invoked directly.
373
  */
374
  int (*read_function)(struct st_io_cache *,uchar *,size_t);
375
  /*
376
    Same idea as in the case of read_function, except my_b_write() needs to
377
    be replaced with my_b_append() for a SEQ_READ_APPEND cache
378
  */
379
  int (*write_function)(struct st_io_cache *,const uchar *,size_t);
380
  /*
381
    Specifies the type of the cache. Depending on the type of the cache
382
    certain operations might not be available and yield unpredicatable
383
    results. Details to be documented later
384
  */
385
  enum cache_type type;
386
  /*
387
    Callbacks when the actual read I/O happens. These were added and
388
    are currently used for binary logging of LOAD DATA INFILE - when a
389
    block is read from the file, we create a block create/append event, and
390
    when IO_CACHE is closed, we create an end event. These functions could,
391
    of course be used for other things
392
  */
393
  IO_CACHE_CALLBACK pre_read;
394
  IO_CACHE_CALLBACK post_read;
395
  IO_CACHE_CALLBACK pre_close;
396
  /*
397
    Counts the number of times, when we were forced to use disk. We use it to
398
    increase the binlog_cache_disk_use status variable.
399
  */
400
  ulong disk_writes;
401
  void* arg;				/* for use by pre/post_read */
402
  char *file_name;			/* if used with 'open_cached_file' */
403
  char *dir,*prefix;
404
  File file; /* file descriptor */
405
  /*
406
    seek_not_done is set by my_b_seek() to inform the upcoming read/write
407
    operation that a seek needs to be preformed prior to the actual I/O
408
    error is 0 if the cache operation was successful, -1 if there was a
409
    "hard" error, and the actual number of I/O-ed bytes if the read/write was
410
    partial.
411
  */
412
  int	seek_not_done,error;
413
  /* buffer_length is memory size allocated for buffer or write_buffer */
414
  size_t	buffer_length;
415
  /* read_length is the same as buffer_length except when we use async io */
416
  size_t  read_length;
417
  myf	myflags;			/* Flags used to my_read/my_write */
418
  /*
419
    alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
420
    0 if it was supplied by the user.
421
    Currently READ_NET is the only one that will use a buffer allocated
422
    somewhere else
423
  */
424
  my_bool alloced_buffer;
425
#ifdef HAVE_AIOWAIT
426
  /*
427
    As inidicated by ifdef, this is for async I/O, which is not currently
428
    used (because it's not reliable on all systems)
429
  */
430
  uint inited;
431
  my_off_t aio_read_pos;
432
  my_aio_result aio_result;
433
#endif
434
} IO_CACHE;
435
436
typedef int (*qsort2_cmp)(const void *, const void *, const void *);
437
438
	/* defines for mf_iocache */
439
440
	/* Test if buffer is inited */
441
#define my_b_clear(info) (info)->buffer=0
442
#define my_b_inited(info) (info)->buffer
443
#define my_b_EOF INT_MIN
444
445
#define my_b_read(info,Buffer,Count) \
446
  ((info)->read_pos + (Count) <= (info)->read_end ?\
447
   (memcpy(Buffer,(info)->read_pos,(size_t) (Count)), \
448
    ((info)->read_pos+=(Count)),0) :\
449
   (*(info)->read_function)((info),Buffer,Count))
450
451
#define my_b_write(info,Buffer,Count) \
452
 ((info)->write_pos + (Count) <=(info)->write_end ?\
453
  (memcpy((info)->write_pos, (Buffer), (size_t)(Count)),\
454
   ((info)->write_pos+=(Count)),0) : \
455
   (*(info)->write_function)((info),(Buffer),(Count)))
456
457
#define my_b_get(info) \
458
  ((info)->read_pos != (info)->read_end ?\
459
   ((info)->read_pos++, (int) (uchar) (info)->read_pos[-1]) :\
460
   _my_b_get(info))
461
462
	/* my_b_write_byte dosn't have any err-check */
463
#define my_b_write_byte(info,chr) \
464
  (((info)->write_pos < (info)->write_end) ?\
465
   ((*(info)->write_pos++)=(chr)) :\
466
   (_my_b_write(info,0,0) , ((*(info)->write_pos++)=(chr))))
467
468
#define my_b_fill_cache(info) \
469
  (((info)->read_end=(info)->read_pos),(*(info)->read_function)(info,0,0))
470
471
#define my_b_tell(info) ((info)->pos_in_file + \
472
			 (size_t) (*(info)->current_pos - (info)->request_pos))
473
474
#define my_b_get_buffer_start(info) (info)->request_pos 
475
#define my_b_get_bytes_in_buffer(info) (char*) (info)->read_end -   \
476
  (char*) my_b_get_buffer_start(info)
477
#define my_b_get_pos_in_file(info) (info)->pos_in_file
478
479
/* tell write offset in the SEQ_APPEND cache */
480
int      my_b_copy_to_file(IO_CACHE *cache, FILE *file);
481
my_off_t my_b_append_tell(IO_CACHE* info);
482
my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
483
484
#define my_b_bytes_in_cache(info) (size_t) (*(info)->current_end - \
485
					  *(info)->current_pos)
486
487
typedef uint32 ha_checksum;
488
489
/* Define the type of function to be passed to process_default_option_files */
490
typedef int (*Process_option_func)(void *ctx, const char *group_name,
491
                                   const char *option);
492
493
#include <my_alloc.h>
494
495
496
	/* Prototypes for mysys and my_func functions */
497
498
extern int my_copy(const char *from,const char *to,myf MyFlags);
499
extern int my_append(const char *from,const char *to,myf MyFlags);
500
extern int my_delete(const char *name,myf MyFlags);
501
extern int my_getwd(char * buf,size_t size,myf MyFlags);
502
extern int my_setwd(const char *dir,myf MyFlags);
503
extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags);
504
extern void *my_once_alloc(size_t Size,myf MyFlags);
505
extern void my_once_free(void);
506
extern char *my_once_strdup(const char *src,myf myflags);
507
extern void *my_once_memdup(const void *src, size_t len, myf myflags);
508
extern File my_open(const char *FileName,int Flags,myf MyFlags);
509
extern File my_register_filename(File fd, const char *FileName,
510
				 enum file_type type_of_file,
511
				 uint error_message_number, myf MyFlags);
512
extern File my_create(const char *FileName,int CreateFlags,
513
		      int AccessFlags, myf MyFlags);
514
extern int my_close(File Filedes,myf MyFlags);
515
extern File my_dup(File file, myf MyFlags);
516
extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
517
extern int my_readlink(char *to, const char *filename, myf MyFlags);
518
extern int my_realpath(char *to, const char *filename, myf MyFlags);
519
extern File my_create_with_symlink(const char *linkname, const char *filename,
520
				   int createflags, int access_flags,
521
				   myf MyFlags);
522
extern int my_delete_with_symlink(const char *name, myf MyFlags);
523
extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags);
524
extern int my_symlink(const char *content, const char *linkname, myf MyFlags);
525
extern size_t my_read(File Filedes,uchar *Buffer,size_t Count,myf MyFlags);
526
extern int my_rename(const char *from,const char *to,myf MyFlags);
527
extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags);
528
extern my_off_t my_tell(File fd,myf MyFlags);
529
extern size_t my_write(File Filedes,const uchar *Buffer,size_t Count,
530
		     myf MyFlags);
531
extern size_t my_fread(FILE *stream,uchar *Buffer,size_t Count,myf MyFlags);
532
extern size_t my_fwrite(FILE *stream,const uchar *Buffer,size_t Count,
533
		      myf MyFlags);
534
extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags);
535
extern my_off_t my_ftell(FILE *stream,myf MyFlags);
536
extern void *_mymalloc(size_t uSize,const char *sFile,
537
                       uint uLine, myf MyFlag);
538
extern void *_myrealloc(void *pPtr,size_t uSize,const char *sFile,
539
		       uint uLine, myf MyFlag);
540
extern void * my_multi_malloc _VARARGS((myf MyFlags, ...));
541
extern void _myfree(void *pPtr,const char *sFile,uint uLine, myf MyFlag);
542
extern int _sanity(const char *sFile, uint uLine);
543
extern void *_my_memdup(const void *from, size_t length,
544
                        const char *sFile, uint uLine,myf MyFlag);
545
extern char * _my_strdup(const char *from, const char *sFile, uint uLine,
546
                         myf MyFlag);
547
extern char *_my_strndup(const char *from, size_t length,
548
                         const char *sFile, uint uLine,
549
                         myf MyFlag);
550
551
/* implemented in my_memmem.c */
552
extern void *my_memmem(const void *haystack, size_t haystacklen,
553
                       const void *needle, size_t needlelen);
554
555
556
#define my_access access
557
extern int check_if_legal_filename(const char *path);
558
extern int check_if_legal_tablename(const char *path);
559
560
#define my_delete_allow_opened(fname,flags)  my_delete((fname),(flags))
561
562
#ifndef TERMINATE
563
extern void TERMINATE(FILE *file, uint flag);
564
#endif
565
extern void init_glob_errs(void);
566
extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
567
extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
568
extern int my_fclose(FILE *fd,myf MyFlags);
569
extern int my_sync(File fd, myf my_flags);
570
extern int my_sync_dir(const char *dir_name, myf my_flags);
571
extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
572
extern void my_error _VARARGS((int nr,myf MyFlags, ...));
573
extern void my_printf_error _VARARGS((uint my_err, const char *format,
574
                                      myf MyFlags, ...))
575
				      ATTRIBUTE_FORMAT(printf, 2, 4);
576
extern int my_error_register(const char **errmsgs, int first, int last);
577
extern const char **my_error_unregister(int first, int last);
578
extern void my_message(uint my_err, const char *str,myf MyFlags);
579
extern void my_message_no_curses(uint my_err, const char *str,myf MyFlags);
580
extern my_bool my_init(void);
581
extern void my_end(int infoflag);
582
extern int my_redel(const char *from, const char *to, int MyFlags);
583
extern int my_copystat(const char *from, const char *to, int MyFlags);
584
extern char * my_filename(File fd);
585
586
#ifdef EXTRA_DEBUG
587
void my_print_open_files(void);
588
#else
589
#define my_print_open_files()
590
#endif
591
592
extern my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist);
593
extern char *my_tmpdir(MY_TMPDIR *tmpdir);
594
extern void free_tmpdir(MY_TMPDIR *tmpdir);
595
596
extern void my_remember_signal(int signal_number,sig_handler (*func)(int));
597
extern size_t dirname_part(char * to,const char *name, size_t *to_res_length);
598
extern size_t dirname_length(const char *name);
599
#define base_name(A) (A+dirname_length(A))
600
extern int test_if_hard_path(const char *dir_name);
601
extern my_bool has_path(const char *name);
602
extern char *convert_dirname(char *to, const char *from, const char *from_end);
603
extern void to_unix_path(char * name);
604
extern char * fn_ext(const char *name);
605
extern char * fn_same(char * toname,const char *name,int flag);
606
extern char * fn_format(char * to,const char *name,const char *dir,
607
			   const char *form, uint flag);
608
extern size_t strlength(const char *str);
609
extern void pack_dirname(char * to,const char *from);
610
extern size_t unpack_dirname(char * to,const char *from);
611
extern size_t cleanup_dirname(char * to,const char *from);
612
extern size_t system_filename(char * to,const char *from);
613
extern size_t unpack_filename(char * to,const char *from);
614
extern char * intern_filename(char * to,const char *from);
615
extern char * directory_file_name(char * dst, const char *src);
616
extern int pack_filename(char * to, const char *name, size_t max_length);
617
extern char * my_path(char * to,const char *progname,
618
			 const char *own_pathname_part);
619
extern char * my_load_path(char * to, const char *path,
620
			      const char *own_path_prefix);
621
extern int wild_compare(const char *str,const char *wildstr,
622
                        pbool str_is_pattern);
623
extern WF_PACK *wf_comp(char * str);
624
extern int wf_test(struct wild_file_pack *wf_pack,const char *name);
625
extern void wf_end(struct wild_file_pack *buffer);
626
extern size_t strip_sp(char * str);
627
extern my_bool array_append_string_unique(const char *str,
628
                                          const char **array, size_t size);
629
extern void get_date(char * to,int timeflag,time_t use_time);
630
extern void soundex(CHARSET_INFO *, char * out_pntr, char * in_pntr,
631
                    pbool remove_garbage);
632
extern int init_record_cache(RECORD_CACHE *info,size_t cachesize,File file,
633
			     size_t reclength,enum cache_type type,
634
			     pbool use_async_io);
635
extern int read_cache_record(RECORD_CACHE *info,uchar *to);
636
extern int end_record_cache(RECORD_CACHE *info);
637
extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos,
638
			      const uchar *record,size_t length);
639
extern int flush_write_cache(RECORD_CACHE *info);
640
extern long my_clock(void);
641
extern sig_handler sigtstp_handler(int signal_number);
642
extern void handle_recived_signals(void);
643
644
extern sig_handler my_set_alarm_variable(int signo);
645
extern void my_string_ptr_sort(uchar *base,uint items,size_t size);
646
extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
647
				  size_t size_of_element,uchar *buffer[]);
648
extern qsort_t my_qsort(void *base_ptr, size_t total_elems, size_t size,
649
                        qsort_cmp cmp);
650
extern qsort_t my_qsort2(void *base_ptr, size_t total_elems, size_t size,
651
                         qsort2_cmp cmp, void *cmp_argument);
652
extern qsort2_cmp get_ptr_compare(size_t);
653
void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos);
654
my_off_t my_get_ptr(uchar *ptr, size_t pack_length);
655
extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
656
			 enum cache_type type,my_off_t seek_offset,
657
			 pbool use_async_io, myf cache_myflags);
658
extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
659
			       my_off_t seek_offset,pbool use_async_io,
660
			       pbool clear_cache);
661
extern void setup_io_cache(IO_CACHE* info);
662
extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count);
663
extern int _my_b_read_r(IO_CACHE *info,uchar *Buffer,size_t Count);
664
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
665
                                IO_CACHE *write_cache, uint num_threads);
666
extern void remove_io_thread(IO_CACHE *info);
667
extern int _my_b_seq_read(IO_CACHE *info,uchar *Buffer,size_t Count);
668
extern int _my_b_net_read(IO_CACHE *info,uchar *Buffer,size_t Count);
669
extern int _my_b_get(IO_CACHE *info);
670
extern int _my_b_async_read(IO_CACHE *info,uchar *Buffer,size_t Count);
671
extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
672
extern int my_b_append(IO_CACHE *info,const uchar *Buffer,size_t Count);
673
extern int my_b_safe_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
674
675
extern int my_block_write(IO_CACHE *info, const uchar *Buffer,
676
			  size_t Count, my_off_t pos);
677
extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
678
679
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
680
681
extern int end_io_cache(IO_CACHE *info);
682
extern size_t my_b_fill(IO_CACHE *info);
683
extern void my_b_seek(IO_CACHE *info,my_off_t pos);
684
extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
685
extern my_off_t my_b_filelength(IO_CACHE *info);
686
extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...);
687
extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
688
extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
689
				 const char *prefix, size_t cache_size,
690
				 myf cache_myflags);
691
extern my_bool real_open_cached_file(IO_CACHE *cache);
692
extern void close_cached_file(IO_CACHE *cache);
693
File create_temp_file(char *to, const char *dir, const char *pfx,
694
		      int mode, myf MyFlags);
695
#define my_init_dynamic_array(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D CALLER_INFO)
696
#define my_init_dynamic_array_ci(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D ORIG_CALLER_INFO)
697
#define my_init_dynamic_array2(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E CALLER_INFO)
698
#define my_init_dynamic_array2_ci(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E ORIG_CALLER_INFO)
699
extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array,uint element_size,
700
                                   void *init_buffer, uint init_alloc, 
701
                                   uint alloc_increment
702
                                   CALLER_INFO_PROTO);
703
/* init_dynamic_array() function is deprecated */
704
extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size,
705
                                  uint init_alloc,uint alloc_increment
706
                                  CALLER_INFO_PROTO);
707
extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,uchar * element);
708
extern uchar *alloc_dynamic(DYNAMIC_ARRAY *array);
709
extern uchar *pop_dynamic(DYNAMIC_ARRAY*);
710
extern my_bool set_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
711
extern my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements);
712
extern void get_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
713
extern void delete_dynamic(DYNAMIC_ARRAY *array);
714
extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index);
715
extern void freeze_size(DYNAMIC_ARRAY *array);
716
extern int  get_index_dynamic(DYNAMIC_ARRAY *array, uchar * element);
717
#define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element)
718
#define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index))
719
#define push_dynamic(A,B) insert_dynamic((A),(B))
720
#define reset_dynamic(array) ((array)->elements= 0)
721
#define sort_dynamic(A,cmp) my_qsort((A)->buffer, (A)->elements, (A)->size_of_element, (cmp))
722
723
extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
724
				   size_t init_alloc,size_t alloc_increment);
725
extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append);
726
my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
727
			  size_t length);
728
extern my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append,
729
                                       ...);
730
extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str);
731
extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size);
732
extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n);
733
extern void dynstr_free(DYNAMIC_STRING *str);
734
#ifdef HAVE_MLOCK
735
extern void *my_malloc_lock(size_t length,myf flags);
736
extern void my_free_lock(void *ptr,myf flags);
737
#else
738
#define my_malloc_lock(A,B) my_malloc((A),(B))
739
#define my_free_lock(A,B) my_free((A),(B))
740
#endif
741
#define alloc_root_inited(A) ((A)->min_malloc != 0)
742
#define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
743
#define clear_alloc_root(A) do { (A)->free= (A)->used= (A)->pre_alloc= 0; (A)->min_malloc=0;} while(0)
744
extern void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
745
			    size_t pre_alloc_size);
746
extern void *alloc_root(MEM_ROOT *mem_root, size_t Size);
747
extern void *multi_alloc_root(MEM_ROOT *mem_root, ...);
748
extern void free_root(MEM_ROOT *root, myf MyFLAGS);
749
extern void set_prealloc_root(MEM_ROOT *root, char *ptr);
750
extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
751
                                size_t prealloc_size);
752
extern char *strdup_root(MEM_ROOT *root,const char *str);
753
extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
754
extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
755
extern int get_defaults_options(int argc, char **argv,
756
                                char **defaults, char **extra_defaults,
757
                                char **group_suffix);
758
extern int load_defaults(const char *conf_file, const char **groups,
759
			 int *argc, char ***argv);
760
extern int modify_defaults_file(const char *file_location, const char *option,
761
                                const char *option_value,
762
                                const char *section_name, int remove_option);
763
extern int my_search_option_files(const char *conf_file, int *argc,
764
                                  char ***argv, uint *args_used,
765
                                  Process_option_func func, void *func_ctx);
766
extern void free_defaults(char **argv);
767
extern void my_print_default_files(const char *conf_file);
768
extern void print_defaults(const char *conf_file, const char **groups);
769
extern my_bool my_compress(uchar *, size_t *, size_t *);
770
extern my_bool my_uncompress(uchar *, size_t , size_t *);
771
extern uchar *my_compress_alloc(const uchar *packet, size_t *len,
772
                                size_t *complen);
773
extern ha_checksum my_checksum(ha_checksum crc, const uchar *mem,
774
                               size_t count);
775
extern void my_sleep(ulong m_seconds);
776
extern uint my_set_max_open_files(uint files);
777
void my_free_open_file_info(void);
778
779
extern time_t my_time(myf flags);
780
extern ulonglong my_getsystime(void);
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
781
extern ulonglong my_micro_time(void);
1 by brian
clean slate
782
extern ulonglong my_micro_time_and_time(time_t *time_arg);
783
time_t my_time_possible_from_micro(ulonglong microtime);
784
extern my_bool my_gethwaddr(uchar *to);
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
785
extern int my_getncpus(void);
1 by brian
clean slate
786
787
#ifdef HAVE_SYS_MMAN_H
788
#include <sys/mman.h>
789
790
#ifndef MAP_NOSYNC
791
#define MAP_NOSYNC      0
792
#endif
793
#ifndef MAP_NORESERVE
794
#define MAP_NORESERVE 0         /* For irix and AIX */
795
#endif
796
797
#ifdef HAVE_MMAP64
798
#define my_mmap(a,b,c,d,e,f)    mmap64(a,b,c,d,e,f)
799
#else
800
#define my_mmap(a,b,c,d,e,f)    mmap(a,b,c,d,e,f)
801
#endif
802
#define my_munmap(a,b)          munmap((a),(b))
803
804
#else
805
/* not a complete set of mmap() flags, but only those that nesessary */
806
#define PROT_READ        1
807
#define PROT_WRITE       2
808
#define MAP_NORESERVE    0
809
#define MAP_SHARED       0x0001
810
#define MAP_PRIVATE      0x0002
811
#define MAP_NOSYNC       0x0800
812
#define MAP_FAILED       ((void *)-1)
813
#define MS_SYNC          0x0000
814
815
#ifndef __NETWARE__
816
#define HAVE_MMAP
817
#endif
818
819
void *my_mmap(void *, size_t, int, int, int, my_off_t);
820
int my_munmap(void *, size_t);
821
#endif
822
823
/* my_getpagesize */
824
#ifdef HAVE_GETPAGESIZE
825
#define my_getpagesize()        getpagesize()
826
#else
827
int my_getpagesize(void);
828
#endif
829
830
/* character sets */
831
extern uint get_charset_number(const char *cs_name, uint cs_flags);
832
extern uint get_collation_number(const char *name);
833
extern const char *get_charset_name(uint cs_number);
834
835
extern CHARSET_INFO *get_charset(uint cs_number, myf flags);
836
extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags);
837
extern CHARSET_INFO *get_charset_by_csname(const char *cs_name,
838
					   uint cs_flags, myf my_flags);
839
840
extern my_bool resolve_charset(const char *cs_name,
841
                               CHARSET_INFO *default_cs,
842
                               CHARSET_INFO **cs);
843
extern my_bool resolve_collation(const char *cl_name,
844
                                 CHARSET_INFO *default_cl,
845
                                 CHARSET_INFO **cl);
846
847
extern void free_charsets(void);
848
extern char *get_charsets_dir(char *buf);
849
extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2);
850
extern my_bool init_compiled_charsets(myf flags);
851
extern void add_compiled_collation(CHARSET_INFO *cs);
852
extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info,
853
                                      char *to, size_t to_length,
854
                                      const char *from, size_t length);
855
extern size_t escape_quotes_for_mysql(CHARSET_INFO *charset_info,
856
                                      char *to, size_t to_length,
857
                                      const char *from, size_t length);
858
859
extern void thd_increment_bytes_sent(ulong length);
860
extern void thd_increment_bytes_received(ulong length);
861
extern void thd_increment_net_big_packet_count(ulong length);
862
863
C_MODE_END
864
#endif /* _my_sys_h */