From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-6.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by gnuweeb.org (Postfix) with ESMTPS id 320BA7E405 for ; Tue, 19 Apr 2022 00:42:33 +0000 (UTC) Authentication-Results: gnuweeb.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=ibuFo3TP; dkim-atps=neutral Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5B8B1B81178; Tue, 19 Apr 2022 00:42:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7461EC36AE5; Tue, 19 Apr 2022 00:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650328948; bh=9N5Oy4zBAcINKzn6vYAORDvO50WX1cEVYblAMVZFE9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ibuFo3TPCxEoITt/U7wvwza/+VR6Eup5U3XfE3bxHkRrVBLFivxRPYvO3Yh3Ach/w 2AZ+BrxrDu8lu0YUXh8y1S0FpGi5dfEfy/xx7RkH72FTOKYK2McWnQbPnkZHzlsxW9 EW/R7jmMjNuq5Mw4i/cxQEHPZ58K1Nw9ta+VGOWGqWLahP2fTTzuvxD3axFbw/sHkw AaIxDbPIaAPR8GvNJpl0r3T8djoibi9qCS1slrH63GY1/jk0Ick1NBku9CQMxmH4WU WnPSXNjXIDVQ+FS9dJLLzXzsKvmRNK9mZFx39upN3hj9mAcH/FP3iYWtfBQVf5xJ3s lJtlmA8pW2muA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 5924E5C3233; Mon, 18 Apr 2022 17:42:27 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@fb.com, w@lwt.eu, Willy Tarreau , "Paul E . McKenney" Subject: [PATCH nolibc 45/61] tools/nolibc/stdio: add support for '%p' to vfprintf() Date: Mon, 18 Apr 2022 17:42:09 -0700 Message-Id: <20220419004225.3952530-45-paulmck@kernel.org> X-Mailer: git-send-email 2.31.1.189.g2e36527f23 In-Reply-To: <20220419004219.GA3952301@paulmck-ThinkPad-P17-Gen-1> References: <20220419004219.GA3952301@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Willy Tarreau %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 Signed-off-by: Paul E. McKenney --- 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); - break; - case 'x': - u64toh_r(v, tmpbuf); + u64toa_r(v, out); 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.31.1.189.g2e36527f23