summaryrefslogtreecommitdiff
path: root/include/m_string.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/m_string.h')
-rw-r--r--include/m_string.h158
1 files changed, 57 insertions, 101 deletions
diff --git a/include/m_string.h b/include/m_string.h
index e818d339fcb..7c95c7319dc 100644
--- a/include/m_string.h
+++ b/include/m_string.h
@@ -12,8 +12,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/* There may be prolems include all of theese. Try to test in
configure with ones are needed? */
@@ -22,6 +21,9 @@
#ifndef _m_string_h
#define _m_string_h
+
+#include "my_global.h" /* HAVE_* */
+
#ifndef __USE_GNU
#define __USE_GNU /* We want to use stpcpy */
#endif
@@ -51,8 +53,6 @@
# define memmove(d, s, n) bmove ((d), (s), (n))
#elif defined(HAVE_MEMMOVE)
# define bmove(d, s, n) memmove((d), (s), (n))
-#else
-# define memmove(d, s, n) bmove((d), (s), (n)) /* our bmove */
#endif
/* Unixware 7 */
@@ -85,62 +85,21 @@ extern void (*my_str_free)(void *);
#define strmov(A,B) __builtin_stpcpy((A),(B))
#elif defined(HAVE_STPCPY)
#define strmov(A,B) stpcpy((A),(B))
-#ifndef stpcpy
-extern char *stpcpy(char *, const char *); /* For AIX with gcc 2.95.3 */
-#endif
#endif
/* Declared in int2str() */
-extern const char NEAR _dig_vec_upper[];
-extern const char NEAR _dig_vec_lower[];
-
-/* Defined in strtod.c */
-extern const double log_10[309];
+extern const char _dig_vec_upper[];
+extern const char _dig_vec_lower[];
extern char *strmov_overlapp(char *dest, const char *src);
-#ifdef BAD_MEMCPY /* Problem with gcc on Alpha */
-#define memcpy_fixed(A,B,C) bmove((A),(B),(C))
-#else
-#define memcpy_fixed(A,B,C) memcpy((A),(B),(C))
-#endif
-
-#if (!defined(USE_BMOVE512) || defined(HAVE_valgrind)) && !defined(bmove512)
-#define bmove512(A,B,C) memcpy(A,B,C)
-#endif
-
- /* Prototypes for string functions */
-
-#if !defined(bfill) && !defined(HAVE_BFILL)
-extern void bfill(uchar *dst,size_t len,pchar fill);
-#endif
-
-#if !defined(bzero) && !defined(HAVE_BZERO)
-extern void bzero(void * dst,size_t len);
-#endif
-
-#if !defined(bcmp) && !defined(HAVE_BCMP)
-extern size_t bcmp(const uchar *s1,const uchar *s2,size_t len);
-#endif
-#ifdef HAVE_valgrind
-extern size_t my_bcmp(const uchar *s1,const uchar *s2,size_t len);
-#undef bcmp
-#define bcmp(A,B,C) my_bcmp((A),(B),(C))
-#endif /* HAVE_valgrind */
-
#if defined(_lint) || defined(FORCE_INIT_OF_VARS)
#define LINT_INIT_STRUCT(var) bzero(&var, sizeof(var)) /* No uninitialize-warning */
#else
#define LINT_INIT_STRUCT(var)
#endif
-#ifndef bmove512
-extern void bmove512(uchar *dst,const uchar *src,size_t len);
-#endif
-
-#if !defined(HAVE_BMOVE) && !defined(bmove)
-extern void bmove(uuchar *dst, const uchar *src,size_t len);
-#endif
+/* Prototypes for string functions */
extern void bmove_upp(uchar *dst,const uchar *src,size_t len);
extern void bchange(uchar *dst,size_t old_len,const uchar *src,
@@ -148,66 +107,62 @@ extern void bchange(uchar *dst,size_t old_len,const uchar *src,
extern void strappend(char *s,size_t len,pchar fill);
extern char *strend(const char *s);
extern char *strcend(const char *, pchar);
-extern char *strfield(char *src,int fields,int chars,int blanks,
- int tabch);
extern char *strfill(char * s,size_t len,pchar fill);
-extern size_t strinstr(const char *str,const char *search);
-extern size_t r_strinstr(const char *str, size_t from, const char *search);
-extern char *strkey(char *dst,char *head,char *tail,char *flags);
extern char *strmake(char *dst,const char *src,size_t length);
#ifndef strmov
extern char *strmov(char *dst,const char *src);
#endif
-extern char *strnmov(char *dst,const char *src,size_t n);
-extern char *strsuff(const char *src,const char *suffix);
-extern char *strcont(const char *src,const char *set);
-extern char *strxcat _VARARGS((char *dst,const char *src, ...));
-extern char *strxmov _VARARGS((char *dst,const char *src, ...));
-extern char *strxcpy _VARARGS((char *dst,const char *src, ...));
-extern char *strxncat _VARARGS((char *dst,size_t len, const char *src, ...));
-extern char *strxnmov _VARARGS((char *dst,size_t len, const char *src, ...));
-extern char *strxncpy _VARARGS((char *dst,size_t len, const char *src, ...));
+extern char *strnmov(char *dst, const char *src, size_t n);
+extern char *strcont(const char *src, const char *set);
+extern char *strxmov(char *dst, const char *src, ...);
+extern char *strxnmov(char *dst, size_t len, const char *src, ...);
/* Prototypes of normal stringfunctions (with may ours) */
-
-#ifdef WANT_STRING_PROTOTYPES
-extern char *strcat(char *, const char *);
-extern char *strchr(const char *, pchar);
-extern char *strrchr(const char *, pchar);
-extern char *strcpy(char *, const char *);
-extern int strcmp(const char *, const char *);
-#ifndef __GNUC__
-extern size_t strlen(const char *);
-#endif
-#endif
#ifndef HAVE_STRNLEN
extern size_t strnlen(const char *s, size_t n);
#endif
-#if !defined(__cplusplus)
-#ifndef HAVE_STRPBRK
-extern char *strpbrk(const char *, const char *);
-#endif
-#ifndef HAVE_STRSTR
-extern char *strstr(const char *, const char *);
-#endif
-#endif
extern int is_prefix(const char *, const char *);
/* Conversion routines */
+typedef enum {
+ MY_GCVT_ARG_FLOAT,
+ MY_GCVT_ARG_DOUBLE
+} my_gcvt_arg_type;
+
double my_strtod(const char *str, char **end, int *error);
double my_atof(const char *nptr);
+size_t my_fcvt(double x, int precision, char *to, my_bool *error);
+size_t my_gcvt(double x, my_gcvt_arg_type type, int width, char *to,
+ my_bool *error);
-#ifndef NOT_FIXED_DEC
-#define NOT_FIXED_DEC 31
-#endif
+#define NOT_FIXED_DEC 31
/*
- Max length of a floating point number.
- */
+ The longest string my_fcvt can return is 311 + "precision" bytes.
+ Here we assume that we never cal my_fcvt() with precision >= NOT_FIXED_DEC
+ (+ 1 byte for the terminating '\0').
+*/
#define FLOATING_POINT_BUFFER (311 + NOT_FIXED_DEC)
+/*
+ We want to use the 'e' format in some cases even if we have enough space
+ for the 'f' one just to mimic sprintf("%.15g") behavior for large integers,
+ and to improve it for numbers < 10^(-4).
+ That is, for |x| < 1 we require |x| >= 10^(-15), and for |x| > 1 we require
+ it to be integer and be <= 10^DBL_DIG for the 'f' format to be used.
+ We don't lose precision, but make cases like "1e200" or "0.00001" look nicer.
+*/
+#define MAX_DECPT_FOR_F_FORMAT DBL_DIG
+
+/*
+ The maximum possible field width for my_gcvt() conversion.
+ (DBL_DIG + 2) significant digits + sign + "." + ("e-NNN" or
+ MAX_DECPT_FOR_F_FORMAT zeros for cases when |x|<1 and the 'f' format is used).
+*/
+#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + max(5, MAX_DECPT_FOR_F_FORMAT)) \
+
extern char *llstr(longlong value,char *buff);
extern char *ullstr(longlong value,char *buff);
#ifndef HAVE_STRTOUL
@@ -221,7 +176,7 @@ extern char *str2int(const char *src,int radix,long lower,long upper,
long *val);
longlong my_strtoll10(const char *nptr, char **endptr, int *error);
#if SIZEOF_LONG == SIZEOF_LONG_LONG
-#define longlong2str(A,B,C,D) int2str((A),(B),(C),(D))
+#define ll2str(A,B,C,D) int2str((A),(B),(C),(D))
#define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C))
#undef strtoll
#define strtoll(A,B,C) strtol((A),(B),(C))
@@ -234,7 +189,7 @@ longlong my_strtoll10(const char *nptr, char **endptr, int *error);
#endif
#else
#ifdef HAVE_LONG_LONG
-extern char *longlong2str(longlong val,char *dst,int radix, int upcase);
+extern char *ll2str(longlong val,char *dst,int radix, int upcase);
extern char *longlong10_to_str(longlong val,char *dst,int radix);
#if (!defined(HAVE_STRTOULL) || defined(NO_STRTOLL_PROTO))
extern longlong strtoll(const char *str, char **ptr, int base);
@@ -242,30 +197,25 @@ extern ulonglong strtoull(const char *str, char **ptr, int base);
#endif
#endif
#endif
-
-/* my_vsnprintf.c */
-
-extern size_t my_vsnprintf(char *str, size_t n,
- const char *format, va_list ap);
-extern size_t my_snprintf(char *to, size_t n, const char *fmt, ...)
- ATTRIBUTE_FORMAT(printf, 3, 4);
+#define longlong2str(A,B,C) ll2str((A),(B),(C),1)
#if defined(__cplusplus)
}
#endif
-/*
- LEX_STRING -- a pair of a C-string and its length.
- (it's part of the plugin API as a MYSQL_LEX_STRING)
-*/
-
#include <mysql/plugin.h>
-typedef struct st_mysql_lex_string LEX_STRING;
#define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1))
#define USTRING_WITH_LEN(X) ((uchar*) X), ((size_t) (sizeof(X) - 1))
#define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1))
+struct st_mysql_const_lex_string
+{
+ const char *str;
+ size_t length;
+};
+typedef struct st_mysql_const_lex_string LEX_CSTRING;
+
/* A variant with const and unsigned */
struct st_mysql_const_unsigned_lex_string
{
@@ -274,4 +224,10 @@ struct st_mysql_const_unsigned_lex_string
};
typedef struct st_mysql_const_unsigned_lex_string LEX_CUSTRING;
+static inline void lex_string_set(LEX_STRING *lex_str, const char *c_str)
+{
+ lex_str->str= (char *) c_str;
+ lex_str->length= strlen(c_str);
+}
+
#endif