~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_sys.h

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

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