summaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
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