[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260206191121.3602-2-david.laight.linux@gmail.com>
Date: Fri, 6 Feb 2026 19:11:11 +0000
From: david.laight.linux@...il.com
To: Willy Tarreau <w@....eu>,
Thomas Weißschuh <linux@...ssschuh.net>,
linux-kernel@...r.kernel.org,
Cheng Li <lechain@...il.com>
Cc: David Laight <david.laight.linux@...il.com>
Subject: [PATCH v2 next 01/11] tools/nolibc/printf: Change variable used for format chars from 'c' to 'ch'
From: David Laight <david.laight.linux@...il.com>
This makes the code slightly easier to read because the variable
stands out from the single character literals (especially 'c').
The following patches pretty much rewrite the function so the
churn is limited.
Signed-off-by: David Laight <david.laight.linux@...il.com>
---
New patch for v2.
tools/include/nolibc/stdio.h | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
index 1f16dab2ac88..f162cc697a73 100644
--- a/tools/include/nolibc/stdio.h
+++ b/tools/include/nolibc/stdio.h
@@ -250,7 +250,7 @@ typedef int (*__nolibc_printf_cb)(intptr_t state, const char *buf, size_t size);
static __attribute__((unused, format(printf, 4, 0)))
int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char *fmt, va_list args)
{
- char escape, lpref, c;
+ char escape, lpref, ch;
unsigned long long v;
unsigned int written, width;
size_t len, ofs, w;
@@ -259,7 +259,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
written = ofs = escape = lpref = 0;
while (1) {
- c = fmt[ofs++];
+ ch = fmt[ofs++];
width = 0;
if (escape) {
@@ -267,17 +267,17 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
escape = 0;
/* width */
- while (c >= '0' && c <= '9') {
+ while (ch >= '0' && ch <= '9') {
width *= 10;
- width += c - '0';
+ width += ch - '0';
- c = fmt[ofs++];
+ ch = fmt[ofs++];
}
- if (c == 'c' || c == 'd' || c == 'u' || c == 'x' || c == 'p') {
+ if (ch == 'c' || ch == 'd' || ch == 'u' || ch == 'x' || ch == 'p') {
char *out = tmpbuf;
- if (c == 'p')
+ if (ch == 'p')
v = va_arg(args, unsigned long);
else if (lpref) {
if (lpref > 1)
@@ -287,7 +287,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
} else
v = va_arg(args, unsigned int);
- if (c == 'd') {
+ if (ch == 'd') {
/* sign-extend the value */
if (lpref == 0)
v = (long long)(int)v;
@@ -295,7 +295,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
v = (long long)(long)v;
}
- switch (c) {
+ switch (ch) {
case 'c':
out[0] = v;
out[1] = 0;
@@ -316,28 +316,28 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
}
outstr = tmpbuf;
}
- else if (c == 's') {
+ else if (ch == 's') {
outstr = va_arg(args, char *);
if (!outstr)
outstr="(null)";
}
- else if (c == 'm') {
+ else if (ch == 'm') {
#ifdef NOLIBC_IGNORE_ERRNO
outstr = "unknown error";
#else
outstr = strerror(errno);
#endif /* NOLIBC_IGNORE_ERRNO */
}
- else if (c == '%') {
+ else if (ch == '%') {
/* queue it verbatim */
continue;
}
else {
/* modifiers or final 0 */
- if (c == 'l') {
+ if (ch == 'l') {
/* long format prefix, maintain the escape */
lpref++;
- } else if (c == 'j') {
+ } else if (ch == 'j') {
lpref = 2;
}
escape = 1;
@@ -348,7 +348,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
}
/* not an escape sequence */
- if (c == 0 || c == '%') {
+ if (ch == 0 || ch == '%') {
/* flush pending data on escape or end */
escape = 1;
lpref = 0;
@@ -369,7 +369,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
written += len;
do_escape:
- if (c == 0)
+ if (ch == 0)
break;
fmt += ofs;
ofs = 0;
--
2.39.5
Powered by blists - more mailing lists