~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/my_sys.h

  • Committer: Brian Aker
  • Date: 2008-07-20 05:41:52 UTC
  • Revision ID: brian@tangent.org-20080720054152-5laf6plsb0o7h6ss
Documentation cleanup

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