Message ID | 1418113652-25088-9-git-send-email-quwenruo@cn.fujitsu.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
On Tue, Dec 09, 2014 at 04:27:27PM +0800, Qu Wenruo wrote:
> +static inline int count_digit(u64 num)
FYI, I've renamed it to count_digits, and updated all callers.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
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
Add count_digit() function in utils.h to help calculate filename with ino suffix. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v4: Newly introduced. --- utils.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)