summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-04-25 15:26:28 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-03-13 11:32:47 -0400
commit270ba26a9d41292a108a825f8bc9fe0332b8e706 (patch)
tree9128f8356930ab3ef3b96034baa788305c84dd84
parentff4ac40126268f5abe064ba67d7bf9ddcb933c49 (diff)
lib/string_helpers: string_get_size() now returns characters wrote
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 the return value of snprintf(). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--include/linux/string_helpers.h4
-rw-r--r--lib/string_helpers.c6
2 files changed, 5 insertions, 5 deletions
diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
index 8530c7328269..ec90505dae31 100644
--- a/include/linux/string_helpers.h
+++ b/include/linux/string_helpers.h
@@ -18,8 +18,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);
int parse_int_array_user(const char __user *from, size_t count, int **array);
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 593b29fece32..aa8d0af10aa7 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -32,8 +32,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"
@@ -126,7 +126,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);