From: Willy Tarreau <w@1wt.eu>
To: "Paul E . McKenney" <paulmck@kernel.org>
Cc: linux-kernel@vger.kernel.org, Ammar Faizi <ammarfaizi2@gnuweeb.org>
Subject: [PATCH 3/8] tools/nolibc/stdio: add support for '%p' to vfprintf()
Date: Mon, 21 Mar 2022 18:33:09 +0100 [thread overview]
Message-ID: <20220321173314.7519-4-w@1wt.eu> (raw)
In-Reply-To: <20220321173314.7519-1-w@1wt.eu>
%p remains quite useful in test code, and the code path can easily be
merged with the existing "%x" thus only adds ~50 bytes, thus let's
add it.
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
tools/include/nolibc/stdio.h | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
index 559ebe052a75..15dedf8d0902 100644
--- a/tools/include/nolibc/stdio.h
+++ b/tools/include/nolibc/stdio.h
@@ -163,7 +163,7 @@ char *fgets(char *s, int size, FILE *stream)
/* minimal vfprintf(). It supports the following formats:
- * - %[l*]{d,u,c,x}
+ * - %[l*]{d,u,c,x,p}
* - %s
* - unknown modifiers are ignored.
*/
@@ -184,8 +184,12 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
if (escape) {
/* we're in an escape sequence, ofs == 1 */
escape = 0;
- if (c == 'c' || c == 'd' || c == 'u' || c == 'x') {
- if (lpref) {
+ if (c == 'c' || c == 'd' || c == 'u' || c == 'x' || c == 'p') {
+ char *out = tmpbuf;
+
+ if (c == 'p')
+ v = va_arg(args, unsigned long);
+ else if (lpref) {
if (lpref > 1)
v = va_arg(args, unsigned long long);
else
@@ -202,18 +206,22 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
}
switch (c) {
+ case 'c':
+ out[0] = v;
+ out[1] = 0;
+ break;
case 'd':
- i64toa_r(v, tmpbuf);
+ i64toa_r(v, out);
break;
case 'u':
- u64toa_r(v, tmpbuf);
+ u64toa_r(v, out);
break;
- case 'x':
- u64toh_r(v, tmpbuf);
- break;
- default: /* 'c' */
- tmpbuf[0] = v;
- tmpbuf[1] = 0;
+ case 'p':
+ *(out++) = '0';
+ *(out++) = 'x';
+ /* fall through */
+ default: /* 'x' and 'p' above */
+ u64toh_r(v, out);
break;
}
outstr = tmpbuf;
--
2.35.1
next prev parent reply other threads:[~2022-03-21 17:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-21 17:33 [PATCH 0/8] nolibc: small updates required for the self-tests Willy Tarreau
2022-03-21 17:33 ` [PATCH 1/8] tools/nolibc/stdio: make printf(%s) accept NULL Willy Tarreau
2022-03-21 17:33 ` [PATCH 2/8] tools/nolibc/stdlib: add a simple getenv() implementation Willy Tarreau
2022-03-21 17:33 ` Willy Tarreau [this message]
2022-03-21 17:33 ` [PATCH 4/8] tools/nolibc/string: add strcmp() and strncmp() Willy Tarreau
2022-03-21 17:33 ` [PATCH 5/8] tools/nolibc/sys: add syscall definition for getppid() Willy Tarreau
2022-03-21 17:33 ` [PATCH 6/8] tools/nolibc/types: add poll() and waitpid() flag definitions Willy Tarreau
2022-03-21 17:33 ` [PATCH 7/8] tools/nolibc: add a makefile to install headers Willy Tarreau
2022-03-21 17:33 ` [PATCH 8/8] tools/nolibc: add the nolibc subdir to the common Makefile Willy Tarreau
2022-03-21 20:29 ` [PATCH 0/8] nolibc: small updates required for the self-tests Paul E. McKenney
2022-03-21 20:33 ` Willy Tarreau
2022-03-21 20:42 ` Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220321173314.7519-4-w@1wt.eu \
--to=w@1wt.eu \
--cc=ammarfaizi2@gnuweeb.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®