diff options
author | Zach Brown <zab@redhat.com> | 2013-07-09 13:24:43 -0700 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2013-08-09 14:32:33 +0200 |
commit | 876e3f9380d373ba76f9b6d4c08ff84327956abf (patch) | |
tree | a5cf9f31f77249dadbd35b57f9a0025876db2e27 /utils.h | |
parent | 8e6b7ce746d668d7f2c2b6e0b2075dccf55df01a (diff) |
btrfs-progs: per-thread, per-call pretty buffer
We don't need callers to manage string storage for each pretty_sizes()
call. We can use a macro to have per-thread and per-call static storage
so that pretty_sizes() can be used as many times as needed in printf()
arguments without requiring a bunch of supporting variables.
This lets us have a natural interface at the cost of requiring __thread
and TLS from gcc and a small amount of static storage. This seems
better than the current code or doing something with illegible format
specifier macros.
Signed-off-by: Zach Brown <zab@redhat.com>
Acked-by: Wang Shilong <wangs.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'utils.h')
-rw-r--r-- | utils.h | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -44,7 +44,15 @@ int check_mounted_where(int fd, const char *file, char *where, int size, struct btrfs_fs_devices **fs_devices_mnt); int btrfs_device_already_in_root(struct btrfs_root *root, int fd, int super_offset); -char *pretty_sizes(u64 size); + +void pretty_size_snprintf(u64 size, char *str, size_t str_bytes); +#define pretty_size(size) \ + ({ \ + static __thread char _str[24]; \ + pretty_size_snprintf((size), _str, sizeof(_str)); \ + _str; \ + }) + int get_mountpt(char *dev, char *mntpt, size_t size); int btrfs_scan_block_devices(int run_ioctl); u64 parse_size(char *s); |