1 | /* Copyright (C) 2000 MySQL AB |
---|
2 | |
---|
3 | This program is free software; you can redistribute it and/or modify |
---|
4 | it under the terms of the GNU General Public License as published by |
---|
5 | the Free Software Foundation; version 2 of the License. |
---|
6 | |
---|
7 | This program is distributed in the hope that it will be useful, |
---|
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
10 | GNU General Public License for more details. |
---|
11 | |
---|
12 | You should have received a copy of the GNU General Public License |
---|
13 | along with this program; if not, write to the Free Software |
---|
14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
---|
15 | |
---|
16 | /* There may be prolems include all of theese. Try to test in |
---|
17 | configure with ones are needed? */ |
---|
18 | |
---|
19 | /* This is needed for the definitions of strchr... on solaris */ |
---|
20 | |
---|
21 | #ifndef _m_string_h |
---|
22 | #define _m_string_h |
---|
23 | #ifndef __USE_GNU |
---|
24 | #define __USE_GNU /* We want to use stpcpy */ |
---|
25 | #endif |
---|
26 | #if defined(HAVE_STRINGS_H) |
---|
27 | #include <strings.h> |
---|
28 | #endif |
---|
29 | #if defined(HAVE_STRING_H) |
---|
30 | #include <string.h> |
---|
31 | #endif |
---|
32 | |
---|
33 | /* need by my_vsnprintf */ |
---|
34 | #include <stdarg.h> |
---|
35 | |
---|
36 | /* Correct some things for UNIXWARE7 */ |
---|
37 | #ifdef HAVE_UNIXWARE7_THREADS |
---|
38 | #undef HAVE_STRINGS_H |
---|
39 | #undef HAVE_MEMORY_H |
---|
40 | #define HAVE_MEMCPY |
---|
41 | #ifndef HAVE_MEMMOVE |
---|
42 | #define HAVE_MEMMOVE |
---|
43 | #endif |
---|
44 | #undef HAVE_BCMP |
---|
45 | #undef bcopy |
---|
46 | #undef bcmp |
---|
47 | #undef bzero |
---|
48 | #endif /* HAVE_UNIXWARE7_THREADS */ |
---|
49 | #ifdef _AIX |
---|
50 | #undef HAVE_BCMP |
---|
51 | #endif |
---|
52 | |
---|
53 | /* This is needed for the definitions of bzero... on solaris */ |
---|
54 | #if defined(HAVE_STRINGS_H) && !defined(HAVE_mit_thread) |
---|
55 | #include <strings.h> |
---|
56 | #endif |
---|
57 | |
---|
58 | /* This is needed for the definitions of memcpy... on solaris */ |
---|
59 | #if defined(HAVE_MEMORY_H) && !defined(__cplusplus) |
---|
60 | #include <memory.h> |
---|
61 | #endif |
---|
62 | |
---|
63 | #if !defined(HAVE_MEMCPY) && !defined(HAVE_MEMMOVE) |
---|
64 | # define memcpy(d, s, n) bcopy ((s), (d), (n)) |
---|
65 | # define memset(A,C,B) bfill((A),(B),(C)) |
---|
66 | # define memmove(d, s, n) bmove ((d), (s), (n)) |
---|
67 | #elif defined(HAVE_MEMMOVE) |
---|
68 | # define bmove(d, s, n) memmove((d), (s), (n)) |
---|
69 | #else |
---|
70 | # define memmove(d, s, n) bmove((d), (s), (n)) /* our bmove */ |
---|
71 | #endif |
---|
72 | |
---|
73 | /* Unixware 7 */ |
---|
74 | #if !defined(HAVE_BFILL) |
---|
75 | # define bfill(A,B,C) memset((A),(C),(B)) |
---|
76 | # define bmove_align(A,B,C) memcpy((A),(B),(C)) |
---|
77 | #endif |
---|
78 | |
---|
79 | #if !defined(HAVE_BCMP) |
---|
80 | # define bcopy(s, d, n) memcpy((d), (s), (n)) |
---|
81 | # define bcmp(A,B,C) memcmp((A),(B),(C)) |
---|
82 | # define bzero(A,B) memset((A),0,(B)) |
---|
83 | # define bmove_align(A,B,C) memcpy((A),(B),(C)) |
---|
84 | #endif |
---|
85 | |
---|
86 | #if defined(__cplusplus) && !defined(OS2) |
---|
87 | extern "C" { |
---|
88 | #endif |
---|
89 | |
---|
90 | /* |
---|
91 | my_str_malloc() and my_str_free() are assigned to implementations in |
---|
92 | strings/alloc.c, but can be overridden in the calling program. |
---|
93 | */ |
---|
94 | extern void *(*my_str_malloc)(size_t); |
---|
95 | extern void (*my_str_free)(void *); |
---|
96 | |
---|
97 | #if defined(HAVE_STPCPY) && !defined(HAVE_mit_thread) |
---|
98 | #define strmov(A,B) stpcpy((A),(B)) |
---|
99 | #ifndef stpcpy |
---|
100 | extern char *stpcpy(char *, const char *); /* For AIX with gcc 2.95.3 */ |
---|
101 | #endif |
---|
102 | #endif |
---|
103 | |
---|
104 | /* Declared in int2str() */ |
---|
105 | extern char NEAR _dig_vec_upper[]; |
---|
106 | extern char NEAR _dig_vec_lower[]; |
---|
107 | |
---|
108 | /* Defined in strtod.c */ |
---|
109 | extern const double log_10[309]; |
---|
110 | |
---|
111 | #ifdef BAD_STRING_COMPILER |
---|
112 | #define strmov(A,B) (memccpy(A,B,0,INT_MAX)-1) |
---|
113 | #else |
---|
114 | #define strmov_overlapp(A,B) strmov(A,B) |
---|
115 | #define strmake_overlapp(A,B,C) strmake(A,B,C) |
---|
116 | #endif |
---|
117 | |
---|
118 | #ifdef BAD_MEMCPY /* Problem with gcc on Alpha */ |
---|
119 | #define memcpy_fixed(A,B,C) bmove((A),(B),(C)) |
---|
120 | #else |
---|
121 | #define memcpy_fixed(A,B,C) memcpy((A),(B),(C)) |
---|
122 | #endif |
---|
123 | |
---|
124 | #ifdef MSDOS |
---|
125 | #undef bmove_align |
---|
126 | #define bmove512(A,B,C) bmove_align(A,B,C) |
---|
127 | extern void bmove_align(gptr dst,const gptr src,uint len); |
---|
128 | #endif |
---|
129 | |
---|
130 | #if (!defined(USE_BMOVE512) || defined(HAVE_purify)) && !defined(bmove512) |
---|
131 | #define bmove512(A,B,C) memcpy(A,B,C) |
---|
132 | #endif |
---|
133 | |
---|
134 | /* Prototypes for string functions */ |
---|
135 | |
---|
136 | #if !defined(bfill) && !defined(HAVE_BFILL) |
---|
137 | extern void bfill(gptr dst,uint len,pchar fill); |
---|
138 | #endif |
---|
139 | |
---|
140 | #if !defined(bzero) && !defined(HAVE_BZERO) |
---|
141 | extern void bzero(gptr dst,uint len); |
---|
142 | #endif |
---|
143 | |
---|
144 | #if !defined(bcmp) && !defined(HAVE_BCMP) |
---|
145 | extern int bcmp(const char *s1,const char *s2,uint len); |
---|
146 | #endif |
---|
147 | #ifdef HAVE_purify |
---|
148 | extern int my_bcmp(const char *s1,const char *s2,uint len); |
---|
149 | #undef bcmp |
---|
150 | #define bcmp(A,B,C) my_bcmp((A),(B),(C)) |
---|
151 | #endif |
---|
152 | |
---|
153 | #ifndef bmove512 |
---|
154 | extern void bmove512(gptr dst,const gptr src,uint len); |
---|
155 | #endif |
---|
156 | |
---|
157 | #if !defined(HAVE_BMOVE) && !defined(bmove) |
---|
158 | extern void bmove(char *dst, const char *src,uint len); |
---|
159 | #endif |
---|
160 | |
---|
161 | extern void bmove_upp(char *dst,const char *src,uint len); |
---|
162 | extern void bchange(char *dst,uint old_len,const char *src, |
---|
163 | uint new_len,uint tot_len); |
---|
164 | extern void strappend(char *s,uint len,pchar fill); |
---|
165 | extern char *strend(const char *s); |
---|
166 | extern char *strcend(const char *, pchar); |
---|
167 | extern char *strfield(char *src,int fields,int chars,int blanks, |
---|
168 | int tabch); |
---|
169 | extern char *strfill(my_string s,uint len,pchar fill); |
---|
170 | extern uint strinstr(const char *str,const char *search); |
---|
171 | extern uint r_strinstr(reg1 my_string str,int from, reg4 my_string search); |
---|
172 | extern char *strkey(char *dst,char *head,char *tail,char *flags); |
---|
173 | extern char *strmake(char *dst,const char *src,uint length); |
---|
174 | #ifndef strmake_overlapp |
---|
175 | extern char *strmake_overlapp(char *dst,const char *src, uint length); |
---|
176 | #endif |
---|
177 | |
---|
178 | #ifndef strmov |
---|
179 | extern char *strmov(char *dst,const char *src); |
---|
180 | #endif |
---|
181 | extern char *strnmov(char *dst,const char *src,uint n); |
---|
182 | extern char *strsuff(const char *src,const char *suffix); |
---|
183 | extern char *strcont(const char *src,const char *set); |
---|
184 | extern char *strxcat _VARARGS((char *dst,const char *src, ...)); |
---|
185 | extern char *strxmov _VARARGS((char *dst,const char *src, ...)); |
---|
186 | extern char *strxcpy _VARARGS((char *dst,const char *src, ...)); |
---|
187 | extern char *strxncat _VARARGS((char *dst,uint len, const char *src, ...)); |
---|
188 | extern char *strxnmov _VARARGS((char *dst,uint len, const char *src, ...)); |
---|
189 | extern char *strxncpy _VARARGS((char *dst,uint len, const char *src, ...)); |
---|
190 | |
---|
191 | /* Prototypes of normal stringfunctions (with may ours) */ |
---|
192 | |
---|
193 | #ifdef WANT_STRING_PROTOTYPES |
---|
194 | extern char *strcat(char *, const char *); |
---|
195 | extern char *strchr(const char *, pchar); |
---|
196 | extern char *strrchr(const char *, pchar); |
---|
197 | extern char *strcpy(char *, const char *); |
---|
198 | extern int strcmp(const char *, const char *); |
---|
199 | #ifndef __GNUC__ |
---|
200 | extern size_t strlen(const char *); |
---|
201 | #endif |
---|
202 | #endif |
---|
203 | #ifndef HAVE_STRNLEN |
---|
204 | extern uint strnlen(const char *s, uint n); |
---|
205 | #endif |
---|
206 | |
---|
207 | #if !defined(__cplusplus) |
---|
208 | #ifndef HAVE_STRPBRK |
---|
209 | extern char *strpbrk(const char *, const char *); |
---|
210 | #endif |
---|
211 | #ifndef HAVE_STRSTR |
---|
212 | extern char *strstr(const char *, const char *); |
---|
213 | #endif |
---|
214 | #endif |
---|
215 | extern int is_prefix(const char *, const char *); |
---|
216 | |
---|
217 | /* Conversion routines */ |
---|
218 | double my_strtod(const char *str, char **end, int *error); |
---|
219 | double my_atof(const char *nptr); |
---|
220 | |
---|
221 | extern char *llstr(longlong value,char *buff); |
---|
222 | extern char *ullstr(longlong value,char *buff); |
---|
223 | #ifndef HAVE_STRTOUL |
---|
224 | extern long strtol(const char *str, char **ptr, int base); |
---|
225 | extern ulong strtoul(const char *str, char **ptr, int base); |
---|
226 | #endif |
---|
227 | |
---|
228 | extern char *int2str(long val, char *dst, int radix, int upcase); |
---|
229 | extern char *int10_to_str(long val,char *dst,int radix); |
---|
230 | extern char *str2int(const char *src,int radix,long lower,long upper, |
---|
231 | long *val); |
---|
232 | longlong my_strtoll10(const char *nptr, char **endptr, int *error); |
---|
233 | #if SIZEOF_LONG == SIZEOF_LONG_LONG |
---|
234 | #define longlong2str(A,B,C) int2str((A),(B),(C),1) |
---|
235 | #define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C)) |
---|
236 | #undef strtoll |
---|
237 | #define strtoll(A,B,C) strtol((A),(B),(C)) |
---|
238 | #define strtoull(A,B,C) strtoul((A),(B),(C)) |
---|
239 | #ifndef HAVE_STRTOULL |
---|
240 | #define HAVE_STRTOULL |
---|
241 | #endif |
---|
242 | #ifndef HAVE_STRTOLL |
---|
243 | #define HAVE_STRTOLL |
---|
244 | #endif |
---|
245 | #else |
---|
246 | #ifdef HAVE_LONG_LONG |
---|
247 | extern char *longlong2str(longlong val,char *dst,int radix); |
---|
248 | extern char *longlong10_to_str(longlong val,char *dst,int radix); |
---|
249 | #if (!defined(HAVE_STRTOULL) || defined(HAVE_mit_thread)) || defined(NO_STRTOLL_PROTO) |
---|
250 | extern longlong strtoll(const char *str, char **ptr, int base); |
---|
251 | extern ulonglong strtoull(const char *str, char **ptr, int base); |
---|
252 | #endif |
---|
253 | #endif |
---|
254 | #endif |
---|
255 | |
---|
256 | /* my_vsnprintf.c */ |
---|
257 | |
---|
258 | extern int my_vsnprintf( char *str, size_t n, |
---|
259 | const char *format, va_list ap ); |
---|
260 | extern int my_snprintf(char *to, size_t n, const char *fmt, ...) |
---|
261 | ATTRIBUTE_FORMAT(printf, 3, 4); |
---|
262 | |
---|
263 | #if defined(__cplusplus) && !defined(OS2) |
---|
264 | } |
---|
265 | #endif |
---|
266 | #endif |
---|