summaryrefslogtreecommitdiff
path: root/lib/string_helpers.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-04-25 15:26:28 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2022-10-05 16:49:06 -0400
commit315692ba517c9d58c00c0d84e73b1565f50b600d (patch)
tree77f3cafe309ce51a1bb8e8439992d1ae61249aaa /lib/string_helpers.c
parent68715f789b2a5249d42085c6d0df2e85374934e5 (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>
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r--lib/string_helpers.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 7be20bcc6137..d247bf945f16 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);