1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-21978 Add %sQ, %sB, %uE & %sT to my_vsnprintf

This is the first part of
MDEV-21978 make my_vsnprintf to use gcc-compatible format extensions,
which adds these alternatives to the MySQL extensions.
There’s also the escapes `%sS` & `%uU` for any hippies needing them.
These suffixes are compatible with the C standard and
therefore as well as `printf` tools such as GCC checks.

The old extension formats (e.g., `%M`) are now effectively deprecated,
although they’re left intact for now. For a more sequential
MDEV-21978 process, a separate commit will delete them after we migrate
all `my_vsnprintf` usages to the new preferred syntax. The service’s
major version bumped nonetheless for the new significance of suffixes.

[Breaking] This commit may fail
* on places needing the aforementioned escapes
* because of the major version bump

Reviewed-by: Andrew Hutchings <andrew@mariadb.org>
Reviewed-by: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
This commit is contained in:
ParadoxV5
2024-07-25 21:57:06 -06:00
committed by Sergei Golubchik
parent 06851e7f77
commit b668a960cd
4 changed files with 143 additions and 39 deletions

View File

@@ -39,40 +39,41 @@
@post
The syntax of a format string is generally the same:
% <flag> <width> <precision> <length modifier> <format>
% <flag> <width> <.precision> <length modifier> <format> <format extension>
where everything but the format is optional.
Three one-character flags are recognized:
Two one-character flags are recognized:
'0' has the standard zero-padding semantics;
'-' is parsed, but silently ignored;
'`' (backtick) is only supported for strings (%s) and means that the
string will be quoted according to MySQL identifier quoting rules.
Both <width> and <precision> can be specified as numbers or '*'.
If an asterisk is used, an argument of type int is consumed.
<length modifier> can be 'l', 'll', or 'z'.
Supported formats are 's' (null pointer is accepted, printed as
"(null)"), 'b' (extension, see below), 'c', 'd', 'i', 'u', 'x', 'o',
'X', 'p' (works as 0x%x), 'f', 'g', 'M' (extension, see below),
'T' (extension, see below).
Supported formats are 's' (null pointer is accepted, printed as "(null)"),
'c', 'd', 'i', 'u', 'x', 'X', 'o', 'p' (works as 0x%x), 'f', and 'g'.
Standard syntax for positional arguments $n is supported.
Extensions:
Format extensions:
Flag '`' (backtick): see above.
Format 'sQ': quotes the string according to MySQL identifier quoting rules.
Format 'b': binary buffer, prints exactly <precision> bytes from the
argument, without stopping at '\0'.
Format 'sB': binary buffer, prints exactly <precision> bytes from the
argument, without stopping at '\0'. The behavior for unspecified <precision>
is not yet defined.
Format 'M': takes one integer, prints this integer, space, double quote
error message, double quote. In other words
printf("%M", n) === printf("%d \"%s\"", n, strerror(n))
Format 'uE': takes one integer, prints this integer, space, double quote,
error message corresponding to this integer errno, double quote. In other words:
printf("%uE", n) === printf("%d \"%sT\"", n, strerror(n))
Format 'T': takes string and print it like s but if the strints should be
Format 'sT': takes string and print it like s but if the strings should be
truncated puts "..." at the end.
Format 'sS' and 'uU': prints synonymously as s and u respectively. These two
escape simple s and u from consuming the following plain text as one of the
above extension suffixes; for example, "Data size: %uUEiB".
*/
#ifdef __cplusplus