From: Wang Shilong Date: Mon, 7 Oct 2013 07:21:47 +0000 (+0800) Subject: Btrfs-progs: make pretty_size_snprintf() return len X-Git-Tag: upstream/4.16.1~3081 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=48d0762f356ebe5d33b93e29377ce38ac17ab360;p=platform%2Fupstream%2Fbtrfs-progs.git Btrfs-progs: make pretty_size_snprintf() return len Sometimes, we need to catch length of snprintf() in pretty_size_snprintf(). Signed-off-by: Wang Shilong Signed-off-by: David Sterba Signed-off-by: Chris Mason --- diff --git a/utils.c b/utils.c index 2f1d54f..69ae21f 100644 --- a/utils.c +++ b/utils.c @@ -1190,13 +1190,13 @@ out: } static char *size_strs[] = { "", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"}; -void pretty_size_snprintf(u64 size, char *str, size_t str_bytes) +int pretty_size_snprintf(double size, char *str, size_t str_bytes) { int num_divs = 0; float fraction; if (str_bytes == 0) - return; + return 0; if( size < 1024 ){ fraction = size; @@ -1212,11 +1212,12 @@ void pretty_size_snprintf(u64 size, char *str, size_t str_bytes) if (num_divs >= ARRAY_SIZE(size_strs)) { str[0] = '\0'; - return; + return -1; } fraction = (float)last_size / 1024; } - snprintf(str, str_bytes, "%.2f%s", fraction, size_strs[num_divs]); + return snprintf(str, str_bytes, "%.2f%s", fraction, + size_strs[num_divs]); } /* diff --git a/utils.h b/utils.h index a6d3e5e..7a74826 100644 --- a/utils.h +++ b/utils.h @@ -49,11 +49,11 @@ int check_mounted_where(int fd, const char *file, char *where, int size, int btrfs_device_already_in_root(struct btrfs_root *root, int fd, int super_offset); -void pretty_size_snprintf(u64 size, char *str, size_t str_bytes); +int pretty_size_snprintf(double size, char *str, size_t str_bytes); #define pretty_size(size) \ ({ \ static __thread char _str[24]; \ - pretty_size_snprintf((size), _str, sizeof(_str)); \ + (void)pretty_size_snprintf((size), _str, sizeof(_str)); \ _str; \ })