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-08-07 17:52:46 -0400
commit3d06b2dc65f0bd2f127c6aad294a1d5c3312ea07 (patch)
tree1d2e2cd408624d02817b9af8f3a676a72fabe3ee
parent5227d22936159901198777a430da134b240ba292 (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.c8
2 files changed, 6 insertions, 6 deletions
diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
index d23c5030901a..77ba096cb586 100644
--- a/include/linux/string_helpers.h
+++ b/include/linux/string_helpers.h
@@ -14,8 +14,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 0x01
#define UNESCAPE_OCTAL 0x02
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 29c490e5d478..8abbdfc12f86 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -30,8 +30,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"
@@ -124,8 +124,8 @@ 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);