/src/mysql-server/include/m_string.h
Line | Count | Source |
1 | | /* |
2 | | Copyright (c) 2000, 2025, Oracle and/or its affiliates. |
3 | | |
4 | | This program is free software; you can redistribute it and/or modify |
5 | | it under the terms of the GNU General Public License, version 2.0, |
6 | | as published by the Free Software Foundation. |
7 | | |
8 | | This program is designed to work with certain software (including |
9 | | but not limited to OpenSSL) that is licensed under separate terms, |
10 | | as designated in a particular file or component or in included license |
11 | | documentation. The authors of MySQL hereby grant you an additional |
12 | | permission to link the program and your derivative works with the |
13 | | separately licensed software that they have either included with |
14 | | the program or referenced in the documentation. |
15 | | |
16 | | This program is distributed in the hope that it will be useful, |
17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | | GNU General Public License, version 2.0, for more details. |
20 | | |
21 | | You should have received a copy of the GNU General Public License |
22 | | along with this program; if not, write to the Free Software |
23 | | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
24 | | |
25 | | #ifndef M_STRING_INCLUDED |
26 | | #define M_STRING_INCLUDED |
27 | | |
28 | | /** |
29 | | @file include/m_string.h |
30 | | */ |
31 | | |
32 | | /* |
33 | | This file is for trivial constant definitions and in-line wrappers only. |
34 | | |
35 | | Please don't add new stuff to this file unnecessarily. |
36 | | */ |
37 | | |
38 | | #include <float.h> |
39 | | #include <limits.h> |
40 | | #include <stdbool.h> // IWYU pragma: keep |
41 | | #include <stdint.h> |
42 | | #include <stdio.h> |
43 | | #include <stdlib.h> |
44 | | #include <string.h> |
45 | | |
46 | | #include <algorithm> |
47 | | #include <cstdint> |
48 | | |
49 | | #include "lex_string.h" |
50 | | #include "my_config.h" |
51 | | |
52 | | /* |
53 | | bchange(dst, old_length, src, new_length, tot_length) |
54 | | replaces old_length characters at dst to new_length characters from |
55 | | src in a buffer with tot_length bytes. |
56 | | */ |
57 | | static inline void bchange(uint8_t *dst, size_t old_length, const uint8_t *src, |
58 | 0 | size_t new_length, size_t tot_length) { |
59 | 0 | memmove(dst + new_length, dst + old_length, tot_length - old_length); |
60 | 0 | memcpy(dst, src, new_length); |
61 | 0 | } Unexecuted instantiation: charset.cc:bchange(unsigned char*, unsigned long, unsigned char const*, unsigned long, unsigned long) Unexecuted instantiation: my_getwd.cc:bchange(unsigned char*, unsigned long, unsigned char const*, unsigned long, unsigned long) Unexecuted instantiation: my_lib.cc:bchange(unsigned char*, unsigned long, unsigned char const*, unsigned long, unsigned long) Unexecuted instantiation: mf_pack.cc:bchange(unsigned char*, unsigned long, unsigned char const*, unsigned long, unsigned long) Unexecuted instantiation: ctype-bin.cc:bchange(unsigned char*, unsigned long, unsigned char const*, unsigned long, unsigned long) Unexecuted instantiation: ctype-latin1.cc:bchange(unsigned char*, unsigned long, unsigned char const*, unsigned long, unsigned long) Unexecuted instantiation: ctype-mb.cc:bchange(unsigned char*, unsigned long, unsigned char const*, unsigned long, unsigned long) Unexecuted instantiation: ctype-simple.cc:bchange(unsigned char*, unsigned long, unsigned char const*, unsigned long, unsigned long) Unexecuted instantiation: ctype-uca.cc:bchange(unsigned char*, unsigned long, unsigned char const*, unsigned long, unsigned long) |
62 | | |
63 | | /* |
64 | | strend(s) returns a character pointer to the NUL which ends s. That |
65 | | is, strend(s)-s == strlen(s). This is useful for adding things at |
66 | | the end of strings. It is redundant, because strchr(s,'\0') could |
67 | | be used instead, but this is clearer and faster. |
68 | | */ |
69 | 0 | static inline const char *strend(const char *s) { |
70 | 0 | while (*s++) { |
71 | 0 | } |
72 | 0 | return s - 1; |
73 | 0 | } Unexecuted instantiation: charset.cc:strend(char const*) Unexecuted instantiation: my_getwd.cc:strend(char const*) Unexecuted instantiation: my_lib.cc:strend(char const*) Unexecuted instantiation: mf_pack.cc:strend(char const*) Unexecuted instantiation: ctype-bin.cc:strend(char const*) Unexecuted instantiation: ctype-latin1.cc:strend(char const*) Unexecuted instantiation: ctype-mb.cc:strend(char const*) Unexecuted instantiation: ctype-simple.cc:strend(char const*) Unexecuted instantiation: ctype-uca.cc:strend(char const*) |
74 | | |
75 | 0 | static inline char *strend(char *s) { |
76 | 0 | while (*s++) { |
77 | 0 | } |
78 | 0 | return s - 1; |
79 | 0 | } Unexecuted instantiation: charset.cc:strend(char*) Unexecuted instantiation: my_getwd.cc:strend(char*) Unexecuted instantiation: my_lib.cc:strend(char*) Unexecuted instantiation: mf_pack.cc:strend(char*) Unexecuted instantiation: ctype-bin.cc:strend(char*) Unexecuted instantiation: ctype-latin1.cc:strend(char*) Unexecuted instantiation: ctype-mb.cc:strend(char*) Unexecuted instantiation: ctype-simple.cc:strend(char*) Unexecuted instantiation: ctype-uca.cc:strend(char*) |
80 | | |
81 | | /* |
82 | | strcend(s, c) returns a pointer to the first place in s where c |
83 | | occurs, or a pointer to the end-null of s if c does not occur in s. |
84 | | */ |
85 | 0 | static inline const char *strcend(const char *s, char c) { |
86 | 0 | for (;;) { |
87 | 0 | if (*s == c) return s; |
88 | 0 | if (!*s++) return s - 1; |
89 | 0 | } |
90 | 0 | } Unexecuted instantiation: charset.cc:strcend(char const*, char) Unexecuted instantiation: my_getwd.cc:strcend(char const*, char) Unexecuted instantiation: my_lib.cc:strcend(char const*, char) Unexecuted instantiation: mf_pack.cc:strcend(char const*, char) Unexecuted instantiation: ctype-bin.cc:strcend(char const*, char) Unexecuted instantiation: ctype-latin1.cc:strcend(char const*, char) Unexecuted instantiation: ctype-mb.cc:strcend(char const*, char) Unexecuted instantiation: ctype-simple.cc:strcend(char const*, char) Unexecuted instantiation: ctype-uca.cc:strcend(char const*, char) |
91 | | |
92 | | /* |
93 | | strfill(dest, len, fill) makes a string of fill-characters. The result |
94 | | string is of length == len. The des+len character is always set to NULL. |
95 | | strfill() returns pointer to dest+len; |
96 | | */ |
97 | 0 | static inline char *strfill(char *s, size_t len, char fill) { |
98 | 0 | while (len--) *s++ = fill; |
99 | 0 | *(s) = '\0'; |
100 | 0 | return (s); |
101 | 0 | } Unexecuted instantiation: charset.cc:strfill(char*, unsigned long, char) Unexecuted instantiation: my_getwd.cc:strfill(char*, unsigned long, char) Unexecuted instantiation: my_lib.cc:strfill(char*, unsigned long, char) Unexecuted instantiation: mf_pack.cc:strfill(char*, unsigned long, char) Unexecuted instantiation: ctype-bin.cc:strfill(char*, unsigned long, char) Unexecuted instantiation: ctype-latin1.cc:strfill(char*, unsigned long, char) Unexecuted instantiation: ctype-mb.cc:strfill(char*, unsigned long, char) Unexecuted instantiation: ctype-simple.cc:strfill(char*, unsigned long, char) Unexecuted instantiation: ctype-uca.cc:strfill(char*, unsigned long, char) |
102 | | |
103 | | /* |
104 | | my_stpmov(dst, src) moves all the characters of src (including the |
105 | | closing NUL) to dst, and returns a pointer to the new closing NUL in |
106 | | dst. The similar UNIX routine strcpy returns the old value of dst, |
107 | | which I have never found useful. my_stpmov(my_stpmov(dst,a),b) moves a//b |
108 | | into dst, which seems useful. |
109 | | */ |
110 | 0 | static inline char *my_stpmov(char *dst, const char *src) { |
111 | 0 | while ((*dst++ = *src++)) { |
112 | 0 | } |
113 | 0 | return dst - 1; |
114 | 0 | } Unexecuted instantiation: charset.cc:my_stpmov(char*, char const*) Unexecuted instantiation: my_getwd.cc:my_stpmov(char*, char const*) Unexecuted instantiation: my_lib.cc:my_stpmov(char*, char const*) Unexecuted instantiation: mf_pack.cc:my_stpmov(char*, char const*) Unexecuted instantiation: ctype-bin.cc:my_stpmov(char*, char const*) Unexecuted instantiation: ctype-latin1.cc:my_stpmov(char*, char const*) Unexecuted instantiation: ctype-mb.cc:my_stpmov(char*, char const*) Unexecuted instantiation: ctype-simple.cc:my_stpmov(char*, char const*) Unexecuted instantiation: ctype-uca.cc:my_stpmov(char*, char const*) |
115 | | |
116 | | /* |
117 | | my_stpnmov(dst,src,length) moves length characters, or until end, of src to |
118 | | dst and appends a closing NUL to dst if src is shorter than length. |
119 | | The result is a pointer to the first NUL in dst, or is dst+n if dst was |
120 | | truncated. |
121 | | */ |
122 | 2 | static inline char *my_stpnmov(char *dst, const char *src, size_t n) { |
123 | 10 | while (n-- != 0) { |
124 | 10 | if (!(*dst++ = *src++)) return (char *)dst - 1; |
125 | 10 | } |
126 | 0 | return dst; |
127 | 2 | } Unexecuted instantiation: charset.cc:my_stpnmov(char*, char const*, unsigned long) Unexecuted instantiation: my_getwd.cc:my_stpnmov(char*, char const*, unsigned long) Unexecuted instantiation: my_lib.cc:my_stpnmov(char*, char const*, unsigned long) mf_pack.cc:my_stpnmov(char*, char const*, unsigned long) Line | Count | Source | 122 | 2 | static inline char *my_stpnmov(char *dst, const char *src, size_t n) { | 123 | 10 | while (n-- != 0) { | 124 | 10 | if (!(*dst++ = *src++)) return (char *)dst - 1; | 125 | 10 | } | 126 | 0 | return dst; | 127 | 2 | } |
Unexecuted instantiation: ctype-bin.cc:my_stpnmov(char*, char const*, unsigned long) Unexecuted instantiation: ctype-latin1.cc:my_stpnmov(char*, char const*, unsigned long) Unexecuted instantiation: ctype-mb.cc:my_stpnmov(char*, char const*, unsigned long) Unexecuted instantiation: ctype-simple.cc:my_stpnmov(char*, char const*, unsigned long) Unexecuted instantiation: ctype-uca.cc:my_stpnmov(char*, char const*, unsigned long) |
128 | | |
129 | | /** |
130 | | Copy a string from src to dst until (and including) terminating null byte. |
131 | | |
132 | | @param dst Destination |
133 | | @param src Source |
134 | | |
135 | | @note src and dst cannot overlap. |
136 | | Use my_stpmov() if src and dst overlaps. |
137 | | |
138 | | @note Unsafe, consider using my_stpnpy() instead. |
139 | | |
140 | | @return pointer to terminating null byte. |
141 | | */ |
142 | 0 | static inline char *my_stpcpy(char *dst, const char *src) { |
143 | | #if defined(HAVE_BUILTIN_STPCPY) |
144 | | /* |
145 | | If __builtin_stpcpy() is available, use it instead of stpcpy(), since GCC in |
146 | | some situations is able to transform __builtin_stpcpy() into more efficient |
147 | | strcpy() or memcpy() calls. It does not perform these transformations for a |
148 | | plain call to stpcpy() when the compiler runs in strict mode. See GCC bug |
149 | | 82429. |
150 | | */ |
151 | | return __builtin_stpcpy(dst, src); |
152 | | #elif defined(HAVE_STPCPY) |
153 | | return stpcpy(dst, src); |
154 | | #else |
155 | | /* Fallback to implementation supporting overlap. */ |
156 | | return my_stpmov(dst, src); |
157 | | #endif |
158 | 0 | } Unexecuted instantiation: charset.cc:my_stpcpy(char*, char const*) Unexecuted instantiation: my_getwd.cc:my_stpcpy(char*, char const*) Unexecuted instantiation: my_lib.cc:my_stpcpy(char*, char const*) Unexecuted instantiation: mf_pack.cc:my_stpcpy(char*, char const*) Unexecuted instantiation: ctype-bin.cc:my_stpcpy(char*, char const*) Unexecuted instantiation: ctype-latin1.cc:my_stpcpy(char*, char const*) Unexecuted instantiation: ctype-mb.cc:my_stpcpy(char*, char const*) Unexecuted instantiation: ctype-simple.cc:my_stpcpy(char*, char const*) Unexecuted instantiation: ctype-uca.cc:my_stpcpy(char*, char const*) |
159 | | |
160 | | /** |
161 | | Copy fixed-size string from src to dst. |
162 | | |
163 | | @param dst Destination |
164 | | @param src Source |
165 | | @param n Maximum number of characters to copy. |
166 | | |
167 | | @note src and dst cannot overlap |
168 | | Use my_stpnmov() if src and dst overlaps. |
169 | | |
170 | | @return pointer to terminating null byte. |
171 | | */ |
172 | 0 | static inline char *my_stpncpy(char *dst, const char *src, size_t n) { |
173 | 0 | #if defined(HAVE_STPNCPY) |
174 | 0 | return stpncpy(dst, src, n); |
175 | 0 | #else |
176 | 0 | /* Fallback to implementation supporting overlap. */ |
177 | 0 | return my_stpnmov(dst, src, n); |
178 | 0 | #endif |
179 | 0 | } Unexecuted instantiation: charset.cc:my_stpncpy(char*, char const*, unsigned long) Unexecuted instantiation: my_getwd.cc:my_stpncpy(char*, char const*, unsigned long) Unexecuted instantiation: my_lib.cc:my_stpncpy(char*, char const*, unsigned long) Unexecuted instantiation: mf_pack.cc:my_stpncpy(char*, char const*, unsigned long) Unexecuted instantiation: ctype-bin.cc:my_stpncpy(char*, char const*, unsigned long) Unexecuted instantiation: ctype-latin1.cc:my_stpncpy(char*, char const*, unsigned long) Unexecuted instantiation: ctype-mb.cc:my_stpncpy(char*, char const*, unsigned long) Unexecuted instantiation: ctype-simple.cc:my_stpncpy(char*, char const*, unsigned long) Unexecuted instantiation: ctype-uca.cc:my_stpncpy(char*, char const*, unsigned long) |
180 | | |
181 | 0 | static inline long long my_strtoll(const char *nptr, char **endptr, int base) { |
182 | 0 | #if defined _WIN32 |
183 | 0 | return _strtoi64(nptr, endptr, base); |
184 | 0 | #else |
185 | 0 | return strtoll(nptr, endptr, base); |
186 | 0 | #endif |
187 | 0 | } Unexecuted instantiation: charset.cc:my_strtoll(char const*, char**, int) Unexecuted instantiation: my_getwd.cc:my_strtoll(char const*, char**, int) Unexecuted instantiation: my_lib.cc:my_strtoll(char const*, char**, int) Unexecuted instantiation: mf_pack.cc:my_strtoll(char const*, char**, int) Unexecuted instantiation: ctype-bin.cc:my_strtoll(char const*, char**, int) Unexecuted instantiation: ctype-latin1.cc:my_strtoll(char const*, char**, int) Unexecuted instantiation: ctype-mb.cc:my_strtoll(char const*, char**, int) Unexecuted instantiation: ctype-simple.cc:my_strtoll(char const*, char**, int) Unexecuted instantiation: ctype-uca.cc:my_strtoll(char const*, char**, int) |
188 | | |
189 | | static inline unsigned long long my_strtoull(const char *nptr, char **endptr, |
190 | 0 | int base) { |
191 | 0 | #if defined _WIN32 |
192 | 0 | return _strtoui64(nptr, endptr, base); |
193 | 0 | #else |
194 | 0 | return strtoull(nptr, endptr, base); |
195 | 0 | #endif |
196 | 0 | } Unexecuted instantiation: charset.cc:my_strtoull(char const*, char**, int) Unexecuted instantiation: my_getwd.cc:my_strtoull(char const*, char**, int) Unexecuted instantiation: my_lib.cc:my_strtoull(char const*, char**, int) Unexecuted instantiation: mf_pack.cc:my_strtoull(char const*, char**, int) Unexecuted instantiation: ctype-bin.cc:my_strtoull(char const*, char**, int) Unexecuted instantiation: ctype-latin1.cc:my_strtoull(char const*, char**, int) Unexecuted instantiation: ctype-mb.cc:my_strtoull(char const*, char**, int) Unexecuted instantiation: ctype-simple.cc:my_strtoull(char const*, char**, int) Unexecuted instantiation: ctype-uca.cc:my_strtoull(char const*, char**, int) |
197 | | |
198 | 0 | static inline char *my_strtok_r(char *str, const char *delim, char **saveptr) { |
199 | 0 | #if defined _WIN32 |
200 | 0 | return strtok_s(str, delim, saveptr); |
201 | 0 | #else |
202 | 0 | return strtok_r(str, delim, saveptr); |
203 | 0 | #endif |
204 | 0 | } Unexecuted instantiation: charset.cc:my_strtok_r(char*, char const*, char**) Unexecuted instantiation: my_getwd.cc:my_strtok_r(char*, char const*, char**) Unexecuted instantiation: my_lib.cc:my_strtok_r(char*, char const*, char**) Unexecuted instantiation: mf_pack.cc:my_strtok_r(char*, char const*, char**) Unexecuted instantiation: ctype-bin.cc:my_strtok_r(char*, char const*, char**) Unexecuted instantiation: ctype-latin1.cc:my_strtok_r(char*, char const*, char**) Unexecuted instantiation: ctype-mb.cc:my_strtok_r(char*, char const*, char**) Unexecuted instantiation: ctype-simple.cc:my_strtok_r(char*, char const*, char**) Unexecuted instantiation: ctype-uca.cc:my_strtok_r(char*, char const*, char**) |
205 | | |
206 | | /* native_ rather than my_ since my_strcasecmp already exists */ |
207 | 0 | static inline int native_strcasecmp(const char *s1, const char *s2) { |
208 | 0 | #if defined _WIN32 |
209 | 0 | return _stricmp(s1, s2); |
210 | 0 | #else |
211 | 0 | return strcasecmp(s1, s2); |
212 | 0 | #endif |
213 | 0 | } Unexecuted instantiation: charset.cc:native_strcasecmp(char const*, char const*) Unexecuted instantiation: my_getwd.cc:native_strcasecmp(char const*, char const*) Unexecuted instantiation: my_lib.cc:native_strcasecmp(char const*, char const*) Unexecuted instantiation: mf_pack.cc:native_strcasecmp(char const*, char const*) Unexecuted instantiation: ctype-bin.cc:native_strcasecmp(char const*, char const*) Unexecuted instantiation: ctype-latin1.cc:native_strcasecmp(char const*, char const*) Unexecuted instantiation: ctype-mb.cc:native_strcasecmp(char const*, char const*) Unexecuted instantiation: ctype-simple.cc:native_strcasecmp(char const*, char const*) Unexecuted instantiation: ctype-uca.cc:native_strcasecmp(char const*, char const*) |
214 | | |
215 | | /* native_ rather than my_ for consistency with native_strcasecmp */ |
216 | 0 | static inline int native_strncasecmp(const char *s1, const char *s2, size_t n) { |
217 | | #if defined _WIN32 |
218 | | return _strnicmp(s1, s2, n); |
219 | | #else |
220 | 0 | return strncasecmp(s1, s2, n); |
221 | 0 | #endif |
222 | 0 | } Unexecuted instantiation: charset.cc:native_strncasecmp(char const*, char const*, unsigned long) Unexecuted instantiation: my_getwd.cc:native_strncasecmp(char const*, char const*, unsigned long) Unexecuted instantiation: my_lib.cc:native_strncasecmp(char const*, char const*, unsigned long) Unexecuted instantiation: mf_pack.cc:native_strncasecmp(char const*, char const*, unsigned long) Unexecuted instantiation: ctype-bin.cc:native_strncasecmp(char const*, char const*, unsigned long) Unexecuted instantiation: ctype-latin1.cc:native_strncasecmp(char const*, char const*, unsigned long) Unexecuted instantiation: ctype-mb.cc:native_strncasecmp(char const*, char const*, unsigned long) Unexecuted instantiation: ctype-simple.cc:native_strncasecmp(char const*, char const*, unsigned long) Unexecuted instantiation: ctype-uca.cc:native_strncasecmp(char const*, char const*, unsigned long) |
223 | | |
224 | | /* |
225 | | is_prefix(s, t) returns 1 if s starts with t. |
226 | | A empty t is always a prefix. |
227 | | */ |
228 | 0 | static inline int is_prefix(const char *s, const char *t) { |
229 | 0 | while (*t) |
230 | 0 | if (*s++ != *t++) return 0; |
231 | 0 | return 1; /* WRONG */ |
232 | 0 | } Unexecuted instantiation: charset.cc:is_prefix(char const*, char const*) Unexecuted instantiation: my_getwd.cc:is_prefix(char const*, char const*) Unexecuted instantiation: my_lib.cc:is_prefix(char const*, char const*) Unexecuted instantiation: mf_pack.cc:is_prefix(char const*, char const*) Unexecuted instantiation: ctype-bin.cc:is_prefix(char const*, char const*) Unexecuted instantiation: ctype-latin1.cc:is_prefix(char const*, char const*) Unexecuted instantiation: ctype-mb.cc:is_prefix(char const*, char const*) Unexecuted instantiation: ctype-simple.cc:is_prefix(char const*, char const*) Unexecuted instantiation: ctype-uca.cc:is_prefix(char const*, char const*) |
233 | | |
234 | | /** |
235 | | Skip trailing space (ASCII spaces only). |
236 | | |
237 | | @return New end of the string. |
238 | | */ |
239 | | static inline const uint8_t *skip_trailing_space(const uint8_t *ptr, |
240 | 0 | size_t len) { |
241 | 0 | const uint8_t *end = ptr + len; |
242 | 0 | while (end - ptr >= 8) { |
243 | 0 | uint64_t chunk; |
244 | 0 | memcpy(&chunk, end - 8, sizeof(chunk)); |
245 | 0 | if (chunk != 0x2020202020202020ULL) break; |
246 | 0 | end -= 8; |
247 | 0 | } |
248 | 0 | while (end > ptr && end[-1] == 0x20) end--; |
249 | 0 | return (end); |
250 | 0 | } Unexecuted instantiation: charset.cc:skip_trailing_space(unsigned char const*, unsigned long) Unexecuted instantiation: my_getwd.cc:skip_trailing_space(unsigned char const*, unsigned long) Unexecuted instantiation: my_lib.cc:skip_trailing_space(unsigned char const*, unsigned long) Unexecuted instantiation: mf_pack.cc:skip_trailing_space(unsigned char const*, unsigned long) Unexecuted instantiation: ctype-bin.cc:skip_trailing_space(unsigned char const*, unsigned long) Unexecuted instantiation: ctype-latin1.cc:skip_trailing_space(unsigned char const*, unsigned long) Unexecuted instantiation: ctype-mb.cc:skip_trailing_space(unsigned char const*, unsigned long) Unexecuted instantiation: ctype-simple.cc:skip_trailing_space(unsigned char const*, unsigned long) Unexecuted instantiation: ctype-uca.cc:skip_trailing_space(unsigned char const*, unsigned long) |
251 | | |
252 | | /* |
253 | | Format a double (representing number of bytes) into a human-readable string. |
254 | | |
255 | | @param buf Buffer used for printing |
256 | | @param buf_len Length of buffer |
257 | | @param dbl_val Value to be formatted |
258 | | |
259 | | @note |
260 | | Sample output format: 42 1K 234M 2G |
261 | | If we exceed ULLONG_MAX YiB we give up, and convert to "+INF". |
262 | | |
263 | | @todo Consider writing KiB GiB etc, since we use 1024 rather than 1000 |
264 | | */ |
265 | | static inline void human_readable_num_bytes(char *buf, int buf_len, |
266 | 0 | double dbl_val) { |
267 | 0 | const char size[] = {'\0', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'}; |
268 | 0 | unsigned int i; |
269 | 0 | for (i = 0; dbl_val > 1024 && i < sizeof(size) - 1; i++) dbl_val /= 1024; |
270 | 0 | const char mult = size[i]; |
271 | 0 | // 18446744073709551615 Yottabytes should be enough for most ... |
272 | 0 | // ULLONG_MAX is not exactly representable as a double. This is the largest |
273 | 0 | // double that is still below ULLONG_MAX. |
274 | 0 | if (dbl_val > 18446744073709549568.0) |
275 | 0 | snprintf(buf, buf_len, "+INF"); |
276 | 0 | else |
277 | 0 | snprintf(buf, buf_len, "%llu%c", (unsigned long long)dbl_val, mult); |
278 | 0 | } Unexecuted instantiation: charset.cc:human_readable_num_bytes(char*, int, double) Unexecuted instantiation: my_getwd.cc:human_readable_num_bytes(char*, int, double) Unexecuted instantiation: my_lib.cc:human_readable_num_bytes(char*, int, double) Unexecuted instantiation: mf_pack.cc:human_readable_num_bytes(char*, int, double) Unexecuted instantiation: ctype-bin.cc:human_readable_num_bytes(char*, int, double) Unexecuted instantiation: ctype-latin1.cc:human_readable_num_bytes(char*, int, double) Unexecuted instantiation: ctype-mb.cc:human_readable_num_bytes(char*, int, double) Unexecuted instantiation: ctype-simple.cc:human_readable_num_bytes(char*, int, double) Unexecuted instantiation: ctype-uca.cc:human_readable_num_bytes(char*, int, double) |
279 | | |
280 | 0 | static inline void lex_string_set(LEX_STRING *lex_str, char *c_str) { |
281 | 0 | lex_str->str = c_str; |
282 | 0 | lex_str->length = strlen(c_str); |
283 | 0 | } Unexecuted instantiation: charset.cc:lex_string_set(MYSQL_LEX_STRING*, char*) Unexecuted instantiation: my_getwd.cc:lex_string_set(MYSQL_LEX_STRING*, char*) Unexecuted instantiation: my_lib.cc:lex_string_set(MYSQL_LEX_STRING*, char*) Unexecuted instantiation: mf_pack.cc:lex_string_set(MYSQL_LEX_STRING*, char*) Unexecuted instantiation: ctype-bin.cc:lex_string_set(MYSQL_LEX_STRING*, char*) Unexecuted instantiation: ctype-latin1.cc:lex_string_set(MYSQL_LEX_STRING*, char*) Unexecuted instantiation: ctype-mb.cc:lex_string_set(MYSQL_LEX_STRING*, char*) Unexecuted instantiation: ctype-simple.cc:lex_string_set(MYSQL_LEX_STRING*, char*) Unexecuted instantiation: ctype-uca.cc:lex_string_set(MYSQL_LEX_STRING*, char*) |
284 | | |
285 | 0 | static inline void lex_cstring_set(LEX_CSTRING *lex_str, const char *c_str) { |
286 | 0 | lex_str->str = c_str; |
287 | 0 | lex_str->length = strlen(c_str); |
288 | 0 | } Unexecuted instantiation: charset.cc:lex_cstring_set(MYSQL_LEX_CSTRING*, char const*) Unexecuted instantiation: my_getwd.cc:lex_cstring_set(MYSQL_LEX_CSTRING*, char const*) Unexecuted instantiation: my_lib.cc:lex_cstring_set(MYSQL_LEX_CSTRING*, char const*) Unexecuted instantiation: mf_pack.cc:lex_cstring_set(MYSQL_LEX_CSTRING*, char const*) Unexecuted instantiation: ctype-bin.cc:lex_cstring_set(MYSQL_LEX_CSTRING*, char const*) Unexecuted instantiation: ctype-latin1.cc:lex_cstring_set(MYSQL_LEX_CSTRING*, char const*) Unexecuted instantiation: ctype-mb.cc:lex_cstring_set(MYSQL_LEX_CSTRING*, char const*) Unexecuted instantiation: ctype-simple.cc:lex_cstring_set(MYSQL_LEX_CSTRING*, char const*) Unexecuted instantiation: ctype-uca.cc:lex_cstring_set(MYSQL_LEX_CSTRING*, char const*) |
289 | | |
290 | | #endif // M_STRING_INCLUDED |