diff --git a/src/fs.c b/src/fs.c index 54617c63..2152552b 100644 --- a/src/fs.c +++ b/src/fs.c @@ -212,21 +212,24 @@ void init_fs_bar(struct text_object *obj, const char *arg) obj->data.opaque = prepare_fs_stat(arg); } +static double get_fs_perc(struct fs_stat *fs, int get_free) +{ + double ret = 0.0; + + if(fs && fs->size) { + if(get_free) + ret = fs->avail; + else + ret = fs->size - fs->free; + ret /= fs->size; + } + + return ret; +} + void print_fs_bar(struct text_object *obj, int be_free_bar, char *p, int p_max_size) { - double val = 1.0; - struct fs_stat *fs = obj->data.opaque; - - if (!fs) - return; - - if (fs->size) - val = (double)fs->avail / (double)fs->size; - - if (!be_free_bar) - val = 1.0 - val; - - new_bar(obj, p, p_max_size, (int)(255 * val)); + new_bar(obj, p, p_max_size, (int)(get_fs_perc(obj->data.opaque, be_free_bar) * 255) ); } void init_fs(struct text_object *obj, const char *arg) @@ -236,19 +239,7 @@ void init_fs(struct text_object *obj, const char *arg) void print_fs_perc(struct text_object *obj, int be_free, char *p, int p_max_size) { - struct fs_stat *fs = obj->data.opaque; - int val = 100; - - if (!fs) - return; - - if (fs->size) - val = fs->avail * 100 / fs->size; - - if (!be_free) - val = 100 - val; - - percent_print(p, p_max_size, val); + percent_print(p, p_max_size, (int)(get_fs_perc(obj->data.opaque, be_free) * 100) ); } #define HUMAN_PRINT_FS_GENERATOR(name, expr) \