From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85BE41A9F8C for ; Mon, 23 Feb 2026 10:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771843250; cv=none; b=oEOJgv0JJbD0Z4wFb/2Xzu45zCtGRpcgOT5ak+4DP4IjkM41F0X91B7EkxVxLVX8NXzExx50AN7iTXMiQgAuklZUxubD3drVj3bJ988AW8SU+pKklnsHkSxPqzIFeYwrGac1BtBaueX29a+FZfpYgs518JrVZkKbRajh7hVqu1E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771843250; c=relaxed/simple; bh=I6UJp7IqGHwY3QNXGfGmqDI7gonDxC8mrBBYCsxzif8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oiNX5uqnKkKTip7T973tYDANNP2qzOcVetbNLu3MjgSpKOx9o05/rIxuh9WUDA6EqH2nM1WXJ4psdRWR16+/ZxvGic56dquEINF1bo6azuG2ZI/cR2yWpzrLuKWNcp29t/lYRN7zihOVoN1qa7pFYxkNFnsWvSHtosUNB+g4m/4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=runbox.com; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b=RsbszwQ1; arc=none smtp.client-ip=185.226.149.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=runbox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b="RsbszwQ1" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vuT1E-00Ggpf-V9; Mon, 23 Feb 2026 11:18:24 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector2; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=PfnSLSWmlNHpxKQJ2pLW1j5n0vlSVJPWVbwcSXAZnfI=; b=RsbszwQ1eNOepMsgjCk6uVITgk f2l31stxH8YJUFSIeldBJnTykWjpBJrNTwTGrpA8FE8ZQa2uYPq6vPeaxWgySaEhsKX4cFu/5o+zH HWSWLdZO3vtI8JCYBErCUjKXtpE3UF1C0Fc6xTNHwmr+MWeGKKOcmay1gcNC4vur/doTi5871q7e2 ZRkK8CwKFVDlFTZK0LZWheaOyDgqH9L//Cp500iY0z5ivGsmVcxXAe2bSzD2WCaj8wPIUB5yLvvev 0om7sm0t99ieKW3IoUhWSPocPBAY92iMqMApyjMMaHA03mc1/ek4hGr04gnpM7see9l8hn0pEt/ty FOEaWG1g==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vuT1E-0005QA-Ku; Mon, 23 Feb 2026 11:18:24 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (1493616)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1vuT15-006AjD-Ue; Mon, 23 Feb 2026 11:18:16 +0100 From: david.laight.linux@gmail.com To: Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kernel@vger.kernel.org, Cheng Li Cc: David Laight Subject: [PATCH v3 next 14/17] tools/nolibc/printf: Add support for left aligning fields Date: Mon, 23 Feb 2026 10:17:32 +0000 Message-Id: <20260223101735.2922-15-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260223101735.2922-1-david.laight.linux@gmail.com> References: <20260223101735.2922-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Laight Output the characters before or after the pad - writing the pad takes more code. Include additional/changed tests Signed-off-by: David Laight --- Changes for v3: - Formally part of patch 7. tools/include/nolibc/stdio.h | 6 +++++- tools/testing/selftests/nolibc/nolibc-test.c | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index c21abe085fa6..482e5b143c86 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -540,7 +540,11 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list /* Stop gcc back-merging this code into one of the conditionals above. */ _NOLIBC_OPTIMIZER_HIDE_VAR(len); + /* Output the characters on the required side of any padding. */ width -= len; + flags = _NOLIBC_PF_FLAGS_CONTAIN(flags, '-'); + if (flags && cb(state, outstr, len) != 0) + return -1; while (width > 0) { /* Output pad in 16 byte blocks with the small block first. */ int pad_len = ((width - 1) & 15) + 1; @@ -549,7 +553,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list if (cb(state, " ", pad_len) != 0) return -1; } - if (cb(state, outstr, len) != 0) + if (!flags && cb(state, outstr, len) != 0) return -1; } diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index f746711af777..cc59c0116855 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1851,9 +1851,11 @@ static int run_printf(int min, int max) CASE_TEST(truncation); EXPECT_VFPRINTF(1, "012345678901234567890123456789", "%s", "012345678901234567890123456789"); break; CASE_TEST(string_width); EXPECT_VFPRINTF(1, " 1", "%10s", "1"); break; CASE_TEST(number_width); EXPECT_VFPRINTF(1, " 1", "%10d", 1); break; + CASE_TEST(number_left); EXPECT_VFPRINTF(1, "|-5 |", "|%-8d|", -5); break; + CASE_TEST(string_align); EXPECT_VFPRINTF(1, "|foo |", "|%-8s|", "foo"); break; CASE_TEST(width_trunc); EXPECT_VFPRINTF(1, " 1", "%30d", 1); break; CASE_TEST(hex_alt); EXPECT_VFPRINTF(1, "|0x1| 0x2| 0|", "|%#x|%#5x|%#5x|", 1, 2, 0); break; - CASE_TEST(errno); EXPECT_VFPRINTF(is_nolibc, "22:errno=22", "%d:%m", errno=22); break; + CASE_TEST(errno); EXPECT_VFPRINTF(is_nolibc, "22:errno=22 ", "%d:%-12m", errno=22); break; CASE_TEST(errno-neg); EXPECT_VFPRINTF(is_nolibc, "-22: errno=-22", "%d:%12m", errno=-22); break; CASE_TEST(scanf); EXPECT_ZR(1, test_scanf()); break; CASE_TEST(printf_error); EXPECT_ZR(1, test_printf_error()); break; -- 2.39.5