Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../usr/include/mysql/server
File: m_string.h
/*
[0] Fix | Delete
Copyright (c) 2000, 2012, Oracle and/or its affiliates.
[1] Fix | Delete
Copyright (c) 2019, 2021, MariaDB Corporation.
[2] Fix | Delete
[3] Fix | Delete
This program is free software; you can redistribute it and/or modify
[4] Fix | Delete
it under the terms of the GNU General Public License as published by
[5] Fix | Delete
the Free Software Foundation; version 2 of the License.
[6] Fix | Delete
[7] Fix | Delete
This program is distributed in the hope that it will be useful,
[8] Fix | Delete
but WITHOUT ANY WARRANTY; without even the implied warranty of
[9] Fix | Delete
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[10] Fix | Delete
GNU General Public License for more details.
[11] Fix | Delete
[12] Fix | Delete
You should have received a copy of the GNU General Public License
[13] Fix | Delete
along with this program; if not, write to the Free Software
[14] Fix | Delete
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
[15] Fix | Delete
[16] Fix | Delete
/* There may be problems included in all of these. Try to test in
[17] Fix | Delete
configure which ones are needed? */
[18] Fix | Delete
[19] Fix | Delete
/* This is needed for the definitions of strchr... on solaris */
[20] Fix | Delete
[21] Fix | Delete
#ifndef _m_string_h
[22] Fix | Delete
#define _m_string_h
[23] Fix | Delete
[24] Fix | Delete
#include "my_decimal_limits.h"
[25] Fix | Delete
[26] Fix | Delete
#ifndef __USE_GNU
[27] Fix | Delete
#define __USE_GNU /* We want to use stpcpy */
[28] Fix | Delete
#endif
[29] Fix | Delete
#if defined(HAVE_STRINGS_H)
[30] Fix | Delete
#include <strings.h>
[31] Fix | Delete
#endif
[32] Fix | Delete
#if defined(HAVE_STRING_H)
[33] Fix | Delete
#include <string.h>
[34] Fix | Delete
#endif
[35] Fix | Delete
[36] Fix | Delete
/* This is needed for the definitions of memcpy... on solaris */
[37] Fix | Delete
#if defined(HAVE_MEMORY_H) && !defined(__cplusplus)
[38] Fix | Delete
#include <memory.h>
[39] Fix | Delete
#endif
[40] Fix | Delete
[41] Fix | Delete
#if !defined(HAVE_MEMCPY) && !defined(HAVE_MEMMOVE)
[42] Fix | Delete
# define memcpy(d, s, n) bcopy ((s), (d), (n))
[43] Fix | Delete
# define memset(A,C,B) bfill((A),(B),(C))
[44] Fix | Delete
# define memmove(d, s, n) bmove ((d), (s), (n))
[45] Fix | Delete
#elif defined(HAVE_MEMMOVE)
[46] Fix | Delete
# define bmove(d, s, n) memmove((d), (s), (n))
[47] Fix | Delete
#endif
[48] Fix | Delete
[49] Fix | Delete
/* Unixware 7 */
[50] Fix | Delete
#if !defined(HAVE_BFILL)
[51] Fix | Delete
# define bfill(A,B,C) memset((A),(C),(B))
[52] Fix | Delete
#endif
[53] Fix | Delete
[54] Fix | Delete
# define bmove_align(A,B,C) memcpy((A),(B),(C))
[55] Fix | Delete
[56] Fix | Delete
# define bcmp(A,B,C) memcmp((A),(B),(C))
[57] Fix | Delete
[58] Fix | Delete
#if !defined(bzero)
[59] Fix | Delete
# define bzero(A,B) memset((A),0,(B))
[60] Fix | Delete
#endif
[61] Fix | Delete
[62] Fix | Delete
#if defined(__cplusplus)
[63] Fix | Delete
extern "C" {
[64] Fix | Delete
#endif
[65] Fix | Delete
[66] Fix | Delete
#ifdef DBUG_OFF
[67] Fix | Delete
#if defined(HAVE_STPCPY) && defined(__GNUC__) && !defined(__INTEL_COMPILER)
[68] Fix | Delete
#define strmov(A,B) __builtin_stpcpy((A),(B))
[69] Fix | Delete
#elif defined(HAVE_STPCPY)
[70] Fix | Delete
#define strmov(A,B) stpcpy((A),(B))
[71] Fix | Delete
#endif
[72] Fix | Delete
#endif
[73] Fix | Delete
[74] Fix | Delete
/* Declared in int2str() */
[75] Fix | Delete
extern const char _dig_vec_upper[];
[76] Fix | Delete
extern const char _dig_vec_lower[];
[77] Fix | Delete
[78] Fix | Delete
extern char *strmov_overlapp(char *dest, const char *src);
[79] Fix | Delete
[80] Fix | Delete
#if defined(_lint) || defined(FORCE_INIT_OF_VARS)
[81] Fix | Delete
#define LINT_INIT_STRUCT(var) bzero(&var, sizeof(var)) /* No uninitialize-warning */
[82] Fix | Delete
#else
[83] Fix | Delete
#define LINT_INIT_STRUCT(var)
[84] Fix | Delete
#endif
[85] Fix | Delete
[86] Fix | Delete
/* Prototypes for string functions */
[87] Fix | Delete
[88] Fix | Delete
extern void bmove_upp(uchar *dst,const uchar *src,size_t len);
[89] Fix | Delete
extern void bchange(uchar *dst,size_t old_len,const uchar *src,
[90] Fix | Delete
size_t new_len,size_t tot_len);
[91] Fix | Delete
extern void strappend(char *s,size_t len,pchar fill);
[92] Fix | Delete
extern char *strend(const char *s);
[93] Fix | Delete
extern char *strcend(const char *, pchar);
[94] Fix | Delete
extern char *strfill(char * s,size_t len,pchar fill);
[95] Fix | Delete
extern char *strmake(char *dst,const char *src,size_t length);
[96] Fix | Delete
[97] Fix | Delete
#if !defined(__GNUC__) || (__GNUC__ < 4)
[98] Fix | Delete
#define strmake_buf(D,S) strmake(D, S, sizeof(D) - 1)
[99] Fix | Delete
#else
[100] Fix | Delete
#define strmake_buf(D,S) ({ \
[101] Fix | Delete
__typeof__ (D) __x __attribute__((unused)) = { 2 }; \
[102] Fix | Delete
strmake(D, S, sizeof(D) - 1); \
[103] Fix | Delete
})
[104] Fix | Delete
#endif
[105] Fix | Delete
[106] Fix | Delete
#ifndef strmov
[107] Fix | Delete
extern char *strmov(char *dst,const char *src);
[108] Fix | Delete
#endif
[109] Fix | Delete
extern char *strnmov(char *dst, const char *src, size_t n);
[110] Fix | Delete
extern char *strcont(const char *src, const char *set);
[111] Fix | Delete
extern char *strxmov(char *dst, const char *src, ...);
[112] Fix | Delete
extern char *strxnmov(char *dst, size_t len, const char *src, ...);
[113] Fix | Delete
[114] Fix | Delete
/* Prototypes of normal stringfunctions (with may ours) */
[115] Fix | Delete
#ifndef HAVE_STRNLEN
[116] Fix | Delete
extern size_t strnlen(const char *s, size_t n);
[117] Fix | Delete
#endif
[118] Fix | Delete
[119] Fix | Delete
extern int is_prefix(const char *, const char *);
[120] Fix | Delete
[121] Fix | Delete
/* Conversion routines */
[122] Fix | Delete
typedef enum {
[123] Fix | Delete
MY_GCVT_ARG_FLOAT,
[124] Fix | Delete
MY_GCVT_ARG_DOUBLE
[125] Fix | Delete
} my_gcvt_arg_type;
[126] Fix | Delete
[127] Fix | Delete
double my_strtod(const char *str, char **end, int *error);
[128] Fix | Delete
double my_atof(const char *nptr);
[129] Fix | Delete
size_t my_fcvt(double x, int precision, char *to, my_bool *error);
[130] Fix | Delete
size_t my_gcvt(double x, my_gcvt_arg_type type, int width, char *to,
[131] Fix | Delete
my_bool *error);
[132] Fix | Delete
[133] Fix | Delete
/*
[134] Fix | Delete
The longest string my_fcvt can return is 311 + "precision" bytes.
[135] Fix | Delete
Here we assume that we never cal my_fcvt() with
[136] Fix | Delete
precision >= DECIMAL_NOT_SPECIFIED
[137] Fix | Delete
(+ 1 byte for the terminating '\0').
[138] Fix | Delete
*/
[139] Fix | Delete
#define FLOATING_POINT_BUFFER (311 + DECIMAL_NOT_SPECIFIED)
[140] Fix | Delete
[141] Fix | Delete
/*
[142] Fix | Delete
We want to use the 'e' format in some cases even if we have enough space
[143] Fix | Delete
for the 'f' one just to mimic sprintf("%.15g") behavior for large integers,
[144] Fix | Delete
and to improve it for numbers < 10^(-4).
[145] Fix | Delete
That is, for |x| < 1 we require |x| >= 10^(-15), and for |x| > 1 we require
[146] Fix | Delete
it to be integer and be <= 10^DBL_DIG for the 'f' format to be used.
[147] Fix | Delete
We don't lose precision, but make cases like "1e200" or "0.00001" look nicer.
[148] Fix | Delete
*/
[149] Fix | Delete
#define MAX_DECPT_FOR_F_FORMAT DBL_DIG
[150] Fix | Delete
[151] Fix | Delete
/*
[152] Fix | Delete
The maximum possible field width for my_gcvt() conversion.
[153] Fix | Delete
(DBL_DIG + 2) significant digits + sign + "." + ("e-NNN" or
[154] Fix | Delete
MAX_DECPT_FOR_F_FORMAT zeros for cases when |x|<1 and the 'f' format is used).
[155] Fix | Delete
*/
[156] Fix | Delete
#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + MY_MAX(5, MAX_DECPT_FOR_F_FORMAT)) \
[157] Fix | Delete
[158] Fix | Delete
extern char *llstr(longlong value,char *buff);
[159] Fix | Delete
extern char *ullstr(longlong value,char *buff);
[160] Fix | Delete
#ifndef HAVE_STRTOUL
[161] Fix | Delete
extern long strtol(const char *str, char **ptr, int base);
[162] Fix | Delete
extern ulong strtoul(const char *str, char **ptr, int base);
[163] Fix | Delete
#endif
[164] Fix | Delete
[165] Fix | Delete
extern char *int2str(long val, char *dst, int radix, int upcase);
[166] Fix | Delete
extern char *int10_to_str(long val,char *dst,int radix);
[167] Fix | Delete
extern char *str2int(const char *src,int radix,long lower,long upper,
[168] Fix | Delete
long *val);
[169] Fix | Delete
longlong my_strtoll10(const char *nptr, char **endptr, int *error);
[170] Fix | Delete
#if SIZEOF_LONG == SIZEOF_LONG_LONG
[171] Fix | Delete
#define ll2str(A,B,C,D) int2str((A),(B),(C),(D))
[172] Fix | Delete
#define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C))
[173] Fix | Delete
#undef strtoll
[174] Fix | Delete
#define strtoll(A,B,C) strtol((A),(B),(C))
[175] Fix | Delete
#define strtoull(A,B,C) strtoul((A),(B),(C))
[176] Fix | Delete
#ifndef HAVE_STRTOULL
[177] Fix | Delete
#define HAVE_STRTOULL
[178] Fix | Delete
#endif
[179] Fix | Delete
#ifndef HAVE_STRTOLL
[180] Fix | Delete
#define HAVE_STRTOLL
[181] Fix | Delete
#endif
[182] Fix | Delete
#else
[183] Fix | Delete
#ifdef HAVE_LONG_LONG
[184] Fix | Delete
extern char *ll2str(longlong val,char *dst,int radix, int upcase);
[185] Fix | Delete
extern char *longlong10_to_str(longlong val,char *dst,int radix);
[186] Fix | Delete
#if (!defined(HAVE_STRTOULL) || defined(NO_STRTOLL_PROTO))
[187] Fix | Delete
extern longlong strtoll(const char *str, char **ptr, int base);
[188] Fix | Delete
extern ulonglong strtoull(const char *str, char **ptr, int base);
[189] Fix | Delete
#endif
[190] Fix | Delete
#endif
[191] Fix | Delete
#endif
[192] Fix | Delete
#define longlong2str(A,B,C) ll2str((A),(B),(C),1)
[193] Fix | Delete
[194] Fix | Delete
#if defined(__cplusplus)
[195] Fix | Delete
}
[196] Fix | Delete
#endif
[197] Fix | Delete
[198] Fix | Delete
#include <mysql/plugin.h>
[199] Fix | Delete
[200] Fix | Delete
#ifdef __cplusplus
[201] Fix | Delete
#include <type_traits>
[202] Fix | Delete
template<typename T> inline const char *_swl_check(T s)
[203] Fix | Delete
{
[204] Fix | Delete
static_assert(std::is_same<T, const char (&)[sizeof(T)]>::value
[205] Fix | Delete
|| std::is_same<T, const char [sizeof(T)]>::value,
[206] Fix | Delete
"Wrong argument for STRING_WITH_LEN()");
[207] Fix | Delete
return s;
[208] Fix | Delete
}
[209] Fix | Delete
#define STRING_WITH_LEN(X) _swl_check<decltype(X)>(X), ((size_t) (sizeof(X) - 1))
[210] Fix | Delete
#else
[211] Fix | Delete
#define STRING_WITH_LEN(X) (X ""), ((size_t) (sizeof(X) - 1))
[212] Fix | Delete
#endif
[213] Fix | Delete
[214] Fix | Delete
#define USTRING_WITH_LEN(X) (uchar*) STRING_WITH_LEN(X)
[215] Fix | Delete
#define C_STRING_WITH_LEN(X) (char *) STRING_WITH_LEN(X)
[216] Fix | Delete
#define LEX_STRING_WITH_LEN(X) (X).str, (X).length
[217] Fix | Delete
[218] Fix | Delete
typedef struct st_mysql_const_lex_string LEX_CSTRING;
[219] Fix | Delete
[220] Fix | Delete
/* A variant with const and unsigned */
[221] Fix | Delete
struct st_mysql_const_unsigned_lex_string
[222] Fix | Delete
{
[223] Fix | Delete
const uchar *str;
[224] Fix | Delete
size_t length;
[225] Fix | Delete
};
[226] Fix | Delete
typedef struct st_mysql_const_unsigned_lex_string LEX_CUSTRING;
[227] Fix | Delete
[228] Fix | Delete
static inline void lex_string_set(LEX_CSTRING *lex_str, const char *c_str)
[229] Fix | Delete
{
[230] Fix | Delete
lex_str->str= c_str;
[231] Fix | Delete
lex_str->length= strlen(c_str);
[232] Fix | Delete
}
[233] Fix | Delete
static inline void lex_string_set3(LEX_CSTRING *lex_str, const char *c_str,
[234] Fix | Delete
size_t len)
[235] Fix | Delete
{
[236] Fix | Delete
lex_str->str= c_str;
[237] Fix | Delete
lex_str->length= len;
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
/**
[241] Fix | Delete
Copies a string.
[242] Fix | Delete
[243] Fix | Delete
@param dst destination buffer, will be NUL padded.
[244] Fix | Delete
@param dst_size size of dst buffer, must be > 0
[245] Fix | Delete
@param src NUL terminated source string
[246] Fix | Delete
*/
[247] Fix | Delete
static inline void safe_strcpy(char *dst, size_t dst_size, const char *src)
[248] Fix | Delete
{
[249] Fix | Delete
DBUG_ASSERT(dst_size > 0);
[250] Fix | Delete
[251] Fix | Delete
/* 1) IF there is a 0 byte in the first dst_size bytes of src, strncpy will
[252] Fix | Delete
* 0-terminate dst, and pad dst with additional 0 bytes out to dst_size.
[253] Fix | Delete
*
[254] Fix | Delete
* 2) IF there is no 0 byte in the first dst_size bytes of src, strncpy will
[255] Fix | Delete
* copy dst_size bytes, and the final byte won't be 0.
[256] Fix | Delete
*
[257] Fix | Delete
* In GCC 8+, the `-Wstringop-truncation` warning may object to strncpy()
[258] Fix | Delete
* being used in this way, so we need to disable this warning for this
[259] Fix | Delete
* single statement.
[260] Fix | Delete
*/
[261] Fix | Delete
[262] Fix | Delete
#if defined __GNUC__ && __GNUC__ >= 8
[263] Fix | Delete
#pragma GCC diagnostic push
[264] Fix | Delete
#pragma GCC diagnostic ignored "-Wstringop-truncation"
[265] Fix | Delete
#endif
[266] Fix | Delete
strncpy(dst, src, dst_size);
[267] Fix | Delete
#if defined __GNUC__ && __GNUC__ >= 8
[268] Fix | Delete
#pragma GCC diagnostic pop
[269] Fix | Delete
#endif
[270] Fix | Delete
dst[dst_size - 1]= 0;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
Copies a string, checking for truncation.
[275] Fix | Delete
[276] Fix | Delete
@param dst destination buffer, will be NUL padded.
[277] Fix | Delete
@param dst_size size of dst buffer, must be > 0
[278] Fix | Delete
@param src NUL terminated source string
[279] Fix | Delete
[280] Fix | Delete
@retval 1 if the src string was truncated due to too small size of dst.
[281] Fix | Delete
@retval 0 if src completely fit within dst,
[282] Fix | Delete
*/
[283] Fix | Delete
static inline int safe_strcpy_truncated(char *dst, size_t dst_size,
[284] Fix | Delete
const char *src)
[285] Fix | Delete
{
[286] Fix | Delete
[287] Fix | Delete
DBUG_ASSERT(dst_size > 0);
[288] Fix | Delete
if (dst_size == 0)
[289] Fix | Delete
return 1;
[290] Fix | Delete
/*
[291] Fix | Delete
We do not want to use strncpy() as we do not want to rely on
[292] Fix | Delete
strncpy() filling the unused dst with 0.
[293] Fix | Delete
We cannot use strmake() here as it in debug mode fills the buffers
[294] Fix | Delete
with 'Z'.
[295] Fix | Delete
*/
[296] Fix | Delete
if (strnmov(dst, src, dst_size) == dst+dst_size)
[297] Fix | Delete
{
[298] Fix | Delete
dst[dst_size-1]= 0;
[299] Fix | Delete
return 1;
[300] Fix | Delete
}
[301] Fix | Delete
return 0;
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
/**
[305] Fix | Delete
Appends src to dst and ensures dst is a NUL terminated C string.
[306] Fix | Delete
[307] Fix | Delete
@retval 1 if the src string was truncated due to too small size of dst.
[308] Fix | Delete
@retval 0 if src completely fit within the remaining dst space,
[309] Fix | Delete
including NUL termination.
[310] Fix | Delete
*/
[311] Fix | Delete
static inline int safe_strcat(char *dst, size_t dst_size, const char *src)
[312] Fix | Delete
{
[313] Fix | Delete
size_t init_len= strlen(dst);
[314] Fix | Delete
if (init_len >= dst_size)
[315] Fix | Delete
return 1;
[316] Fix | Delete
return safe_strcpy_truncated(dst + init_len, dst_size - init_len, src);
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
#ifdef __cplusplus
[320] Fix | Delete
static inline char *safe_str(char *str)
[321] Fix | Delete
{ return str ? str : const_cast<char*>(""); }
[322] Fix | Delete
#endif
[323] Fix | Delete
[324] Fix | Delete
static inline const char *safe_str(const char *str)
[325] Fix | Delete
{ return str ? str : ""; }
[326] Fix | Delete
[327] Fix | Delete
static inline size_t safe_strlen(const char *str)
[328] Fix | Delete
{ return str ? strlen(str) : 0; }
[329] Fix | Delete
[330] Fix | Delete
#endif
[331] Fix | Delete
[332] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function