home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / mySQL / mysql-5.0.1-alpha-snapshot-win / data1.cab / Development / include / my_sys.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-07-28  |  30.8 KB  |  788 lines

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