summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils.c18
-rw-r--r--utils.h7
2 files changed, 19 insertions, 6 deletions
diff --git a/utils.c b/utils.c
index b4983812..e89707c7 100644
--- a/utils.c
+++ b/utils.c
@@ -1479,6 +1479,24 @@ out:
return ret;
}
+/*
+ * Note: this function uses a static per-thread buffer. Do not call this
+ * function more than 10 times within one argument list!
+ */
+const char *pretty_size_mode(u64 size, unsigned mode)
+{
+ static __thread int ps_index = 0;
+ static __thread char ps_array[10][32];
+ char *ret;
+
+ ret = ps_array[ps_index];
+ ps_index++;
+ ps_index %= 10;
+ (void)pretty_size_snprintf(size, ret, 32, mode);
+
+ return ret;
+}
+
static const char* unit_suffix_binary[] =
{ "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"};
static const char* unit_suffix_decimal[] =
diff --git a/utils.h b/utils.h
index 9b6a07b6..7260035b 100644
--- a/utils.h
+++ b/utils.h
@@ -129,12 +129,7 @@ int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
int pretty_size_snprintf(u64 size, char *str, size_t str_bytes, unsigned unit_mode);
#define pretty_size(size) pretty_size_mode(size, UNITS_DEFAULT)
-#define pretty_size_mode(size, mode) \
- ({ \
- static __thread char _str[32]; \
- (void)pretty_size_snprintf((size), _str, sizeof(_str), (mode)); \
- _str; \
- })
+const char *pretty_size_mode(u64 size, unsigned mode);
int get_mountpt(char *dev, char *mntpt, size_t size);
u64 parse_size(char *s);