summaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2014-12-09 16:27:27 +0800
committerDavid Sterba <dsterba@suse.cz>2014-12-10 13:44:52 +0100
commit1c4d47c037c78cce4c3d5ad7502387ebfd4370cb (patch)
tree67043b65afdd62529a234362530b4d747e511040 /utils.h
parent43c36f3cfd4e076e8bc882a2f53619b88be15e2e (diff)
btrfs-progs: Add count_digits() function to help calculate filename len.
Add count_digits() function in utils.h to help calculate filename with ino suffix. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/utils.h b/utils.h
index 8950fca3..6cbb7b89 100644
--- a/utils.h
+++ b/utils.h
@@ -169,4 +169,22 @@ int find_next_key(struct btrfs_path *path, struct btrfs_key *key);
char* btrfs_group_type_str(u64 flag);
char* btrfs_group_profile_str(u64 flag);
+/*
+ * Get the length of the string converted from a u64 number.
+ *
+ * Result is equal to log10(num) + 1, but without the use of math library.
+ */
+static inline int count_digits(u64 num)
+{
+ int ret = 0;
+
+ if (num == 0)
+ return 1;
+ while (num > 0) {
+ ret++;
+ num /= 10;
+ }
+ return ret;
+}
+
#endif