9
3

my_sys.h 40 KB

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