my_sys.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. /* Copyright (c) 2000, 2013, Oracle and/or its affiliates.
  2. Copyright (c) 2010, 2016, Monty Program Ab.
  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. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
  13. #ifndef _my_sys_h
  14. #define _my_sys_h
  15. #include "my_global.h" /* C_MODE_START, C_MODE_END */
  16. #include <m_string.h>
  17. C_MODE_START
  18. #ifdef HAVE_AIOWAIT
  19. #include <sys/asynch.h> /* Used by record-cache */
  20. typedef struct my_aio_result {
  21. aio_result_t result;
  22. int pending;
  23. } my_aio_result;
  24. #endif
  25. #include <my_valgrind.h>
  26. #include <my_pthread.h>
  27. #include <m_ctype.h> /* for CHARSET_INFO */
  28. #include <stdarg.h>
  29. #include <typelib.h>
  30. #ifdef _WIN32
  31. #include <malloc.h> /*for alloca*/
  32. #endif
  33. #include <mysql/plugin.h>
  34. #define MY_INIT(name) { my_progname= name; my_init(); }
  35. /**
  36. Max length of an error message generated by mysys utilities.
  37. Some mysys functions produce error messages. These mostly go
  38. to stderr.
  39. This constant defines the size of the buffer used to format
  40. the message. It should be kept in sync with MYSQL_ERRMSG_SIZE,
  41. since sometimes mysys errors are stored in the server diagnostics
  42. area, and we would like to avoid unexpected truncation.
  43. */
  44. #define MYSYS_ERRMSG_SIZE (512)
  45. #define MYSYS_STRERROR_SIZE (128)
  46. #define MY_FILE_ERROR ((size_t) -1)
  47. /* General bitmaps for my_func's */
  48. #define MY_FFNF 1 /* Fatal if file not found */
  49. #define MY_FNABP 2 /* Fatal if not all bytes read/writen */
  50. #define MY_NABP 4 /* Error if not all bytes read/writen */
  51. #define MY_FAE 8 /* Fatal if any error */
  52. #define MY_WME 16 /* Write message on error */
  53. #define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */
  54. #define MY_IGNORE_BADFD 32 /* my_sync: ignore 'bad descriptor' errors */
  55. #define MY_ENCRYPT 64 /* Encrypt IO_CACHE temporary files */
  56. #define MY_FULL_IO 512 /* For my_read - loop intil I/O is complete */
  57. #define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
  58. #define MY_LINK_WARNING 32 /* my_redel() gives warning if links */
  59. #define MY_COPYTIME 64 /* my_redel() copys time */
  60. #define MY_DELETE_OLD 256 /* my_create_with_symlink() */
  61. #define MY_RESOLVE_LINK 128 /* my_realpath(); Only resolve links */
  62. #define MY_HOLD_ORIGINAL_MODES 128 /* my_copy() holds to file modes */
  63. #define MY_REDEL_MAKE_BACKUP 256
  64. #define MY_SEEK_NOT_DONE 32 /* my_lock may have to do a seek */
  65. #define MY_SHORT_WAIT 64 /* my_lock() don't wait if can't lock */
  66. #define MY_FORCE_LOCK 128 /* use my_lock() even if disable_locking */
  67. #define MY_NO_WAIT 256 /* my_lock() don't wait at all */
  68. /*
  69. init_dynamic_array() has init buffer; Internal flag, not to be used by
  70. caller.
  71. */
  72. #define MY_INIT_BUFFER_USED 256
  73. #define MY_ZEROFILL 32 /* my_malloc(), fill array with zero */
  74. #define MY_ALLOW_ZERO_PTR 64 /* my_realloc() ; zero ptr -> malloc */
  75. #define MY_FREE_ON_ERROR 128 /* my_realloc() ; Free old ptr on error */
  76. #define MY_HOLD_ON_ERROR 256 /* my_realloc() ; Return old ptr on error */
  77. #define MY_DONT_OVERWRITE_FILE 2048 /* my_copy: Don't overwrite file */
  78. #define MY_THREADSAFE 2048 /* my_seek(): lock fd mutex */
  79. #define MY_SYNC 4096 /* my_copy(): sync dst file */
  80. #define MY_SYNC_DIR 32768 /* my_create/delete/rename: sync directory */
  81. #define MY_SYNC_FILESIZE 65536 /* my_sync(): safe sync when file is extended */
  82. #define MY_THREAD_SPECIFIC 0x10000 /* my_malloc(): thread specific */
  83. #define MY_THREAD_MOVE 0x20000 /* realloc(); Memory can move */
  84. /* Tree that should delete things automaticly */
  85. #define MY_TREE_WITH_DELETE 0x40000
  86. #define MY_CHECK_ERROR 1 /* Params to my_end; Check open-close */
  87. #define MY_GIVE_INFO 2 /* Give time info about process*/
  88. #define MY_DONT_FREE_DBUG 4 /* Do not call DBUG_END() in my_end() */
  89. #define ME_HIGHBYTE 8 /* Shift for colours */
  90. #define ME_NOCUR 1 /* Don't use curses message */
  91. #define ME_OLDWIN 2 /* Use old window */
  92. #define ME_BELL 4 /* Ring bell then printing message */
  93. #define ME_HOLDTANG 8 /* Don't delete last keys */
  94. #define ME_WAITTOT 16 /* Wait for errtime secs of for a action */
  95. #define ME_WAITTANG 32 /* Wait for a user action */
  96. #define ME_NOREFRESH 64 /* Write the error message to error log */
  97. #define ME_NOINPUT 128 /* Dont use the input libary */
  98. #define ME_COLOUR1 ((1 << ME_HIGHBYTE)) /* Possibly error-colours */
  99. #define ME_COLOUR2 ((2 << ME_HIGHBYTE))
  100. #define ME_COLOUR3 ((3 << ME_HIGHBYTE))
  101. #define ME_JUST_INFO 1024 /**< not error but just info */
  102. #define ME_JUST_WARNING 2048 /**< not error but just warning */
  103. #define ME_FATALERROR 4096 /* Fatal statement error */
  104. /* Bits in last argument to fn_format */
  105. #define MY_REPLACE_DIR 1 /* replace dir in name with 'dir' */
  106. #define MY_REPLACE_EXT 2 /* replace extension with 'ext' */
  107. #define MY_UNPACK_FILENAME 4 /* Unpack name (~ -> home) */
  108. #define MY_PACK_FILENAME 8 /* Pack name (home -> ~) */
  109. #define MY_RESOLVE_SYMLINKS 16 /* Resolve all symbolic links */
  110. #define MY_RETURN_REAL_PATH 32 /* return full path for file */
  111. #define MY_SAFE_PATH 64 /* Return NULL if too long path */
  112. #define MY_RELATIVE_PATH 128 /* name is relative to 'dir' */
  113. #define MY_APPEND_EXT 256 /* add 'ext' as additional extension*/
  114. /* My seek flags */
  115. #define MY_SEEK_SET 0
  116. #define MY_SEEK_CUR 1
  117. #define MY_SEEK_END 2
  118. /* Some constants */
  119. #define MY_WAIT_FOR_USER_TO_FIX_PANIC 60 /* in seconds */
  120. #define MY_WAIT_GIVE_USER_A_MESSAGE 10 /* Every 10 times of prev */
  121. #define MIN_COMPRESS_LENGTH 50 /* Don't compress small bl. */
  122. #define DFLT_INIT_HITS 3
  123. /* root_alloc flags */
  124. #define MY_KEEP_PREALLOC 1
  125. #define MY_MARK_BLOCKS_FREE 2 /* move used to free list and reuse them */
  126. /* Internal error numbers (for assembler functions) */
  127. #define MY_ERRNO_EDOM 33
  128. #define MY_ERRNO_ERANGE 34
  129. /* Bits for get_date timeflag */
  130. #define GETDATE_DATE_TIME 1
  131. #define GETDATE_SHORT_DATE 2
  132. #define GETDATE_HHMMSSTIME 4
  133. #define GETDATE_GMT 8
  134. #define GETDATE_FIXEDLENGTH 16
  135. /* Extra length needed for filename if one calls my_create_backup_name */
  136. #define MY_BACKUP_NAME_EXTRA_LENGTH 17
  137. /* If we have our own safemalloc (for debugging) */
  138. #if defined(SAFEMALLOC)
  139. void sf_report_leaked_memory(my_thread_id id);
  140. extern my_thread_id (*sf_malloc_dbug_id)(void);
  141. #define SAFEMALLOC_REPORT_MEMORY(X) sf_report_leaked_memory(X)
  142. #else
  143. #define SAFEMALLOC_REPORT_MEMORY(X) do {} while(0)
  144. #endif
  145. typedef void (*MALLOC_SIZE_CB) (long long size, my_bool is_thread_specific);
  146. extern void set_malloc_size_cb(MALLOC_SIZE_CB func);
  147. /* defines when allocating data */
  148. extern void *my_malloc(size_t Size,myf MyFlags);
  149. extern void *my_multi_malloc(myf MyFlags, ...);
  150. extern void *my_multi_malloc_large(myf MyFlags, ...);
  151. extern void *my_realloc(void *oldpoint, size_t Size, myf MyFlags);
  152. extern void my_free(void *ptr);
  153. extern void *my_memdup(const void *from,size_t length,myf MyFlags);
  154. extern char *my_strdup(const char *from,myf MyFlags);
  155. extern char *my_strndup(const char *from, size_t length, myf MyFlags);
  156. #ifdef HAVE_LARGE_PAGES
  157. extern uint my_get_large_page_size(void);
  158. extern uchar * my_large_malloc(size_t size, myf my_flags);
  159. extern void my_large_free(uchar *ptr);
  160. #else
  161. #define my_get_large_page_size() (0)
  162. #define my_large_malloc(A,B) my_malloc_lock((A),(B))
  163. #define my_large_free(A) my_free_lock((A))
  164. #endif /* HAVE_LARGE_PAGES */
  165. #if defined(HAVE_ALLOCA) && !defined(HAVE_valgrind)
  166. #if defined(_AIX) && !defined(__GNUC__) && !defined(_AIX43)
  167. #pragma alloca
  168. #endif /* _AIX */
  169. #if defined(__MWERKS__)
  170. #undef alloca
  171. #define alloca _alloca
  172. #endif /* __MWERKS__ */
  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) ((void)0)
  178. #define MAX_ALLOCA_SZ 4096
  179. #define my_safe_alloca(size) (((size) <= MAX_ALLOCA_SZ) ? \
  180. my_alloca(size) : \
  181. my_malloc((size), MYF(MY_THREAD_SPECIFIC|MY_WME)))
  182. #define my_safe_afree(ptr, size) \
  183. do { if ((size) > MAX_ALLOCA_SZ) my_free(ptr); } while(0)
  184. #else
  185. #define my_alloca(SZ) my_malloc(SZ,MYF(MY_FAE))
  186. #define my_afree(PTR) my_free(PTR)
  187. #define my_safe_alloca(size) my_alloca(size)
  188. #define my_safe_afree(ptr, size) my_afree(ptr)
  189. #endif /* HAVE_ALLOCA */
  190. #ifndef errno /* did we already get it? */
  191. #ifdef HAVE_ERRNO_AS_DEFINE
  192. #include <errno.h> /* errno is a define */
  193. #else
  194. extern int errno; /* declare errno */
  195. #endif
  196. #endif /* #ifndef errno */
  197. extern char *home_dir; /* Home directory for user */
  198. extern MYSQL_PLUGIN_IMPORT char *mysql_data_home;
  199. extern const char *my_progname; /* program-name (printed in errors) */
  200. extern const char *my_progname_short; /* like above but without directory */
  201. extern char curr_dir[]; /* Current directory for user */
  202. extern void (*error_handler_hook)(uint my_err, const char *str,myf MyFlags);
  203. extern void (*fatal_error_handler_hook)(uint my_err, const char *str,
  204. myf MyFlags);
  205. extern uint my_file_limit;
  206. extern ulonglong my_thread_stack_size;
  207. extern int sf_leaking_memory; /* set to 1 to disable memleak detection */
  208. extern void (*proc_info_hook)(void *, const PSI_stage_info *, PSI_stage_info *,
  209. const char *, const char *, const unsigned int);
  210. #ifdef HAVE_LARGE_PAGES
  211. extern my_bool my_use_large_pages;
  212. extern uint my_large_page_size;
  213. #endif
  214. /* charsets */
  215. #define MY_ALL_CHARSETS_SIZE 2048
  216. extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *default_charset_info;
  217. extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *all_charsets[MY_ALL_CHARSETS_SIZE];
  218. extern struct charset_info_st compiled_charsets[];
  219. /* Collation properties and use statistics */
  220. extern my_bool my_collation_is_known_id(uint id);
  221. extern ulonglong my_collation_statistics_get_use_count(uint id);
  222. extern const char *my_collation_get_tailoring(uint id);
  223. /* statistics */
  224. extern ulong my_file_opened,my_stream_opened, my_tmp_file_created;
  225. extern ulong my_file_total_opened;
  226. extern ulong my_sync_count;
  227. extern uint mysys_usage_id;
  228. extern my_bool my_init_done;
  229. extern my_bool my_assert_on_error;
  230. extern myf my_global_flags; /* Set to MY_WME for more error messages */
  231. /* Point to current my_message() */
  232. extern void (*my_sigtstp_cleanup)(void),
  233. /* Executed before jump to shell */
  234. (*my_sigtstp_restart)(void);
  235. /* Executed when comming from shell */
  236. extern MYSQL_PLUGIN_IMPORT int my_umask; /* Default creation mask */
  237. extern int my_umask_dir,
  238. my_recived_signals, /* Signals we have got */
  239. my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */
  240. my_dont_interrupt; /* call remember_intr when set */
  241. extern my_bool my_use_symdir;
  242. extern ulong my_default_record_cache_size;
  243. extern my_bool my_disable_locking, my_disable_async_io,
  244. my_disable_flush_key_blocks, my_disable_symlinks;
  245. extern my_bool my_disable_sync, my_disable_copystat_in_redel;
  246. extern char wild_many,wild_one,wild_prefix;
  247. extern const char *charsets_dir;
  248. extern my_bool timed_mutexes;
  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};
  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. @brief like FLUSH_KEEP but return immediately if file is already being
  266. flushed (even partially) by another thread; only for page cache,
  267. forbidden for key cache.
  268. */
  269. FLUSH_KEEP_LAZY
  270. };
  271. typedef struct st_record_cache /* Used when cacheing records */
  272. {
  273. File file;
  274. int rc_seek,error,inited;
  275. uint rc_length,read_length,reclength;
  276. my_off_t rc_record_pos,end_of_file;
  277. uchar *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos;
  278. #ifdef HAVE_AIOWAIT
  279. int use_async_io;
  280. my_aio_result aio_result;
  281. #endif
  282. enum cache_type type;
  283. } RECORD_CACHE;
  284. enum file_type
  285. {
  286. UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN,
  287. FILE_BY_MKSTEMP, FILE_BY_DUP
  288. };
  289. struct st_my_file_info
  290. {
  291. char *name;
  292. #ifdef _WIN32
  293. HANDLE fhandle; /* win32 file handle */
  294. int oflag; /* open flags, e.g O_APPEND */
  295. #endif
  296. enum file_type type;
  297. };
  298. extern struct st_my_file_info *my_file_info;
  299. /* Free function pointer */
  300. typedef void (*FREE_FUNC)(void *);
  301. typedef struct st_dynamic_array
  302. {
  303. uchar *buffer;
  304. uint elements,max_element;
  305. uint alloc_increment;
  306. uint size_of_element;
  307. myf malloc_flags;
  308. } DYNAMIC_ARRAY;
  309. typedef struct st_my_tmpdir
  310. {
  311. DYNAMIC_ARRAY full_list;
  312. char **list;
  313. uint cur, max;
  314. mysql_mutex_t mutex;
  315. } MY_TMPDIR;
  316. typedef struct st_dynamic_string
  317. {
  318. char *str;
  319. size_t length,max_length,alloc_increment;
  320. } DYNAMIC_STRING;
  321. struct st_io_cache;
  322. typedef struct st_io_cache_share
  323. {
  324. mysql_mutex_t mutex; /* To sync on reads into buffer. */
  325. mysql_cond_t cond; /* To wait for signals. */
  326. mysql_cond_t cond_writer; /* For a synchronized writer. */
  327. /* Offset in file corresponding to the first byte of buffer. */
  328. my_off_t pos_in_file;
  329. /* If a synchronized write cache is the source of the data. */
  330. struct st_io_cache *source_cache;
  331. uchar *buffer; /* The read buffer. */
  332. uchar *read_end; /* Behind last valid byte of buffer. */
  333. int running_threads; /* threads not in lock. */
  334. int total_threads; /* threads sharing the cache. */
  335. int error; /* Last error. */
  336. #ifdef NOT_YET_IMPLEMENTED
  337. /* whether the structure should be free'd */
  338. my_bool alloced;
  339. #endif
  340. } IO_CACHE_SHARE;
  341. typedef struct st_io_cache /* Used when cacheing files */
  342. {
  343. /* Offset in file corresponding to the first byte of uchar* buffer. */
  344. my_off_t pos_in_file;
  345. /*
  346. The offset of end of file for READ_CACHE and WRITE_CACHE.
  347. For SEQ_READ_APPEND it the maximum of the actual end of file and
  348. the position represented by read_end.
  349. */
  350. my_off_t end_of_file;
  351. /* Points to current read position in the buffer */
  352. uchar *read_pos;
  353. /* the non-inclusive boundary in the buffer for the currently valid read */
  354. uchar *read_end;
  355. uchar *buffer; /* The read buffer */
  356. /* Used in ASYNC_IO */
  357. uchar *request_pos;
  358. /* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
  359. uchar *write_buffer;
  360. /*
  361. Only used in SEQ_READ_APPEND, and points to the current read position
  362. in the write buffer. Note that reads in SEQ_READ_APPEND caches can
  363. happen from both read buffer (uchar* buffer) and write buffer
  364. (uchar* write_buffer).
  365. */
  366. uchar *append_read_pos;
  367. /* Points to current write position in the write buffer */
  368. uchar *write_pos;
  369. /* The non-inclusive boundary of the valid write area */
  370. uchar *write_end;
  371. /*
  372. Current_pos and current_end are convenience variables used by
  373. my_b_tell() and other routines that need to know the current offset
  374. current_pos points to &write_pos, and current_end to &write_end in a
  375. WRITE_CACHE, and &read_pos and &read_end respectively otherwise
  376. */
  377. uchar **current_pos, **current_end;
  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. mysql_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. /*
  392. A caller will use my_b_read() macro to read from the cache
  393. if the data is already in cache, it will be simply copied with
  394. memcpy() and internal variables will be accordinging updated with
  395. no functions invoked. However, if the data is not fully in the cache,
  396. my_b_read() will call read_function to fetch the data. read_function
  397. must never be invoked directly.
  398. */
  399. int (*read_function)(struct st_io_cache *,uchar *,size_t);
  400. /*
  401. Same idea as in the case of read_function, except my_b_write() needs to
  402. be replaced with my_b_append() for a SEQ_READ_APPEND cache
  403. */
  404. int (*write_function)(struct st_io_cache *,const uchar *,size_t);
  405. /*
  406. Specifies the type of the cache. Depending on the type of the cache
  407. certain operations might not be available and yield unpredicatable
  408. results. Details to be documented later
  409. */
  410. enum cache_type type;
  411. /*
  412. Counts the number of times, when we were forced to use disk. We use it to
  413. increase the binlog_cache_disk_use and binlog_stmt_cache_disk_use status
  414. variables.
  415. */
  416. ulong disk_writes;
  417. char *file_name; /* if used with 'open_cached_file' */
  418. const char *dir;
  419. char prefix[3];
  420. File file; /* file descriptor */
  421. /*
  422. seek_not_done is set by my_b_seek() to inform the upcoming read/write
  423. operation that a seek needs to be preformed prior to the actual I/O
  424. error is 0 if the cache operation was successful, -1 if there was a
  425. "hard" error, and the actual number of I/O-ed bytes if the read/write was
  426. partial.
  427. */
  428. int seek_not_done,error;
  429. /* buffer_length is memory size allocated for buffer or write_buffer */
  430. size_t buffer_length;
  431. /* read_length is the same as buffer_length except when we use async io */
  432. size_t read_length;
  433. myf myflags; /* Flags used to my_read/my_write */
  434. /*
  435. alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
  436. 0 if it was supplied by the user.
  437. Currently READ_NET is the only one that will use a buffer allocated
  438. somewhere else
  439. */
  440. my_bool alloced_buffer;
  441. #ifdef HAVE_AIOWAIT
  442. /*
  443. As inidicated by ifdef, this is for async I/O, which is not currently
  444. used (because it's not reliable on all systems)
  445. */
  446. uint inited;
  447. my_off_t aio_read_pos;
  448. my_aio_result aio_result;
  449. #endif
  450. } IO_CACHE;
  451. typedef int (*qsort2_cmp)(const void *, const void *, const void *);
  452. typedef void (*my_error_reporter)(enum loglevel level, const char *format, ...)
  453. ATTRIBUTE_FORMAT_FPTR(printf, 2, 3);
  454. extern my_error_reporter my_charset_error_reporter;
  455. /* inline functions for mf_iocache */
  456. extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
  457. extern int _my_b_get(IO_CACHE *info);
  458. extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count);
  459. extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
  460. /* Test if buffer is inited */
  461. static inline void my_b_clear(IO_CACHE *info) { info->buffer= 0; }
  462. static inline int my_b_inited(IO_CACHE *info) { return MY_TEST(info->buffer); }
  463. #define my_b_EOF INT_MIN
  464. static inline int my_b_read(IO_CACHE *info, uchar *Buffer, size_t Count)
  465. {
  466. if (info->read_pos + Count <= info->read_end)
  467. {
  468. memcpy(Buffer, info->read_pos, Count);
  469. info->read_pos+= Count;
  470. return 0;
  471. }
  472. return _my_b_read(info, Buffer, Count);
  473. }
  474. static inline int my_b_write(IO_CACHE *info, const uchar *Buffer, size_t Count)
  475. {
  476. if (info->write_pos + Count <= info->write_end)
  477. {
  478. memcpy(info->write_pos, Buffer, Count);
  479. info->write_pos+= Count;
  480. return 0;
  481. }
  482. return _my_b_write(info, Buffer, Count);
  483. }
  484. static inline int my_b_get(IO_CACHE *info)
  485. {
  486. if (info->read_pos != info->read_end)
  487. {
  488. info->read_pos++;
  489. return info->read_pos[-1];
  490. }
  491. return _my_b_get(info);
  492. }
  493. /* my_b_write_byte dosn't have any err-check */
  494. static inline void my_b_write_byte(IO_CACHE *info, uchar chr)
  495. {
  496. if (info->write_pos >= info->write_end)
  497. my_b_flush_io_cache(info, 1);
  498. *info->write_pos++= chr;
  499. }
  500. /**
  501. Fill buffer of the cache.
  502. @note It assumes that you have already used all characters in the CACHE,
  503. independent of the read_pos value!
  504. @returns
  505. 0 On error or EOF (info->error = -1 on error)
  506. # Number of characters
  507. */
  508. static inline size_t my_b_fill(IO_CACHE *info)
  509. {
  510. info->read_pos= info->read_end;
  511. return _my_b_read(info,0,0) ? 0 : info->read_end - info->read_pos;
  512. }
  513. static inline my_off_t my_b_tell(const IO_CACHE *info)
  514. {
  515. return info->pos_in_file + (*info->current_pos - info->request_pos);
  516. }
  517. static inline my_off_t my_b_write_tell(const IO_CACHE *info)
  518. {
  519. return info->pos_in_file + (info->write_pos - info->write_buffer);
  520. }
  521. static inline uchar* my_b_get_buffer_start(const IO_CACHE *info)
  522. {
  523. return info->request_pos;
  524. }
  525. static inline size_t my_b_get_bytes_in_buffer(const IO_CACHE *info)
  526. {
  527. return info->read_end - info->request_pos;
  528. }
  529. static inline my_off_t my_b_get_pos_in_file(const IO_CACHE *info)
  530. {
  531. return info->pos_in_file;
  532. }
  533. static inline size_t my_b_bytes_in_cache(const IO_CACHE *info)
  534. {
  535. return *info->current_end - *info->current_pos;
  536. }
  537. int my_b_copy_to_file(IO_CACHE *cache, FILE *file);
  538. my_off_t my_b_append_tell(IO_CACHE* info);
  539. my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
  540. int my_b_pread(IO_CACHE *info, uchar *Buffer, size_t Count, my_off_t pos);
  541. typedef uint32 ha_checksum;
  542. #include <my_alloc.h>
  543. /* Prototypes for mysys and my_func functions */
  544. extern int my_copy(const char *from,const char *to,myf MyFlags);
  545. extern int my_delete(const char *name,myf MyFlags);
  546. extern int my_getwd(char * buf,size_t size,myf MyFlags);
  547. extern int my_setwd(const char *dir,myf MyFlags);
  548. extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags);
  549. extern void *my_once_alloc(size_t Size,myf MyFlags);
  550. extern void my_once_free(void);
  551. extern char *my_once_strdup(const char *src,myf myflags);
  552. extern void *my_once_memdup(const void *src, size_t len, myf myflags);
  553. extern File my_open(const char *FileName,int Flags,myf MyFlags);
  554. extern File my_register_filename(File fd, const char *FileName,
  555. enum file_type type_of_file,
  556. uint error_message_number, myf MyFlags);
  557. extern File my_create(const char *FileName,int CreateFlags,
  558. int AccessFlags, myf MyFlags);
  559. extern int my_close(File Filedes,myf MyFlags);
  560. extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
  561. extern int my_readlink(char *to, const char *filename, myf MyFlags);
  562. extern int my_is_symlink(const char *filename);
  563. extern int my_realpath(char *to, const char *filename, myf MyFlags);
  564. extern File my_create_with_symlink(const char *linkname, const char *filename,
  565. int createflags, int access_flags,
  566. myf MyFlags);
  567. extern int my_delete_with_symlink(const char *name, myf MyFlags);
  568. extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags);
  569. extern int my_symlink(const char *content, const char *linkname, myf MyFlags);
  570. extern size_t my_read(File Filedes,uchar *Buffer,size_t Count,myf MyFlags);
  571. extern size_t my_pread(File Filedes,uchar *Buffer,size_t Count,my_off_t offset,
  572. myf MyFlags);
  573. extern int my_rename(const char *from,const char *to,myf MyFlags);
  574. extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags);
  575. extern my_off_t my_tell(File fd,myf MyFlags);
  576. extern size_t my_write(File Filedes,const uchar *Buffer,size_t Count,
  577. myf MyFlags);
  578. extern size_t my_pwrite(File Filedes,const uchar *Buffer,size_t Count,
  579. my_off_t offset,myf MyFlags);
  580. extern size_t my_fread(FILE *stream,uchar *Buffer,size_t Count,myf MyFlags);
  581. extern size_t my_fwrite(FILE *stream,const uchar *Buffer,size_t Count,
  582. myf MyFlags);
  583. extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags);
  584. extern my_off_t my_ftell(FILE *stream,myf MyFlags);
  585. /* implemented in my_memmem.c */
  586. extern void *my_memmem(const void *haystack, size_t haystacklen,
  587. const void *needle, size_t needlelen);
  588. #ifdef _WIN32
  589. extern int my_access(const char *path, int amode);
  590. #else
  591. #define my_access access
  592. #endif
  593. extern int check_if_legal_filename(const char *path);
  594. extern int check_if_legal_tablename(const char *path);
  595. #ifdef __WIN__
  596. extern my_bool is_filename_allowed(const char *name, size_t length,
  597. my_bool allow_current_dir);
  598. #else /* __WIN__ */
  599. # define is_filename_allowed(name, length, allow_cwd) (TRUE)
  600. #endif /* __WIN__ */
  601. #ifdef _WIN32
  602. /* Windows-only functions (CRT equivalents)*/
  603. extern HANDLE my_get_osfhandle(File fd);
  604. extern void my_osmaperr(unsigned long last_error);
  605. #endif
  606. extern void init_glob_errs(void);
  607. extern const char** get_global_errmsgs(void);
  608. extern void wait_for_free_space(const char *filename, int errors);
  609. extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
  610. extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
  611. extern FILE *my_freopen(const char *path, const char *mode, FILE *stream);
  612. extern int my_fclose(FILE *fd,myf MyFlags);
  613. extern int my_vfprintf(FILE *stream, const char* format, va_list args);
  614. extern void my_strerror(char *buf, size_t len, int nr);
  615. extern int my_fprintf(FILE *stream, const char* format, ...);
  616. extern File my_fileno(FILE *fd);
  617. extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
  618. extern int my_chmod(const char *name, mode_t mode, myf my_flags);
  619. extern const char *my_basename(const char *filename);
  620. extern void thr_set_sync_wait_callback(void (*before_sync)(void),
  621. void (*after_sync)(void));
  622. extern int my_sync(File fd, myf my_flags);
  623. extern int my_sync_dir(const char *dir_name, myf my_flags);
  624. extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
  625. extern const char *my_get_err_msg(uint nr);
  626. extern void my_error(uint nr,myf MyFlags, ...);
  627. extern void my_printf_error(uint my_err, const char *format,
  628. myf MyFlags, ...)
  629. ATTRIBUTE_FORMAT(printf, 2, 4);
  630. extern void my_printv_error(uint error, const char *format, myf MyFlags,
  631. va_list ap);
  632. extern int my_error_register(const char** (*get_errmsgs) (void),
  633. uint first, uint last);
  634. extern const char **my_error_unregister(uint first, uint last);
  635. extern void my_message(uint my_err, const char *str,myf MyFlags);
  636. extern void my_message_stderr(uint my_err, const char *str, myf MyFlags);
  637. extern my_bool my_init(void);
  638. extern void my_end(int infoflag);
  639. extern int my_redel(const char *from, const char *to, time_t backup_time_stamp,
  640. myf MyFlags);
  641. void my_create_backup_name(char *to, const char *from,
  642. time_t backup_time_stamp);
  643. extern int my_copystat(const char *from, const char *to, int MyFlags);
  644. extern char * my_filename(File fd);
  645. #ifdef EXTRA_DEBUG
  646. void my_print_open_files(void);
  647. #else
  648. #define my_print_open_files()
  649. #endif
  650. extern my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist);
  651. extern char *my_tmpdir(MY_TMPDIR *tmpdir);
  652. extern void free_tmpdir(MY_TMPDIR *tmpdir);
  653. extern void my_remember_signal(int signal_number,sig_handler (*func)(int));
  654. extern size_t dirname_part(char * to,const char *name, size_t *to_res_length);
  655. extern size_t dirname_length(const char *name);
  656. #define base_name(A) (A+dirname_length(A))
  657. extern int test_if_hard_path(const char *dir_name);
  658. extern my_bool has_path(const char *name);
  659. extern char *convert_dirname(char *to, const char *from, const char *from_end);
  660. extern void to_unix_path(char * name);
  661. extern char * fn_ext(const char *name);
  662. extern char * fn_ext2(const char *name);
  663. extern char * fn_same(char * toname,const char *name,int flag);
  664. extern char * fn_format(char * to,const char *name,const char *dir,
  665. const char *form, uint flag);
  666. extern size_t strlength(const char *str);
  667. extern void pack_dirname(char * to,const char *from);
  668. extern size_t normalize_dirname(char * to, const char *from);
  669. extern size_t unpack_dirname(char * to,const char *from);
  670. extern size_t cleanup_dirname(char * to,const char *from);
  671. extern size_t system_filename(char * to,const char *from);
  672. extern size_t unpack_filename(char * to,const char *from);
  673. extern char * intern_filename(char * to,const char *from);
  674. extern int pack_filename(char * to, const char *name, size_t max_length);
  675. extern char * my_path(char * to,const char *progname,
  676. const char *own_pathname_part);
  677. extern char * my_load_path(char * to, const char *path,
  678. const char *own_path_prefix);
  679. extern int wild_compare(const char *str,const char *wildstr,
  680. pbool str_is_pattern);
  681. extern my_bool array_append_string_unique(const char *str,
  682. const char **array, size_t size);
  683. extern void get_date(char * to,int timeflag,time_t use_time);
  684. extern void soundex(CHARSET_INFO *, char * out_pntr, char * in_pntr,
  685. pbool remove_garbage);
  686. extern int init_record_cache(RECORD_CACHE *info,size_t cachesize,File file,
  687. size_t reclength,enum cache_type type,
  688. pbool use_async_io);
  689. extern int read_cache_record(RECORD_CACHE *info,uchar *to);
  690. extern int end_record_cache(RECORD_CACHE *info);
  691. extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos,
  692. const uchar *record,size_t length);
  693. extern int flush_write_cache(RECORD_CACHE *info);
  694. extern void handle_recived_signals(void);
  695. extern sig_handler my_set_alarm_variable(int signo);
  696. extern my_bool radixsort_is_appliccable(uint n_items, size_t size_of_element);
  697. extern void my_string_ptr_sort(uchar *base,uint items,size_t size);
  698. extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
  699. size_t size_of_element,uchar *buffer[]);
  700. extern qsort_t my_qsort(void *base_ptr, size_t total_elems, size_t size,
  701. qsort_cmp cmp);
  702. extern qsort_t my_qsort2(void *base_ptr, size_t total_elems, size_t size,
  703. qsort2_cmp cmp, void *cmp_argument);
  704. extern qsort2_cmp get_ptr_compare(size_t);
  705. void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos);
  706. my_off_t my_get_ptr(uchar *ptr, size_t pack_length);
  707. extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
  708. enum cache_type type,my_off_t seek_offset,
  709. my_bool use_async_io, myf cache_myflags);
  710. extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
  711. my_off_t seek_offset, my_bool use_async_io,
  712. my_bool clear_cache);
  713. extern void setup_io_cache(IO_CACHE* info);
  714. extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
  715. IO_CACHE *write_cache, uint num_threads);
  716. extern void remove_io_thread(IO_CACHE *info);
  717. extern int _my_b_async_read(IO_CACHE *info,uchar *Buffer,size_t Count);
  718. extern int my_b_append(IO_CACHE *info,const uchar *Buffer,size_t Count);
  719. extern int my_b_safe_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
  720. extern int my_block_write(IO_CACHE *info, const uchar *Buffer,
  721. size_t Count, my_off_t pos);
  722. #define flush_io_cache(info) my_b_flush_io_cache((info),1)
  723. extern int end_io_cache(IO_CACHE *info);
  724. extern void my_b_seek(IO_CACHE *info,my_off_t pos);
  725. extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
  726. extern my_off_t my_b_filelength(IO_CACHE *info);
  727. extern size_t my_b_write_backtick_quote(IO_CACHE *info, const char *str,
  728. size_t len);
  729. extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...);
  730. extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
  731. extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
  732. const char *prefix, size_t cache_size,
  733. myf cache_myflags);
  734. extern my_bool real_open_cached_file(IO_CACHE *cache);
  735. extern void close_cached_file(IO_CACHE *cache);
  736. File create_temp_file(char *to, const char *dir, const char *pfx,
  737. int mode, myf MyFlags);
  738. #define my_init_dynamic_array(A,B,C,D,E) init_dynamic_array2(A,B,NULL,C,D,E)
  739. #define my_init_dynamic_array2(A,B,C,D,E,F) init_dynamic_array2(A,B,C,D,E,F)
  740. extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size,
  741. void *init_buffer, uint init_alloc,
  742. uint alloc_increment, myf my_flags);
  743. extern my_bool insert_dynamic(DYNAMIC_ARRAY *array, const void* element);
  744. extern void *alloc_dynamic(DYNAMIC_ARRAY *array);
  745. extern void *pop_dynamic(DYNAMIC_ARRAY*);
  746. extern my_bool set_dynamic(DYNAMIC_ARRAY *array, const void *element,
  747. uint array_index);
  748. extern my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements);
  749. extern void get_dynamic(DYNAMIC_ARRAY *array, void *element, uint array_index);
  750. extern void delete_dynamic(DYNAMIC_ARRAY *array);
  751. extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index);
  752. extern void delete_dynamic_with_callback(DYNAMIC_ARRAY *array, FREE_FUNC f);
  753. extern void freeze_size(DYNAMIC_ARRAY *array);
  754. extern int get_index_dynamic(DYNAMIC_ARRAY *array, void *element);
  755. #define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element)
  756. #define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index))
  757. #define push_dynamic(A,B) insert_dynamic((A),(B))
  758. #define reset_dynamic(array) ((array)->elements= 0)
  759. #define sort_dynamic(A,cmp) my_qsort((A)->buffer, (A)->elements, (A)->size_of_element, (cmp))
  760. extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
  761. size_t init_alloc,size_t alloc_increment);
  762. extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append);
  763. my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
  764. size_t length);
  765. extern my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append,
  766. ...);
  767. extern my_bool dynstr_append_quoted(DYNAMIC_STRING *str,
  768. const char *append, size_t len,
  769. char quote);
  770. extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str);
  771. extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size);
  772. extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n);
  773. extern void dynstr_free(DYNAMIC_STRING *str);
  774. extern uint32 copy_and_convert_extended(char *to, uint32 to_length,
  775. CHARSET_INFO *to_cs,
  776. const char *from, uint32 from_length,
  777. CHARSET_INFO *from_cs, uint *errors);
  778. extern void dynstr_reassociate(DYNAMIC_STRING *str, char **res, size_t *length,
  779. size_t *alloc_length);
  780. extern uint32 copy_and_convert_extended(char *to, uint32 to_length,
  781. CHARSET_INFO *to_cs,
  782. const char *from, uint32 from_length,
  783. CHARSET_INFO *from_cs, uint *errors);
  784. #ifdef HAVE_MLOCK
  785. extern void *my_malloc_lock(size_t length,myf flags);
  786. extern void my_free_lock(void *ptr);
  787. #else
  788. #define my_malloc_lock(A,B) my_malloc((A),(B))
  789. #define my_free_lock(A) my_free((A))
  790. #endif
  791. #define alloc_root_inited(A) ((A)->min_malloc != 0)
  792. #define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
  793. #define clear_alloc_root(A) do { (A)->free= (A)->used= (A)->pre_alloc= 0; (A)->min_malloc=0;} while(0)
  794. extern void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
  795. size_t pre_alloc_size, myf my_flags);
  796. extern void *alloc_root(MEM_ROOT *mem_root, size_t Size);
  797. extern void *multi_alloc_root(MEM_ROOT *mem_root, ...);
  798. extern void free_root(MEM_ROOT *root, myf MyFLAGS);
  799. extern void set_prealloc_root(MEM_ROOT *root, char *ptr);
  800. extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
  801. size_t prealloc_size);
  802. extern char *strdup_root(MEM_ROOT *root,const char *str);
  803. static inline char *safe_strdup_root(MEM_ROOT *root, const char *str)
  804. {
  805. return str ? strdup_root(root, str) : 0;
  806. }
  807. extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
  808. extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
  809. extern my_bool my_compress(uchar *, size_t *, size_t *);
  810. extern my_bool my_uncompress(uchar *, size_t , size_t *);
  811. extern uchar *my_compress_alloc(const uchar *packet, size_t *len,
  812. size_t *complen);
  813. extern void *my_az_allocator(void *dummy, unsigned int items, unsigned int size);
  814. extern void my_az_free(void *dummy, void *address);
  815. extern int my_compress_buffer(uchar *dest, size_t *destLen,
  816. const uchar *source, size_t sourceLen);
  817. extern int packfrm(const uchar *, size_t, uchar **, size_t *);
  818. extern int unpackfrm(uchar **, size_t *, const uchar *);
  819. extern ha_checksum my_checksum(ha_checksum crc, const uchar *mem,
  820. size_t count);
  821. #ifndef DBUG_OFF
  822. extern void my_debug_put_break_here(void);
  823. #else
  824. #define my_debug_put_break_here() do {} while(0)
  825. #endif
  826. extern void my_sleep(ulong m_seconds);
  827. extern ulong crc32(ulong crc, const uchar *buf, uint len);
  828. extern uint my_set_max_open_files(uint files);
  829. void my_free_open_file_info(void);
  830. extern my_bool my_gethwaddr(uchar *to);
  831. extern int my_getncpus(void);
  832. #define HRTIME_RESOLUTION 1000000ULL /* microseconds */
  833. typedef struct {ulonglong val;} my_hrtime_t;
  834. void my_time_init(void);
  835. extern my_hrtime_t my_hrtime(void);
  836. extern ulonglong my_interval_timer(void);
  837. extern ulonglong my_getcputime(void);
  838. #define microsecond_interval_timer() (my_interval_timer()/1000)
  839. #define hrtime_to_time(X) ((X).val/HRTIME_RESOLUTION)
  840. #define hrtime_from_time(X) ((ulonglong)((X)*HRTIME_RESOLUTION))
  841. #define hrtime_to_double(X) ((X).val/(double)HRTIME_RESOLUTION)
  842. #define hrtime_sec_part(X) ((ulong)((X).val % HRTIME_RESOLUTION))
  843. #define my_time(X) hrtime_to_time(my_hrtime())
  844. #ifdef HAVE_SYS_MMAN_H
  845. #include <sys/mman.h>
  846. #ifndef MAP_NOSYNC
  847. #define MAP_NOSYNC 0
  848. #endif
  849. #ifndef MAP_NORESERVE
  850. #define MAP_NORESERVE 0 /* For irix and AIX */
  851. #endif
  852. #ifdef HAVE_MMAP64
  853. #define my_mmap(a,b,c,d,e,f) mmap64(a,b,c,d,e,f)
  854. #else
  855. #define my_mmap(a,b,c,d,e,f) mmap(a,b,c,d,e,f)
  856. #endif
  857. #define my_munmap(a,b) munmap((a),(b))
  858. #else
  859. /* not a complete set of mmap() flags, but only those that nesessary */
  860. #define PROT_READ 1
  861. #define PROT_WRITE 2
  862. #define MAP_NORESERVE 0
  863. #define MAP_SHARED 0x0001
  864. #define MAP_PRIVATE 0x0002
  865. #define MAP_NOSYNC 0x0800
  866. #define MAP_FAILED ((void *)-1)
  867. #define MS_SYNC 0x0000
  868. #define HAVE_MMAP
  869. void *my_mmap(void *, size_t, int, int, int, my_off_t);
  870. int my_munmap(void *, size_t);
  871. #endif
  872. /* my_getpagesize */
  873. #ifdef HAVE_GETPAGESIZE
  874. #define my_getpagesize() getpagesize()
  875. #else
  876. int my_getpagesize(void);
  877. #endif
  878. int my_msync(int, void *, size_t, int);
  879. #define MY_UUID_SIZE 16
  880. #define MY_UUID_STRING_LENGTH (8+1+4+1+4+1+4+1+12)
  881. void my_uuid_init(ulong seed1, ulong seed2);
  882. void my_uuid(uchar *guid);
  883. void my_uuid2str(const uchar *guid, char *s);
  884. void my_uuid_end(void);
  885. /* character sets */
  886. extern void my_charset_loader_init_mysys(MY_CHARSET_LOADER *loader);
  887. extern uint get_charset_number(const char *cs_name, uint cs_flags);
  888. extern uint get_collation_number(const char *name);
  889. extern const char *get_charset_name(uint cs_number);
  890. extern CHARSET_INFO *get_charset(uint cs_number, myf flags);
  891. extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags);
  892. extern CHARSET_INFO *my_collation_get_by_name(MY_CHARSET_LOADER *loader,
  893. const char *name, myf flags);
  894. extern CHARSET_INFO *get_charset_by_csname(const char *cs_name,
  895. uint cs_flags, myf my_flags);
  896. extern CHARSET_INFO *my_charset_get_by_name(MY_CHARSET_LOADER *loader,
  897. const char *name,
  898. uint cs_flags, myf my_flags);
  899. extern my_bool resolve_charset(const char *cs_name,
  900. CHARSET_INFO *default_cs,
  901. CHARSET_INFO **cs);
  902. extern my_bool resolve_collation(const char *cl_name,
  903. CHARSET_INFO *default_cl,
  904. CHARSET_INFO **cl);
  905. extern void free_charsets(void);
  906. extern char *get_charsets_dir(char *buf);
  907. extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2);
  908. extern my_bool init_compiled_charsets(myf flags);
  909. extern void add_compiled_collation(struct charset_info_st *cs);
  910. extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info,
  911. char *to, size_t to_length,
  912. const char *from, size_t length);
  913. #ifdef __WIN__
  914. #define BACKSLASH_MBTAIL
  915. /* File system character set */
  916. extern CHARSET_INFO *fs_character_set(void);
  917. #endif
  918. extern size_t escape_quotes_for_mysql(CHARSET_INFO *charset_info,
  919. char *to, size_t to_length,
  920. const char *from, size_t length);
  921. extern void thd_increment_bytes_sent(void *thd, ulong length);
  922. extern void thd_increment_bytes_received(void *thd, ulong length);
  923. extern void thd_increment_net_big_packet_count(void *thd, ulong length);
  924. #ifdef __WIN__
  925. extern my_bool have_tcpip; /* Is set if tcpip is used */
  926. /* implemented in my_windac.c */
  927. int my_security_attr_create(SECURITY_ATTRIBUTES **psa, const char **perror,
  928. DWORD owner_rights, DWORD everybody_rights);
  929. void my_security_attr_free(SECURITY_ATTRIBUTES *sa);
  930. /* implemented in my_conio.c */
  931. char* my_cgets(char *string, size_t clen, size_t* plen);
  932. #endif
  933. #include <mysql/psi/psi.h>
  934. #ifdef HAVE_PSI_INTERFACE
  935. extern MYSQL_PLUGIN_IMPORT struct PSI_bootstrap *PSI_hook;
  936. extern void set_psi_server(PSI *psi);
  937. void my_init_mysys_psi_keys(void);
  938. #endif
  939. struct st_mysql_file;
  940. extern struct st_mysql_file *mysql_stdin;
  941. C_MODE_END
  942. #endif /* _my_sys_h */