From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EBE8C25B06 for ; Sun, 14 Aug 2022 21:21:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240487AbiHNVVJ (ORCPT ); Sun, 14 Aug 2022 17:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240370AbiHNVUs (ORCPT ); Sun, 14 Aug 2022 17:20:48 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20E49B7F8 for ; Sun, 14 Aug 2022 14:20:44 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1660512042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KSSfD6zQrXSxaxG/WfiMiw11chh7wGoURyPeSFWijZg=; b=XVYuMqFhV3ebUn9qqWjlZ3npkv+smqZxybB+OB3c8W/SD/3QIOAKil8bQGZl0CIZ8Ulu2F RPaSm5ydlv58LKfYclz4YeQ9Q/WYujcKmKhFWp7CfftePiwF5BScdQv9cWWIQaw3AWB+f+ LyBtidH3codBhcQkaCM7U1jx3Se0BRE= From: Kent Overstreet To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Kent Overstreet , Andy Shevchenko Subject: [PATCH 05/32] lib/string_helpers: string_get_size() now returns characters wrote Date: Sun, 14 Aug 2022 17:19:44 -0400 Message-Id: <20220814212011.1727798-6-kent.overstreet@linux.dev> In-Reply-To: <20220814212011.1727798-1-kent.overstreet@linux.dev> References: <20220814212011.1727798-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kent Overstreet printbuf now needs to know the number of characters that would have been written if the buffer was too small, like snprintf(); this changes string_get_size() to return the return value of snprintf(). Signed-off-by: Kent Overstreet Cc: Andy Shevchenko Acked-by: Andy Shevchenko --- include/linux/string_helpers.h | 4 ++-- lib/string_helpers.c | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index c048eaec08..ae4383f0fe 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -19,8 +19,8 @@ enum string_size_units { STRING_UNITS_2, /* use binary powers of 2^10 */ }; -void string_get_size(u64 size, u64 blk_size, enum string_size_units units, - char *buf, int len); +int string_get_size(u64 size, u64 blk_size, enum string_size_units units, + char *buf, int len); #define UNESCAPE_SPACE BIT(0) #define UNESCAPE_OCTAL BIT(1) diff --git a/lib/string_helpers.c b/lib/string_helpers.c index b366c660e6..a48c6a1cdd 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -33,8 +33,8 @@ * at least 9 bytes and will always be zero terminated. * */ -void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, - char *buf, int len) +int string_get_size(u64 size, u64 blk_size, const enum string_size_units units, + char *buf, int len) { static const char *const units_10[] = { "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" @@ -127,8 +127,7 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, else unit = units_str[units][i]; - snprintf(buf, len, "%u%s %s", (u32)size, - tmp, unit); + return snprintf(buf, len, "%u%s %s", (u32)size, tmp, unit); } EXPORT_SYMBOL(string_get_size); -- 2.36.1