summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2017-02-01 16:09:47 +0100
committerDavid Sterba <dsterba@suse.com>2017-03-08 13:00:46 +0100
commita09f0e96e79e27fc8f34ddb4077682fe09f43cf2 (patch)
tree7757be7416864215f77c9801d1d7bcfcdb4b8eb2
parentca92914804be310293c0b447de9fcd79ffb728ce (diff)
btrfs-progs: move utils code out of header
There are not performance critical static inlines, we can do the normal declaration/definition split for various helpers. Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--utils.c53
-rw-r--r--utils.h61
2 files changed, 59 insertions, 55 deletions
diff --git a/utils.c b/utils.c
index e7bbefbb..5aab60d3 100644
--- a/utils.c
+++ b/utils.c
@@ -2266,6 +2266,32 @@ unsigned int get_unit_mode_from_arg(int *argc, char *argv[], int df_mode)
return unit_mode;
}
+u64 div_factor(u64 num, int factor)
+{
+ if (factor == 10)
+ return num;
+ num *= factor;
+ num /= 10;
+ return num;
+}
+/*
+ * 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.
+ */
+int count_digits(u64 num)
+{
+ int ret = 0;
+
+ if (num == 0)
+ return 1;
+ while (num > 0) {
+ ret++;
+ num /= 10;
+ }
+ return ret;
+}
+
int string_is_numerical(const char *str)
{
if (!str)
@@ -2397,6 +2423,7 @@ out:
return ret;
}
+/* Set the seed manually */
void init_rand_seed(u64 seed)
{
int i;
@@ -2446,6 +2473,7 @@ u32 rand_u32(void)
return (u32)jrand48(rand_seed);
}
+/* Return random number in range [0, upper) */
unsigned int rand_range(unsigned int upper)
{
__init_seed();
@@ -2456,6 +2484,31 @@ unsigned int rand_range(unsigned int upper)
return (unsigned int)(jrand48(rand_seed) % upper);
}
+int rand_int(void)
+{
+ return (int)(rand_u32());
+}
+
+u64 rand_u64(void)
+{
+ u64 ret = 0;
+
+ ret += rand_u32();
+ ret <<= 32;
+ ret += rand_u32();
+ return ret;
+}
+
+u16 rand_u16(void)
+{
+ return (u16)(rand_u32());
+}
+
+u8 rand_u8(void)
+{
+ return (u8)(rand_u32());
+}
+
void btrfs_config_init(void)
{
}
diff --git a/utils.h b/utils.h
index 5861bfe6..a9d689e4 100644
--- a/utils.h
+++ b/utils.h
@@ -138,32 +138,8 @@ int find_next_key(struct btrfs_path *path, struct btrfs_key *key);
const char* btrfs_group_type_str(u64 flag);
const 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;
-}
-
-static inline u64 div_factor(u64 num, int factor)
-{
- if (factor == 10)
- return num;
- num *= factor;
- num /= 10;
- return num;
-}
+int count_digits(u64 num);
+u64 div_factor(u64 num, int factor);
int btrfs_tree_search2_ioctl_supported(int fd);
@@ -292,37 +268,12 @@ static inline int __error_on(int condition, const char *fmt, ...)
}
/* Pseudo random number generator wrappers */
+int rand_int(void);
+u8 rand_u8(void);
+u16 rand_u16(void);
u32 rand_u32(void);
-
-static inline int rand_int(void)
-{
- return (int)(rand_u32());
-}
-
-static inline u64 rand_u64(void)
-{
- u64 ret = 0;
-
- ret += rand_u32();
- ret <<= 32;
- ret += rand_u32();
- return ret;
-}
-
-static inline u16 rand_u16(void)
-{
- return (u16)(rand_u32());
-}
-
-static inline u8 rand_u8(void)
-{
- return (u8)(rand_u32());
-}
-
-/* Return random number in range [0, limit) */
+u64 rand_u64(void);
unsigned int rand_range(unsigned int upper);
-
-/* Also allow setting the seed manually */
void init_rand_seed(u64 seed);
#endif