Add count_digit() function in utils.h to help calculate filename with ino suffix.
Signed-off-by: Qu Wenruo <quwen...@cn.fujitsu.com> --- Changelog: v4: Newly introduced. --- utils.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/utils.h b/utils.h index 289e86b..f68d6d8 100644 --- a/utils.h +++ b/utils.h @@ -161,4 +161,22 @@ static inline u64 btrfs_min_dev_size(u32 leafsize) int find_next_key(struct btrfs_path *path, struct btrfs_key *key); +/* + * 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_digit(u64 num) +{ + int ret = 0; + + if (num == 0) + return 1; + while (num > 0) { + ret++; + num /= 10; + } + return ret; +} + #endif -- 2.1.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html