diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-04-25 21:26:28 +0200 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-09-12 05:59:47 +0200 |
commit | 83feeb195592b533541ff6399c8084e5b7c59677 (patch) | |
tree | c2aba50ec1f7744723b6ab9b0ba71c2f72ba7c4a /lib/string_helpers.c | |
parent | stacktrace: Export stack_trace_save_tsk (diff) | |
download | linux-83feeb195592b533541ff6399c8084e5b7c59677.tar.xz linux-83feeb195592b533541ff6399c8084e5b7c59677.zip |
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@linux.dev>
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r-- | lib/string_helpers.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 9982344cca34..7713f73e66b0 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -31,9 +31,11 @@ * giving the size in the required units. @buf should have room for * at least 9 bytes and will always be zero terminated. * + * Return value: number of characters of output that would have been written + * (which may be greater than len, if output was truncated). */ -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,8 +128,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); |