m_string.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* Copyright (C) 2000 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. /* There may be prolems include all of theese. Try to test in
  13. configure with ones are needed? */
  14. /* This is needed for the definitions of strchr... on solaris */
  15. #ifndef _m_string_h
  16. #define _m_string_h
  17. #ifndef __USE_GNU
  18. #define __USE_GNU /* We want to use stpcpy */
  19. #endif
  20. #if defined(HAVE_STRINGS_H)
  21. #include <strings.h>
  22. #endif
  23. #if defined(HAVE_STRING_H)
  24. #include <string.h>
  25. #endif
  26. /* need by my_vsnprintf */
  27. #include <stdarg.h>
  28. #ifdef _AIX
  29. #undef HAVE_BCMP
  30. #endif
  31. /* This is needed for the definitions of bzero... on solaris */
  32. #if defined(HAVE_STRINGS_H)
  33. #include <strings.h>
  34. #endif
  35. /* This is needed for the definitions of memcpy... on solaris */
  36. #if defined(HAVE_MEMORY_H) && !defined(__cplusplus)
  37. #include <memory.h>
  38. #endif
  39. #if !defined(HAVE_MEMCPY) && !defined(HAVE_MEMMOVE)
  40. # define memcpy(d, s, n) bcopy ((s), (d), (n))
  41. # define memset(A,C,B) bfill((A),(B),(C))
  42. # define memmove(d, s, n) bmove ((d), (s), (n))
  43. #elif defined(HAVE_MEMMOVE)
  44. # define bmove(d, s, n) memmove((d), (s), (n))
  45. #else
  46. # define memmove(d, s, n) bmove((d), (s), (n)) /* our bmove */
  47. #endif
  48. /* Unixware 7 */
  49. #if !defined(HAVE_BFILL)
  50. # define bfill(A,B,C) memset((A),(C),(B))
  51. # define bmove_align(A,B,C) memcpy((A),(B),(C))
  52. #endif
  53. #if !defined(HAVE_BCMP)
  54. # define bcopy(s, d, n) memcpy((d), (s), (n))
  55. # define bcmp(A,B,C) memcmp((A),(B),(C))
  56. # define bzero(A,B) memset((A),0,(B))
  57. # define bmove_align(A,B,C) memcpy((A),(B),(C))
  58. #endif
  59. #if defined(__cplusplus)
  60. extern "C" {
  61. #endif
  62. /*
  63. my_str_malloc() and my_str_free() are assigned to implementations in
  64. strings/alloc.c, but can be overridden in the calling program.
  65. */
  66. extern void *(*my_str_malloc)(size_t);
  67. extern void (*my_str_free)(void *);
  68. #if defined(HAVE_STPCPY)
  69. #define strmov(A,B) stpcpy((A),(B))
  70. #ifndef stpcpy
  71. extern char *stpcpy(char *, const char *); /* For AIX with gcc 2.95.3 */
  72. #endif
  73. #endif
  74. /* Declared in int2str() */
  75. extern char NEAR _dig_vec_upper[];
  76. extern char NEAR _dig_vec_lower[];
  77. /* Defined in strtod.c */
  78. extern const double log_10[309];
  79. #ifndef strmov
  80. #define strmov_overlapp(A,B) strmov(A,B)
  81. #define strmake_overlapp(A,B,C) strmake(A,B,C)
  82. #endif
  83. #ifdef BAD_MEMCPY /* Problem with gcc on Alpha */
  84. #define memcpy_fixed(A,B,C) bmove((A),(B),(C))
  85. #else
  86. #define memcpy_fixed(A,B,C) memcpy((A),(B),(C))
  87. #endif
  88. #if (!defined(USE_BMOVE512) || defined(HAVE_purify)) && !defined(bmove512)
  89. #define bmove512(A,B,C) memcpy(A,B,C)
  90. #endif
  91. /* Prototypes for string functions */
  92. #if !defined(bfill) && !defined(HAVE_BFILL)
  93. extern void bfill(uchar *dst,size_t len,pchar fill);
  94. #endif
  95. #if !defined(bzero) && !defined(HAVE_BZERO)
  96. extern void bzero(uchar * dst,size_t len);
  97. #endif
  98. #if !defined(bcmp) && !defined(HAVE_BCMP)
  99. extern size_t bcmp(const uchar *s1,const uchar *s2,size_t len);
  100. #endif
  101. #ifdef HAVE_purify
  102. extern size_t my_bcmp(const uchar *s1,const uchar *s2,size_t len);
  103. #undef bcmp
  104. #define bcmp(A,B,C) my_bcmp((A),(B),(C))
  105. #define bzero_if_purify(A,B) bzero(A,B)
  106. #else
  107. #define bzero_if_purify(A,B)
  108. #endif /* HAVE_purify */
  109. #ifndef bmove512
  110. extern void bmove512(uchar *dst,const uchar *src,size_t len);
  111. #endif
  112. #if !defined(HAVE_BMOVE) && !defined(bmove)
  113. extern void bmove(uuchar *dst, const uchar *src,size_t len);
  114. #endif
  115. extern void bmove_upp(uchar *dst,const uchar *src,size_t len);
  116. extern void bchange(uchar *dst,size_t old_len,const uchar *src,
  117. size_t new_len,size_t tot_len);
  118. extern void strappend(char *s,size_t len,pchar fill);
  119. extern char *strend(const char *s);
  120. extern char *strcend(const char *, pchar);
  121. extern char *strfield(char *src,int fields,int chars,int blanks,
  122. int tabch);
  123. extern char *strfill(char * s,size_t len,pchar fill);
  124. extern size_t strinstr(const char *str,const char *search);
  125. extern size_t r_strinstr(const char *str, size_t from, const char *search);
  126. extern char *strkey(char *dst,char *head,char *tail,char *flags);
  127. extern char *strmake(char *dst,const char *src,size_t length);
  128. #ifndef strmov
  129. extern char *strmov(char *dst,const char *src);
  130. #else
  131. extern char *strmov_overlapp(char *dst,const char *src);
  132. #endif
  133. extern char *strnmov(char *dst,const char *src,size_t n);
  134. extern char *strsuff(const char *src,const char *suffix);
  135. extern char *strcont(const char *src,const char *set);
  136. extern char *strxcat _VARARGS((char *dst,const char *src, ...));
  137. extern char *strxmov _VARARGS((char *dst,const char *src, ...));
  138. extern char *strxcpy _VARARGS((char *dst,const char *src, ...));
  139. extern char *strxncat _VARARGS((char *dst,size_t len, const char *src, ...));
  140. extern char *strxnmov _VARARGS((char *dst,size_t len, const char *src, ...));
  141. extern char *strxncpy _VARARGS((char *dst,size_t len, const char *src, ...));
  142. /* Prototypes of normal stringfunctions (with may ours) */
  143. #ifdef WANT_STRING_PROTOTYPES
  144. extern char *strcat(char *, const char *);
  145. extern char *strchr(const char *, pchar);
  146. extern char *strrchr(const char *, pchar);
  147. extern char *strcpy(char *, const char *);
  148. extern int strcmp(const char *, const char *);
  149. #ifndef __GNUC__
  150. extern size_t strlen(const char *);
  151. #endif
  152. #endif
  153. #ifndef HAVE_STRNLEN
  154. extern size_t strnlen(const char *s, size_t n);
  155. #endif
  156. #if !defined(__cplusplus)
  157. #ifndef HAVE_STRPBRK
  158. extern char *strpbrk(const char *, const char *);
  159. #endif
  160. #ifndef HAVE_STRSTR
  161. extern char *strstr(const char *, const char *);
  162. #endif
  163. #endif
  164. extern int is_prefix(const char *, const char *);
  165. /* Conversion routines */
  166. double my_strtod(const char *str, char **end, int *error);
  167. double my_atof(const char *nptr);
  168. extern char *llstr(longlong value,char *buff);
  169. extern char *ullstr(longlong value,char *buff);
  170. #ifndef HAVE_STRTOUL
  171. extern long strtol(const char *str, char **ptr, int base);
  172. extern ulong strtoul(const char *str, char **ptr, int base);
  173. #endif
  174. extern char *int2str(long val, char *dst, int radix, int upcase);
  175. extern char *int10_to_str(long val,char *dst,int radix);
  176. extern char *str2int(const char *src,int radix,long lower,long upper,
  177. long *val);
  178. longlong my_strtoll10(const char *nptr, char **endptr, int *error);
  179. #if SIZEOF_LONG == SIZEOF_LONG_LONG
  180. #define longlong2str(A,B,C) int2str((A),(B),(C),1)
  181. #define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C))
  182. #undef strtoll
  183. #define strtoll(A,B,C) strtol((A),(B),(C))
  184. #define strtoull(A,B,C) strtoul((A),(B),(C))
  185. #ifndef HAVE_STRTOULL
  186. #define HAVE_STRTOULL
  187. #endif
  188. #ifndef HAVE_STRTOLL
  189. #define HAVE_STRTOLL
  190. #endif
  191. #else
  192. #ifdef HAVE_LONG_LONG
  193. extern char *longlong2str(longlong val,char *dst,int radix);
  194. extern char *longlong10_to_str(longlong val,char *dst,int radix);
  195. #if (!defined(HAVE_STRTOULL) || defined(NO_STRTOLL_PROTO))
  196. extern longlong strtoll(const char *str, char **ptr, int base);
  197. extern ulonglong strtoull(const char *str, char **ptr, int base);
  198. #endif
  199. #endif
  200. #endif
  201. /* my_vsnprintf.c */
  202. extern size_t my_vsnprintf(char *str, size_t n,
  203. const char *format, va_list ap);
  204. extern size_t my_snprintf(char *to, size_t n, const char *fmt, ...)
  205. ATTRIBUTE_FORMAT(printf, 3, 4);
  206. #if defined(__cplusplus)
  207. }
  208. #endif
  209. /*
  210. LEX_STRING -- a pair of a C-string and its length.
  211. */
  212. #ifndef _my_plugin_h
  213. /* This definition must match the one given in mysql/plugin.h */
  214. struct st_mysql_lex_string
  215. {
  216. char *str;
  217. size_t length;
  218. };
  219. #endif
  220. typedef struct st_mysql_lex_string LEX_STRING;
  221. #define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1))
  222. #define USTRING_WITH_LEN(X) ((uchar*) X), ((size_t) (sizeof(X) - 1))
  223. #define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1))
  224. #endif