summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWang Shilong <wangsl.fnst@cn.fujitsu.com>2013-10-07 15:21:47 +0800
committerChris Mason <chris.mason@fusionio.com>2013-10-16 08:23:12 -0400
commit48d0762f356ebe5d33b93e29377ce38ac17ab360 (patch)
tree0dd8fe6a2f9d6c3a974e5893868ba001101a848d
parent133907d465945428d36242f8bbc9b7a5b49a26c5 (diff)
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 <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
-rw-r--r--utils.c9
-rw-r--r--utils.h4
2 files changed, 7 insertions, 6 deletions
diff --git a/utils.c b/utils.c
index 2f1d54fb..69ae21f2 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 a6d3e5ec..7a748266 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; \
})