~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/my_sys.h

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:20:18 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705112018-fr12kkmgphtu7m29
Changes so that removal of duplicate curr_dir from my_sys.h work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 MySQL
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
 
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 */
20
15
 
21
16
#ifndef _my_sys_h
22
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
23
27
 
24
28
#include <errno.h>
25
29
#define my_errno (errno)
26
30
 
27
 
#include <mysys/my_pthread.h>
 
31
#include <my_pthread.h>
28
32
 
29
 
#include <mystrings/m_ctype.h>                    /* for CHARSET_INFO */
 
33
#include <m_ctype.h>                    /* for CHARSET_INFO */
30
34
#include <stdarg.h>
31
 
#include <mysys/typelib.h>
32
 
#include <mysys/aio_result.h>
33
 
 
34
 
#include <mysys/my_alloc.h>
35
 
 
 
35
#include <typelib.h>
 
36
 
 
37
#define MYSYS_PROGRAM_DONT_USE_CURSES()  { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
36
38
#define MY_INIT(name);          { my_progname= name; my_init(); }
37
39
 
38
40
#define ERRMSGSIZE      (SC_MAXWIDTH)   /* Max length of a error message */
48
50
#define MY_WAIT_IF_FULL 32      /* Wait and try again if disk full error */
49
51
#define MY_IGNORE_BADFD 32      /* my_sync: ignore 'bad descriptor' errors */
50
52
#define MY_SYNC_DIR     1024    /* my_create/delete/rename: sync directory */
 
53
#define MY_RAID         64      /* Support for RAID */
51
54
#define MY_FULL_IO     512      /* For my_read - loop intil I/O is complete */
52
55
#define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
53
56
#define MY_LINK_WARNING 32      /* my_redel() gives warning if links */
67
70
 
68
71
#define MY_CHECK_ERROR  1       /* Params to my_end; Check open-close */
69
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() */
70
74
 
71
75
#define MY_REMOVE_NONE    0     /* Params for modify_defaults_file */
72
76
#define MY_REMOVE_OPTION  1
106
110
        /* Some constants */
107
111
#define MY_WAIT_FOR_USER_TO_FIX_PANIC   60      /* in seconds */
108
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. */
109
114
#define DFLT_INIT_HITS  3
110
115
 
111
116
        /* root_alloc flags */
124
129
#define GETDATE_FIXEDLENGTH     16
125
130
 
126
131
        /* defines when allocating data */
 
132
#ifdef SAFEMALLOC
 
133
#else
127
134
#define my_checkmalloc()
128
135
#undef TERMINATE
129
136
#define TERMINATE(A,B) {}
130
 
 
131
 
#ifdef __cplusplus
132
 
extern "C" {
133
 
#endif
134
 
 
135
 
typedef int  (*qsort_cmp)(const void *,const void *);
136
 
typedef int  (*qsort_cmp2)(void*, const void *,const void *);
137
 
 
 
137
#define QUICK_SAFEMALLOC
 
138
#define NORMAL_SAFEMALLOC
138
139
extern void *my_malloc(size_t Size,myf MyFlags);
139
140
#define my_malloc_ci(SZ,FLAG) my_malloc( SZ, FLAG )
140
141
extern void *my_realloc(void *oldpoint, size_t Size, myf MyFlags);
143
144
extern char *my_strdup(const char *from,myf MyFlags);
144
145
extern char *my_strndup(const char *from, size_t length,
145
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))
146
149
#define CALLER_INFO_PROTO   /* nothing */
147
150
#define CALLER_INFO         /* nothing */
148
151
#define ORIG_CALLER_INFO    /* nothing */
149
152
#define TRASH(A,B) /* nothing */
 
153
#endif
150
154
 
151
155
#ifdef HAVE_ALLOCA
152
156
#if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) && ! defined(alloca)
153
157
#define alloca __builtin_alloca
154
158
#endif /* GNUC */
155
 
#define my_alloca(SZ) malloc((size_t) (SZ))
156
 
#define my_afree(PTR) free((PTR))
 
159
#define my_alloca(SZ) alloca((size_t) (SZ))
 
160
#define my_afree(PTR) {}
157
161
#else
158
 
#define my_alloca(SZ) malloc((SZ))
159
 
#define my_afree(PTR) free((PTR))
 
162
#define my_alloca(SZ) my_malloc(SZ,MYF(0))
 
163
#define my_afree(PTR) my_free(PTR,MYF(MY_WME))
160
164
#endif /* HAVE_ALLOCA */
161
165
 
162
166
#ifndef errno                           /* did we already get it? */
169
173
extern char errbuff[NRERRBUFFS][ERRMSGSIZE];
170
174
extern char *home_dir;                  /* Home directory for user */
171
175
extern const char *my_progname;         /* program-name (printed in errors) */
172
 
extern void (*error_handler_hook)(uint32_t my_err, const char *str,myf MyFlags);
173
 
extern void (*fatal_error_handler_hook)(uint32_t my_err, const char *str,
 
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,
174
178
                                        myf MyFlags);
175
 
extern uint32_t my_file_limit;
176
 
extern uint32_t my_thread_stack_size;
 
179
extern uint my_file_limit;
 
180
extern ulong my_thread_stack_size;
177
181
 
178
182
/* charsets */
179
 
extern const CHARSET_INFO *default_charset_info;
 
183
extern CHARSET_INFO *default_charset_info;
180
184
extern CHARSET_INFO *all_charsets[256];
181
185
extern CHARSET_INFO compiled_charsets[];
182
186
 
183
187
/* statistics */
184
 
extern uint32_t my_file_opened,my_stream_opened, my_tmp_file_created;
185
 
extern uint32_t    my_file_total_opened;
 
188
extern ulong    my_file_opened,my_stream_opened, my_tmp_file_created;
 
189
extern ulong    my_file_total_opened;
186
190
extern uint     mysys_usage_id;
187
 
extern bool     my_init_done;
 
191
extern my_bool  my_init_done;
188
192
 
189
193
                                        /* Point to current my_message() */
190
194
extern void (*my_sigtstp_cleanup)(void),
197
201
           my_recived_signals,  /* Signals we have got */
198
202
           my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */
199
203
           my_dont_interrupt;   /* call remember_intr when set */
200
 
extern bool mysys_uses_curses, my_use_symdir;
201
 
extern uint32_t sf_malloc_cur_memory, sf_malloc_max_memory;
 
204
extern my_bool mysys_uses_curses, my_use_symdir;
 
205
extern ulong sf_malloc_cur_memory, sf_malloc_max_memory;
202
206
 
203
 
extern uint32_t my_default_record_cache_size;
204
 
extern bool my_disable_async_io,
 
207
extern ulong    my_default_record_cache_size;
 
208
extern my_bool my_disable_locking, my_disable_async_io,
205
209
               my_disable_flush_key_blocks, my_disable_symlinks;
206
210
extern char     wild_many, wild_one, wild_prefix;
207
211
extern const char *charsets_dir;
210
214
extern const char *my_defaults_group_suffix;
211
215
extern const char *my_defaults_file;
212
216
 
213
 
extern bool timed_mutexes;
 
217
extern my_bool timed_mutexes;
214
218
 
215
219
typedef struct wild_file_pack   /* Struct to hold info when selecting files */
216
220
{
231
235
  SEQ_READ_APPEND               /* sequential read or append */,
232
236
  READ_FIFO, READ_NET,WRITE_NET};
233
237
 
 
238
enum flush_type
 
239
{
 
240
  FLUSH_KEEP,           /* flush block and keep it in the cache */
 
241
  FLUSH_RELEASE,        /* flush block and remove it from the cache */
 
242
  FLUSH_IGNORE_CHANGED, /* remove block from the cache */
 
243
  /*
 
244
    As my_disable_flush_pagecache_blocks is always 0, the following option
 
245
    is strictly equivalent to FLUSH_KEEP
 
246
  */
 
247
  FLUSH_FORCE_WRITE
 
248
};
 
249
 
234
250
typedef struct st_record_cache  /* Used when cacheing records */
235
251
{
236
252
  File file;
237
253
  int   rc_seek,error,inited;
238
254
  uint  rc_length,read_length,reclength;
239
255
  my_off_t rc_record_pos,end_of_file;
240
 
  unsigned char *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos;
 
256
  uchar *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos;
241
257
#ifdef HAVE_AIOWAIT
242
258
  int   use_async_io;
243
259
  my_aio_result aio_result;
264
280
 
265
281
typedef struct st_dynamic_array
266
282
{
267
 
  unsigned char *buffer;
268
 
  uint32_t elements,max_element;
269
 
  uint32_t alloc_increment;
270
 
  uint32_t size_of_element;
 
283
  uchar *buffer;
 
284
  uint elements,max_element;
 
285
  uint alloc_increment;
 
286
  uint size_of_element;
271
287
} DYNAMIC_ARRAY;
272
288
 
273
289
typedef struct st_my_tmpdir
274
290
{
275
291
  DYNAMIC_ARRAY full_list;
276
292
  char **list;
277
 
  uint32_t cur, max;
 
293
  uint cur, max;
278
294
  pthread_mutex_t mutex;
279
295
} MY_TMPDIR;
280
296
 
 
297
typedef struct st_dynamic_string
 
298
{
 
299
  char *str;
 
300
  size_t length,max_length,alloc_increment;
 
301
} DYNAMIC_STRING;
 
302
 
 
303
struct st_io_cache;
 
304
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
 
305
 
 
306
typedef struct st_io_cache_share
 
307
{
 
308
  pthread_mutex_t       mutex;           /* To sync on reads into buffer. */
 
309
  pthread_cond_t        cond;            /* To wait for signals. */
 
310
  pthread_cond_t        cond_writer;     /* For a synchronized writer. */
 
311
  /* Offset in file corresponding to the first byte of buffer. */
 
312
  my_off_t              pos_in_file;
 
313
  /* If a synchronized write cache is the source of the data. */
 
314
  struct st_io_cache    *source_cache;
 
315
  uchar                 *buffer;         /* The read buffer. */
 
316
  uchar                 *read_end;       /* Behind last valid byte of buffer. */
 
317
  int                   running_threads; /* threads not in lock. */
 
318
  int                   total_threads;   /* threads sharing the cache. */
 
319
  int                   error;           /* Last error. */
 
320
#ifdef NOT_YET_IMPLEMENTED
 
321
  /* whether the structure should be free'd */
 
322
  my_bool alloced;
 
323
#endif
 
324
} IO_CACHE_SHARE;
 
325
 
 
326
typedef struct st_io_cache              /* Used when cacheing files */
 
327
{
 
328
  /* Offset in file corresponding to the first byte of uchar* buffer. */
 
329
  my_off_t pos_in_file;
 
330
  /*
 
331
    The offset of end of file for READ_CACHE and WRITE_CACHE.
 
332
    For SEQ_READ_APPEND it the maximum of the actual end of file and
 
333
    the position represented by read_end.
 
334
  */
 
335
  my_off_t end_of_file;
 
336
  /* Points to current read position in the buffer */
 
337
  uchar *read_pos;
 
338
  /* the non-inclusive boundary in the buffer for the currently valid read */
 
339
  uchar  *read_end;
 
340
  uchar  *buffer;                               /* The read buffer */
 
341
  /* Used in ASYNC_IO */
 
342
  uchar  *request_pos;
 
343
 
 
344
  /* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
 
345
  uchar  *write_buffer;
 
346
  /*
 
347
    Only used in SEQ_READ_APPEND, and points to the current read position
 
348
    in the write buffer. Note that reads in SEQ_READ_APPEND caches can
 
349
    happen from both read buffer (uchar* buffer) and write buffer
 
350
    (uchar* write_buffer).
 
351
  */
 
352
  uchar *append_read_pos;
 
353
  /* Points to current write position in the write buffer */
 
354
  uchar *write_pos;
 
355
  /* The non-inclusive boundary of the valid write area */
 
356
  uchar *write_end;
 
357
 
 
358
  /*
 
359
    Current_pos and current_end are convenience variables used by
 
360
    my_b_tell() and other routines that need to know the current offset
 
361
    current_pos points to &write_pos, and current_end to &write_end in a
 
362
    WRITE_CACHE, and &read_pos and &read_end respectively otherwise
 
363
  */
 
364
  uchar  **current_pos, **current_end;
 
365
  /*
 
366
    The lock is for append buffer used in SEQ_READ_APPEND cache
 
367
    need mutex copying from append buffer to read buffer.
 
368
  */
 
369
  pthread_mutex_t append_buffer_lock;
 
370
  /*
 
371
    The following is used when several threads are reading the
 
372
    same file in parallel. They are synchronized on disk
 
373
    accesses reading the cached part of the file asynchronously.
 
374
    It should be set to NULL to disable the feature.  Only
 
375
    READ_CACHE mode is supported.
 
376
  */
 
377
  IO_CACHE_SHARE *share;
 
378
  /*
 
379
    A caller will use my_b_read() macro to read from the cache
 
380
    if the data is already in cache, it will be simply copied with
 
381
    memcpy() and internal variables will be accordinging updated with
 
382
    no functions invoked. However, if the data is not fully in the cache,
 
383
    my_b_read() will call read_function to fetch the data. read_function
 
384
    must never be invoked directly.
 
385
  */
 
386
  int (*read_function)(struct st_io_cache *,uchar *,size_t);
 
387
  /*
 
388
    Same idea as in the case of read_function, except my_b_write() needs to
 
389
    be replaced with my_b_append() for a SEQ_READ_APPEND cache
 
390
  */
 
391
  int (*write_function)(struct st_io_cache *,const uchar *,size_t);
 
392
  /*
 
393
    Specifies the type of the cache. Depending on the type of the cache
 
394
    certain operations might not be available and yield unpredicatable
 
395
    results. Details to be documented later
 
396
  */
 
397
  enum cache_type type;
 
398
  /*
 
399
    Callbacks when the actual read I/O happens. These were added and
 
400
    are currently used for binary logging of LOAD DATA INFILE - when a
 
401
    block is read from the file, we create a block create/append event, and
 
402
    when IO_CACHE is closed, we create an end event. These functions could,
 
403
    of course be used for other things
 
404
  */
 
405
  IO_CACHE_CALLBACK pre_read;
 
406
  IO_CACHE_CALLBACK post_read;
 
407
  IO_CACHE_CALLBACK pre_close;
 
408
  /*
 
409
    Counts the number of times, when we were forced to use disk. We use it to
 
410
    increase the binlog_cache_disk_use status variable.
 
411
  */
 
412
  ulong disk_writes;
 
413
  void* arg;                            /* for use by pre/post_read */
 
414
  char *file_name;                      /* if used with 'open_cached_file' */
 
415
  char *dir,*prefix;
 
416
  File file; /* file descriptor */
 
417
  /*
 
418
    seek_not_done is set by my_b_seek() to inform the upcoming read/write
 
419
    operation that a seek needs to be preformed prior to the actual I/O
 
420
    error is 0 if the cache operation was successful, -1 if there was a
 
421
    "hard" error, and the actual number of I/O-ed bytes if the read/write was
 
422
    partial.
 
423
  */
 
424
  int   seek_not_done,error;
 
425
  /* buffer_length is memory size allocated for buffer or write_buffer */
 
426
  size_t        buffer_length;
 
427
  /* read_length is the same as buffer_length except when we use async io */
 
428
  size_t  read_length;
 
429
  myf   myflags;                        /* Flags used to my_read/my_write */
 
430
  /*
 
431
    alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
 
432
    0 if it was supplied by the user.
 
433
    Currently READ_NET is the only one that will use a buffer allocated
 
434
    somewhere else
 
435
  */
 
436
  my_bool alloced_buffer;
 
437
#ifdef HAVE_AIOWAIT
 
438
  /*
 
439
    As inidicated by ifdef, this is for async I/O, which is not currently
 
440
    used (because it's not reliable on all systems)
 
441
  */
 
442
  uint inited;
 
443
  my_off_t aio_read_pos;
 
444
  my_aio_result aio_result;
 
445
#endif
 
446
} IO_CACHE;
281
447
 
282
448
typedef int (*qsort2_cmp)(const void *, const void *, const void *);
283
449
 
302
468
 
303
469
#define my_b_get(info) \
304
470
  ((info)->read_pos != (info)->read_end ?\
305
 
   ((info)->read_pos++, (int) (unsigned char) (info)->read_pos[-1]) :\
 
471
   ((info)->read_pos++, (int) (uchar) (info)->read_pos[-1]) :\
306
472
   _my_b_get(info))
307
473
 
308
474
        /* my_b_write_byte dosn't have any err-check */
322
488
  (char*) my_b_get_buffer_start(info)
323
489
#define my_b_get_pos_in_file(info) (info)->pos_in_file
324
490
 
 
491
/* tell write offset in the SEQ_APPEND cache */
 
492
int      my_b_copy_to_file(IO_CACHE *cache, FILE *file);
 
493
my_off_t my_b_append_tell(IO_CACHE* info);
 
494
my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
325
495
 
326
496
#define my_b_bytes_in_cache(info) (size_t) (*(info)->current_end - \
327
497
                                          *(info)->current_pos)
328
498
 
329
 
typedef uint32_t ha_checksum;
 
499
typedef uint32 ha_checksum;
330
500
 
331
501
/* Define the type of function to be passed to process_default_option_files */
332
502
typedef int (*Process_option_func)(void *ctx, const char *group_name,
333
503
                                   const char *option);
334
504
 
335
 
#include <mysys/my_alloc.h>
 
505
#include <my_alloc.h>
336
506
 
337
507
 
338
508
        /* Prototypes for mysys and my_func functions */
339
509
 
340
510
extern int my_copy(const char *from,const char *to,myf MyFlags);
 
511
extern int my_append(const char *from,const char *to,myf MyFlags);
341
512
extern int my_delete(const char *name,myf MyFlags);
342
513
extern int my_getwd(char * buf,size_t size,myf MyFlags);
343
514
extern int my_setwd(const char *dir,myf MyFlags);
 
515
extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags);
344
516
extern void *my_once_alloc(size_t Size,myf MyFlags);
345
517
extern void my_once_free(void);
346
518
extern char *my_once_strdup(const char *src,myf myflags);
348
520
extern File my_open(const char *FileName,int Flags,myf MyFlags);
349
521
extern File my_register_filename(File fd, const char *FileName,
350
522
                                 enum file_type type_of_file,
351
 
                                 uint32_t error_message_number, myf MyFlags);
 
523
                                 uint error_message_number, myf MyFlags);
352
524
extern File my_create(const char *FileName,int CreateFlags,
353
525
                      int AccessFlags, myf MyFlags);
354
526
extern int my_close(File Filedes,myf MyFlags);
362
534
extern int my_delete_with_symlink(const char *name, myf MyFlags);
363
535
extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags);
364
536
extern int my_symlink(const char *content, const char *linkname, myf MyFlags);
365
 
extern size_t my_read(File Filedes,unsigned char *Buffer,size_t Count,myf MyFlags);
 
537
extern size_t my_read(File Filedes,uchar *Buffer,size_t Count,myf MyFlags);
366
538
extern int my_rename(const char *from,const char *to,myf MyFlags);
367
539
extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags);
368
540
extern my_off_t my_tell(File fd,myf MyFlags);
369
 
extern size_t my_write(File Filedes,const unsigned char *Buffer,size_t Count,
 
541
extern size_t my_write(File Filedes,const uchar *Buffer,size_t Count,
370
542
                     myf MyFlags);
371
 
extern size_t my_fwrite(FILE *stream,const unsigned char *Buffer,size_t Count,
 
543
extern size_t my_fread(FILE *stream,uchar *Buffer,size_t Count,myf MyFlags);
 
544
extern size_t my_fwrite(FILE *stream,const uchar *Buffer,size_t Count,
372
545
                      myf MyFlags);
373
546
extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags);
 
547
extern my_off_t my_ftell(FILE *stream,myf MyFlags);
374
548
extern void *_mymalloc(size_t uSize,const char *sFile,
375
 
                       uint32_t uLine, myf MyFlag);
 
549
                       uint uLine, myf MyFlag);
376
550
extern void *_myrealloc(void *pPtr,size_t uSize,const char *sFile,
377
 
                       uint32_t uLine, myf MyFlag);
378
 
extern void * my_multi_malloc (myf MyFlags, ...);
379
 
extern void _myfree(void *pPtr, const char *sFile, uint32_t uLine, myf MyFlag);
380
 
extern int _sanity(const char *sFile, uint32_t uLine);
 
551
                       uint uLine, myf MyFlag);
 
552
extern void * my_multi_malloc _VARARGS((myf MyFlags, ...));
 
553
extern void _myfree(void *pPtr,const char *sFile,uint uLine, myf MyFlag);
 
554
extern int _sanity(const char *sFile, uint uLine);
381
555
extern void *_my_memdup(const void *from, size_t length,
382
 
                        const char *sFile, uint32_t uLine,myf MyFlag);
383
 
extern char * _my_strdup(const char *from, const char *sFile, uint32_t uLine,
 
556
                        const char *sFile, uint uLine,myf MyFlag);
 
557
extern char * _my_strdup(const char *from, const char *sFile, uint uLine,
384
558
                         myf MyFlag);
385
559
extern char *_my_strndup(const char *from, size_t length,
386
 
                         const char *sFile, uint32_t uLine,
 
560
                         const char *sFile, uint uLine,
387
561
                         myf MyFlag);
388
562
 
 
563
/* implemented in my_memmem.c */
 
564
extern void *my_memmem(const void *haystack, size_t haystacklen,
 
565
                       const void *needle, size_t needlelen);
 
566
 
 
567
 
389
568
#define my_access access
390
569
extern int check_if_legal_filename(const char *path);
391
570
extern int check_if_legal_tablename(const char *path);
393
572
#define my_delete_allow_opened(fname,flags)  my_delete((fname),(flags))
394
573
 
395
574
#ifndef TERMINATE
396
 
extern void TERMINATE(FILE *file, uint32_t flag);
 
575
extern void TERMINATE(FILE *file, uint flag);
397
576
#endif
398
577
extern void init_glob_errs(void);
399
578
extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
 
579
extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
400
580
extern int my_fclose(FILE *fd,myf MyFlags);
401
581
extern int my_sync(File fd, myf my_flags);
402
582
extern int my_sync_dir(const char *dir_name, myf my_flags);
403
583
extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
404
 
extern void my_error(int nr,myf MyFlags, ...);
405
 
extern void my_printf_error(uint32_t my_err, const char *format,
406
 
                            myf MyFlags, ...)
407
 
  __attribute__((format(printf, 2, 4)));
 
584
extern void my_error _VARARGS((int nr,myf MyFlags, ...));
 
585
extern void my_printf_error _VARARGS((uint my_err, const char *format,
 
586
                                      myf MyFlags, ...))
 
587
                                      ATTRIBUTE_FORMAT(printf, 2, 4);
408
588
extern int my_error_register(const char **errmsgs, int first, int last);
409
589
extern const char **my_error_unregister(int first, int last);
410
 
extern void my_message(uint32_t my_err, const char *str,myf MyFlags);
411
 
extern void my_message_no_curses(uint32_t my_err, const char *str,myf MyFlags);
412
 
extern bool my_init(void);
 
590
extern void my_message(uint my_err, const char *str,myf MyFlags);
 
591
extern void my_message_no_curses(uint my_err, const char *str,myf MyFlags);
 
592
extern my_bool my_init(void);
413
593
extern void my_end(int infoflag);
414
594
extern int my_redel(const char *from, const char *to, int MyFlags);
415
595
extern int my_copystat(const char *from, const char *to, int MyFlags);
421
601
#define my_print_open_files()
422
602
#endif
423
603
 
424
 
extern bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist);
 
604
extern my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist);
425
605
extern char *my_tmpdir(MY_TMPDIR *tmpdir);
426
606
extern void free_tmpdir(MY_TMPDIR *tmpdir);
427
607
 
428
 
extern void my_remember_signal(int signal_number,RETSIGTYPE (*func)(int));
 
608
extern void my_remember_signal(int signal_number,sig_handler (*func)(int));
429
609
extern size_t dirname_part(char * to,const char *name, size_t *to_res_length);
430
610
extern size_t dirname_length(const char *name);
431
611
#define base_name(A) (A+dirname_length(A))
432
612
extern int test_if_hard_path(const char *dir_name);
433
 
extern bool has_path(const char *name);
 
613
extern my_bool has_path(const char *name);
434
614
extern char *convert_dirname(char *to, const char *from, const char *from_end);
435
615
extern void to_unix_path(char * name);
436
616
extern char * fn_ext(const char *name);
437
617
extern char * fn_same(char * toname,const char *name,int flag);
438
618
extern char * fn_format(char * to,const char *name,const char *dir,
439
 
                           const char *form, uint32_t flag);
 
619
                           const char *form, uint flag);
440
620
extern size_t strlength(const char *str);
441
621
extern void pack_dirname(char * to,const char *from);
442
622
extern size_t unpack_dirname(char * to,const char *from);
451
631
extern char * my_load_path(char * to, const char *path,
452
632
                              const char *own_path_prefix);
453
633
extern int wild_compare(const char *str,const char *wildstr,
454
 
                        bool str_is_pattern);
 
634
                        pbool str_is_pattern);
455
635
extern WF_PACK *wf_comp(char * str);
456
636
extern int wf_test(struct wild_file_pack *wf_pack,const char *name);
457
637
extern void wf_end(struct wild_file_pack *buffer);
458
 
extern bool array_append_string_unique(const char *str,
 
638
extern size_t strip_sp(char * str);
 
639
extern my_bool array_append_string_unique(const char *str,
459
640
                                          const char **array, size_t size);
460
641
extern void get_date(char * to,int timeflag,time_t use_time);
461
642
extern void soundex(CHARSET_INFO *, char * out_pntr, char * in_pntr,
462
 
                    bool remove_garbage);
 
643
                    pbool remove_garbage);
463
644
extern int init_record_cache(RECORD_CACHE *info,size_t cachesize,File file,
464
645
                             size_t reclength,enum cache_type type,
465
 
                             bool use_async_io);
466
 
extern int read_cache_record(RECORD_CACHE *info,unsigned char *to);
 
646
                             pbool use_async_io);
 
647
extern int read_cache_record(RECORD_CACHE *info,uchar *to);
467
648
extern int end_record_cache(RECORD_CACHE *info);
468
649
extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos,
469
 
                              const unsigned char *record,size_t length);
 
650
                              const uchar *record,size_t length);
470
651
extern int flush_write_cache(RECORD_CACHE *info);
471
 
extern RETSIGTYPE sigtstp_handler(int signal_number);
 
652
extern long my_clock(void);
 
653
extern sig_handler sigtstp_handler(int signal_number);
472
654
extern void handle_recived_signals(void);
473
655
 
474
 
extern RETSIGTYPE my_set_alarm_variable(int signo);
475
 
extern void my_string_ptr_sort(unsigned char *base,uint32_t items,size_t size);
476
 
extern void radixsort_for_str_ptr(unsigned char* base[], uint32_t number_of_elements,
477
 
                                  size_t size_of_element,unsigned char *buffer[]);
478
 
extern RETQSORTTYPE my_qsort(void *base_ptr, size_t total_elems, size_t size,
479
 
                             qsort_cmp cmp);
480
 
extern RETQSORTTYPE my_qsort2(void *base_ptr, size_t total_elems, size_t size,
481
 
                              qsort2_cmp cmp, void *cmp_argument);
 
656
extern sig_handler my_set_alarm_variable(int signo);
 
657
extern void my_string_ptr_sort(uchar *base,uint items,size_t size);
 
658
extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
 
659
                                  size_t size_of_element,uchar *buffer[]);
 
660
extern qsort_t my_qsort(void *base_ptr, size_t total_elems, size_t size,
 
661
                        qsort_cmp cmp);
 
662
extern qsort_t my_qsort2(void *base_ptr, size_t total_elems, size_t size,
 
663
                         qsort2_cmp cmp, void *cmp_argument);
482
664
extern qsort2_cmp get_ptr_compare(size_t);
483
 
void my_store_ptr(unsigned char *buff, size_t pack_length, my_off_t pos);
484
 
my_off_t my_get_ptr(unsigned char *ptr, size_t pack_length);
 
665
void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos);
 
666
my_off_t my_get_ptr(uchar *ptr, size_t pack_length);
 
667
extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
 
668
                         enum cache_type type,my_off_t seek_offset,
 
669
                         pbool use_async_io, myf cache_myflags);
 
670
extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
 
671
                               my_off_t seek_offset,pbool use_async_io,
 
672
                               pbool clear_cache);
 
673
extern void setup_io_cache(IO_CACHE* info);
 
674
extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count);
 
675
extern int _my_b_read_r(IO_CACHE *info,uchar *Buffer,size_t Count);
 
676
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
 
677
                                IO_CACHE *write_cache, uint num_threads);
 
678
extern void remove_io_thread(IO_CACHE *info);
 
679
extern int _my_b_seq_read(IO_CACHE *info,uchar *Buffer,size_t Count);
 
680
extern int _my_b_net_read(IO_CACHE *info,uchar *Buffer,size_t Count);
 
681
extern int _my_b_get(IO_CACHE *info);
 
682
extern int _my_b_async_read(IO_CACHE *info,uchar *Buffer,size_t Count);
 
683
extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
 
684
extern int my_b_append(IO_CACHE *info,const uchar *Buffer,size_t Count);
 
685
extern int my_b_safe_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
 
686
 
 
687
extern int my_block_write(IO_CACHE *info, const uchar *Buffer,
 
688
                          size_t Count, my_off_t pos);
 
689
extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
 
690
 
 
691
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
 
692
 
 
693
extern int end_io_cache(IO_CACHE *info);
 
694
extern size_t my_b_fill(IO_CACHE *info);
 
695
extern void my_b_seek(IO_CACHE *info,my_off_t pos);
 
696
extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
 
697
extern my_off_t my_b_filelength(IO_CACHE *info);
 
698
extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...);
 
699
extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
 
700
extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
 
701
                                 const char *prefix, size_t cache_size,
 
702
                                 myf cache_myflags);
 
703
extern my_bool real_open_cached_file(IO_CACHE *cache);
 
704
extern void close_cached_file(IO_CACHE *cache);
485
705
File create_temp_file(char *to, const char *dir, const char *pfx,
486
706
                      int mode, myf MyFlags);
487
707
#define my_init_dynamic_array(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D CALLER_INFO)
488
708
#define my_init_dynamic_array_ci(A,B,C,D) init_dynamic_array2(A,B,NULL,C,D ORIG_CALLER_INFO)
489
709
#define my_init_dynamic_array2(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E CALLER_INFO)
490
710
#define my_init_dynamic_array2_ci(A,B,C,D,E) init_dynamic_array2(A,B,C,D,E ORIG_CALLER_INFO)
491
 
extern bool init_dynamic_array2(DYNAMIC_ARRAY *array,uint32_t element_size,
492
 
                                   void *init_buffer, uint32_t init_alloc, 
493
 
                                   uint32_t alloc_increment
 
711
extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array,uint element_size,
 
712
                                   void *init_buffer, uint init_alloc, 
 
713
                                   uint alloc_increment
494
714
                                   CALLER_INFO_PROTO);
495
715
/* init_dynamic_array() function is deprecated */
496
 
extern bool init_dynamic_array(DYNAMIC_ARRAY *array,uint32_t element_size,
497
 
                                  uint32_t init_alloc,uint32_t alloc_increment
 
716
extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size,
 
717
                                  uint init_alloc,uint alloc_increment
498
718
                                  CALLER_INFO_PROTO);
499
 
extern bool insert_dynamic(DYNAMIC_ARRAY *array,unsigned char * element);
500
 
extern unsigned char *alloc_dynamic(DYNAMIC_ARRAY *array);
501
 
extern unsigned char *pop_dynamic(DYNAMIC_ARRAY*);
502
 
extern bool set_dynamic(DYNAMIC_ARRAY *array,unsigned char * element,uint32_t array_index);
503
 
extern bool allocate_dynamic(DYNAMIC_ARRAY *array, uint32_t max_elements);
504
 
extern void get_dynamic(DYNAMIC_ARRAY *array,unsigned char * element,uint32_t array_index);
 
719
extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,uchar * element);
 
720
extern uchar *alloc_dynamic(DYNAMIC_ARRAY *array);
 
721
extern uchar *pop_dynamic(DYNAMIC_ARRAY*);
 
722
extern my_bool set_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
 
723
extern my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements);
 
724
extern void get_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
505
725
extern void delete_dynamic(DYNAMIC_ARRAY *array);
506
 
extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint32_t array_index);
 
726
extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index);
507
727
extern void freeze_size(DYNAMIC_ARRAY *array);
508
 
extern int  get_index_dynamic(DYNAMIC_ARRAY *array, unsigned char * element);
 
728
extern int  get_index_dynamic(DYNAMIC_ARRAY *array, uchar * element);
509
729
#define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element)
510
730
#define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index))
511
731
#define push_dynamic(A,B) insert_dynamic((A),(B))
512
732
#define reset_dynamic(array) ((array)->elements= 0)
513
733
#define sort_dynamic(A,cmp) my_qsort((A)->buffer, (A)->elements, (A)->size_of_element, (cmp))
514
734
 
 
735
extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
 
736
                                   size_t init_alloc,size_t alloc_increment);
 
737
extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append);
 
738
my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
 
739
                          size_t length);
 
740
extern my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append,
 
741
                                       ...);
 
742
extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str);
 
743
extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size);
 
744
extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n);
 
745
extern void dynstr_free(DYNAMIC_STRING *str);
 
746
#ifdef HAVE_MLOCK
 
747
extern void *my_malloc_lock(size_t length,myf flags);
 
748
extern void my_free_lock(void *ptr,myf flags);
 
749
#else
515
750
#define my_malloc_lock(A,B) my_malloc((A),(B))
 
751
#define my_free_lock(A,B) my_free((A),(B))
 
752
#endif
516
753
#define alloc_root_inited(A) ((A)->min_malloc != 0)
517
754
#define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
518
755
#define clear_alloc_root(A) do { (A)->free= (A)->used= (A)->pre_alloc= 0; (A)->min_malloc=0;} while(0)
 
756
extern void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
 
757
                            size_t pre_alloc_size);
 
758
extern void *alloc_root(MEM_ROOT *mem_root, size_t Size);
 
759
extern void *multi_alloc_root(MEM_ROOT *mem_root, ...);
 
760
extern void free_root(MEM_ROOT *root, myf MyFLAGS);
 
761
extern void set_prealloc_root(MEM_ROOT *root, char *ptr);
 
762
extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
 
763
                                size_t prealloc_size);
 
764
extern char *strdup_root(MEM_ROOT *root,const char *str);
 
765
extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
 
766
extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
519
767
extern int get_defaults_options(int argc, char **argv,
520
768
                                char **defaults, char **extra_defaults,
521
769
                                char **group_suffix);
525
773
                                const char *option_value,
526
774
                                const char *section_name, int remove_option);
527
775
extern int my_search_option_files(const char *conf_file, int *argc,
528
 
                                  char ***argv, uint32_t *args_used,
 
776
                                  char ***argv, uint *args_used,
529
777
                                  Process_option_func func, void *func_ctx);
530
778
extern void free_defaults(char **argv);
531
779
extern void my_print_default_files(const char *conf_file);
532
780
extern void print_defaults(const char *conf_file, const char **groups);
533
 
extern ha_checksum my_checksum(ha_checksum crc, const unsigned char *mem,
 
781
extern my_bool my_compress(uchar *, size_t *, size_t *);
 
782
extern my_bool my_uncompress(uchar *, size_t , size_t *);
 
783
extern uchar *my_compress_alloc(const uchar *packet, size_t *len,
 
784
                                size_t *complen);
 
785
extern ha_checksum my_checksum(ha_checksum crc, const uchar *mem,
534
786
                               size_t count);
535
 
extern void my_sleep(uint32_t m_seconds);
536
 
extern uint32_t my_set_max_open_files(uint32_t files);
 
787
extern void my_sleep(ulong m_seconds);
 
788
extern ulong crc32(ulong crc, const uchar *buf, uint len);
 
789
extern uint my_set_max_open_files(uint files);
537
790
void my_free_open_file_info(void);
538
791
 
539
792
extern time_t my_time(myf flags);
540
 
extern uint64_t my_getsystime(void);
541
 
extern uint64_t my_micro_time(void);
542
 
extern uint64_t my_micro_time_and_time(time_t *time_arg);
543
 
time_t my_time_possible_from_micro(uint64_t microtime);
544
 
extern bool my_gethwaddr(unsigned char *to);
 
793
extern ulonglong my_getsystime(void);
 
794
extern ulonglong my_micro_time(void);
 
795
extern ulonglong my_micro_time_and_time(time_t *time_arg);
 
796
time_t my_time_possible_from_micro(ulonglong microtime);
 
797
extern my_bool my_gethwaddr(uchar *to);
 
798
extern int my_getncpus(void);
545
799
 
546
800
#ifdef HAVE_SYS_MMAN_H
547
801
#include <sys/mman.h>
570
824
#define MAP_NOSYNC       0x0800
571
825
#define MAP_FAILED       ((void *)-1)
572
826
#define MS_SYNC          0x0000
 
827
 
 
828
#ifndef __NETWARE__
573
829
#define HAVE_MMAP
 
830
#endif
574
831
 
575
832
void *my_mmap(void *, size_t, int, int, int, my_off_t);
576
833
int my_munmap(void *, size_t);
577
834
#endif
578
835
 
 
836
/* my_getpagesize */
 
837
#ifdef HAVE_GETPAGESIZE
 
838
#define my_getpagesize()        getpagesize()
 
839
#else
 
840
int my_getpagesize(void);
 
841
#endif
 
842
 
579
843
/* character sets */
580
 
extern uint32_t get_charset_number(const char *cs_name, uint32_t cs_flags);
581
 
extern uint32_t get_collation_number(const char *name);
582
 
extern const char *get_charset_name(uint32_t cs_number);
583
 
 
584
 
extern const CHARSET_INFO *get_charset(uint32_t cs_number, myf flags);
585
 
extern const CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags);
586
 
extern const CHARSET_INFO *get_charset_by_csname(const char *cs_name, uint32_t cs_flags, myf my_flags);
587
 
 
588
 
extern bool resolve_charset(const char *cs_name,
589
 
                            const CHARSET_INFO *default_cs,
590
 
                            const CHARSET_INFO **cs);
591
 
extern bool resolve_collation(const char *cl_name,
592
 
                             const CHARSET_INFO *default_cl,
593
 
                             const CHARSET_INFO **cl);
 
844
extern uint get_charset_number(const char *cs_name, uint cs_flags);
 
845
extern uint get_collation_number(const char *name);
 
846
extern const char *get_charset_name(uint cs_number);
 
847
 
 
848
extern CHARSET_INFO *get_charset(uint cs_number, myf flags);
 
849
extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags);
 
850
extern CHARSET_INFO *get_charset_by_csname(const char *cs_name,
 
851
                                           uint cs_flags, myf my_flags);
 
852
 
 
853
extern my_bool resolve_charset(const char *cs_name,
 
854
                               CHARSET_INFO *default_cs,
 
855
                               CHARSET_INFO **cs);
 
856
extern my_bool resolve_collation(const char *cl_name,
 
857
                                 CHARSET_INFO *default_cl,
 
858
                                 CHARSET_INFO **cl);
594
859
 
595
860
extern void free_charsets(void);
596
861
extern char *get_charsets_dir(char *buf);
597
 
extern bool my_charset_same(const CHARSET_INFO *cs1, const CHARSET_INFO *cs2);
598
 
extern bool init_compiled_charsets(myf flags);
 
862
extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2);
 
863
extern my_bool init_compiled_charsets(myf flags);
599
864
extern void add_compiled_collation(CHARSET_INFO *cs);
600
 
extern size_t escape_string_for_drizzle(const CHARSET_INFO *charset_info,
601
 
                                        char *to, size_t to_length,
602
 
                                        const char *from, size_t length);
603
 
extern size_t escape_quotes_for_drizzle(const CHARSET_INFO *charset_info,
604
 
                                        char *to, size_t to_length,
605
 
                                        const char *from, size_t length);
606
 
 
607
 
extern void thd_increment_bytes_sent(uint32_t length);
608
 
extern void thd_increment_bytes_received(uint32_t length);
609
 
extern void thd_increment_net_big_packet_count(uint32_t length);
610
 
 
611
 
#ifdef __cplusplus
612
 
}
613
 
#endif
614
 
 
 
865
extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info,
 
866
                                      char *to, size_t to_length,
 
867
                                      const char *from, size_t length);
 
868
extern size_t escape_quotes_for_mysql(CHARSET_INFO *charset_info,
 
869
                                      char *to, size_t to_length,
 
870
                                      const char *from, size_t length);
 
871
 
 
872
extern void thd_increment_bytes_sent(ulong length);
 
873
extern void thd_increment_bytes_received(ulong length);
 
874
extern void thd_increment_net_big_packet_count(ulong length);
 
875
 
 
876
C_MODE_END
615
877
#endif /* _my_sys_h */