mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Rename my_snprintf
’s %uE
to %iE
… and delete `%uU` (just use `%d` for that) The follow-up #3360 discovered `%M` usages that suggest that it was designed for `errno` and similar **signed** `int` (“errno_t”) variables. Besides convenience, if the old `%M` read a `signed int`, so should the new version to maintain compatibility. I only added `%iE` (no `%dE`) to keep the new suffix mechanics away from the popular `%d`. Beïng synonyms (originally), this decision on preserving `%d` also saves the need for `%iI`/`%dD`.
This commit is contained in:
committed by
Sergei Golubchik
parent
891177418e
commit
6a182553ce
@@ -67,21 +67,22 @@
|
||||
<precision> bytes without terminating on any '\0's in the sequence.
|
||||
The default <precision> when it's unspecified is not defined.
|
||||
|
||||
Format 'uE'
|
||||
treats the argument as an errno number. It prints this number, a space,
|
||||
then its corresponding error message in double quotes. In other words:
|
||||
printf("%uE", n) === printf("%d \"%sT\"", n, strerror(n))
|
||||
|
||||
Format 'sT'
|
||||
replaces the end of the printed string with "..." if it was truncated.
|
||||
|
||||
Format 'sS' and 'uU'
|
||||
are synonyms of 's' and 'u' respectively. They are escapes that avoid
|
||||
Format 'sS'
|
||||
is a synonym for 's'. It's an escape that avoid
|
||||
consuming the following plain char as one of the above extension suffixes.
|
||||
Example: "Data size: %uUEiB"
|
||||
Example: "Data Class: %sSType"
|
||||
|
||||
Format 'iE'
|
||||
treats the argument as an errno number. It prints this number, a space,
|
||||
then its corresponding error message in double quotes. In other words:
|
||||
printf("%iE", n) === printf("%i \"%sT\"", n, strerror(n))
|
||||
Format 'dE' has no effect. Therefore, to escape '%iE', use '%dE' instead.
|
||||
|
||||
Unrecognized and multiple suffixes are not parsed;
|
||||
for example, both "%sTQ" and "%uQ" will print a literal 'Q'.
|
||||
for example, both "%sTQ" and "%iQ" will suffix with a literal 'Q'.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -586,16 +586,12 @@ start:
|
||||
/* Integer parameter */
|
||||
longlong larg= args_arr[print_arr[i].arg_idx].longlong_arg;
|
||||
my_bool suffix_e= arg_type == 'M';
|
||||
if (arg_type == 'u')
|
||||
switch (*print_arr[idx].begin) // look at the start of the next chunk
|
||||
{
|
||||
case 'E':
|
||||
suffix_e= TRUE;
|
||||
// fall-through
|
||||
case 'U': // escape
|
||||
++print_arr[idx].begin; // roll forward to consume the char
|
||||
break;
|
||||
}
|
||||
// look at the start of the next chunk
|
||||
if (arg_type == 'i' && *print_arr[i].begin == 'E')
|
||||
{
|
||||
suffix_e= TRUE;
|
||||
++print_arr[i].begin; // roll forward to consume the char
|
||||
}
|
||||
if (suffix_e)
|
||||
{
|
||||
const char *real_end;
|
||||
@@ -807,16 +803,11 @@ size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
|
||||
larg= va_arg(ap, int);
|
||||
else
|
||||
larg= va_arg(ap, uint);
|
||||
if (arg_type == 'u')
|
||||
switch (fmt[1]) // look-ahead
|
||||
{
|
||||
case 'E':
|
||||
suffix_e= TRUE;
|
||||
// fall-through
|
||||
case 'U': // escape
|
||||
++fmt;
|
||||
break;
|
||||
}
|
||||
if (arg_type == 'i' && fmt[1] == 'E') // look-ahead
|
||||
{
|
||||
suffix_e= TRUE;
|
||||
++fmt;
|
||||
}
|
||||
if (suffix_e)
|
||||
{
|
||||
const char *real_end= MY_MIN(to + width, end);
|
||||
|
@@ -113,9 +113,6 @@ int main(void)
|
||||
|
||||
test1("MariaDB extension escape sS works",
|
||||
"MariaDB extension escape sS %sS", "works");
|
||||
test1("MariaDB extension escape uU 2",
|
||||
"MariaDB extension escape uU %uU", 2);
|
||||
|
||||
test1("MariaDB extension sQ works: `abcd` `op``q`",
|
||||
"MariaDB extension sQ works: %sQ %.4sQ", "abcd", "op`qrst");
|
||||
|
||||
@@ -131,21 +128,24 @@ int main(void)
|
||||
}
|
||||
|
||||
{
|
||||
// Test that %uE works
|
||||
// Test that %iE works
|
||||
const char *results[]=
|
||||
{
|
||||
"MariaDB extension uE works: 1 \"Operation not permitted\"", // Linux
|
||||
"MariaDB extension uE works: 1 \"Not owner\"", // Solaris
|
||||
"MariaDB extension iE works: 1 \"Operation not permitted\"", // Linux
|
||||
"MariaDB extension iE works: 1 \"Not owner\"", // Solaris
|
||||
NullS
|
||||
};
|
||||
test_many(results, "MariaDB extension uE works: %uE", 1);
|
||||
test_many(results, "MariaDB extension iE works: %iE", 1);
|
||||
}
|
||||
test1("uE with 0 errno: 0 \"Internal error/check (Not system error)\"",
|
||||
"uE with 0 errno: %uE", 0);
|
||||
test1("uE with width: <0 \"Internal error...>",
|
||||
"uE with width: <%.20uE>", 0);
|
||||
test_w_len("uE with small buf: 0 \"..",
|
||||
25, "uE with small buf: %uE", 0);
|
||||
test1("iE with 0 errno: 0 \"Internal error/check (Not system error)\"",
|
||||
"iE with 0 errno: %iE", 0);
|
||||
test1("iE with width: <0 \"Internal error...>",
|
||||
"iE with width: <%.20iE>", 0);
|
||||
test_w_len("iE with small buf: 0 \"..",
|
||||
25, "iE with small buf: %iE", 0);
|
||||
|
||||
test1("MariaDB extension dE DOESN'T work: 0E",
|
||||
"MariaDB extension dE DOESN'T work: %dE", 0);
|
||||
|
||||
test1("MariaDB extension sT works: <abcd> <op...>",
|
||||
"MariaDB extension sT %sT: <%.5sT> <%.5sT>", "works", "abcd", "opqrst");
|
||||
|
Reference in New Issue
Block a user