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