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>
master
Qu Wenruo 2014-12-09 16:27:27 +08:00 committed by David Sterba
parent 43c36f3cfd
commit 1c4d47c037
1 changed files with 18 additions and 0 deletions

18
utils.h
View File

@ -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