diff --git a/source/libublsettings.c b/source/libublsettings.c index f7cf7cc..6289ad3 100644 --- a/source/libublsettings.c +++ b/source/libublsettings.c @@ -35,6 +35,14 @@ float yon_size_convert_automatic(int bytes, int *size){ return byte_float; } +long yon_size_to_bytes(long size, int size_mod){ + long final = size; + for (int i=0;i1024;repeats++){ + byte_float=byte_float/1024; + } + if (repeats==-1) { + repeats=0; + byte_float=byte_float/1024; + } + switch(repeats){ + case 0: (*size)='K'; + break; + case 1: (*size)='M'; + break; + case 2: (*size)='G'; + break; + case 3: (*size)='T'; + break; + } + return byte_float; +} + config_str yon_dir_get_contents(char *dir_path, int *size){ config_str dir = NULL; *size=0; diff --git a/source/libublsettings.h b/source/libublsettings.h index 7e39499..543f44f 100644 --- a/source/libublsettings.h +++ b/source/libublsettings.h @@ -1054,15 +1054,18 @@ config_str yon_ubl_get_all_users(int *user_size); int yon_password_get_min_len(); -/** yon_size_convert_automatic(int bytes, int *size) - * [EN] - * - * [RU] - * Делит число [bytes] на 1024 пока оно не станет меньше 1024. - * Возвращает получившееся число и устанавливает [size] равным количеству делений. -*/ +/// @brief Converts bytes amount to kilobytes, megabytes gigabytes or terabytes (K, M, G, T) +/// @param bytes bytes to convert +/// @param size pointer for conversion iteration number. use it with yon_size_get_mod() to get text string of conversion +/// @return converted to kilobytes, megabytes gigabytes or terabytes vaue float yon_size_convert_automatic(int bytes, int *size); +/// @brief Convert size from kilobytes, megabytes gigabytes or terabytes (K, M, G, T) to bytes +/// @param size initial size to convert +/// @param size_mod size modifier. Use yon_get_size_get_from_letter() to get. +/// @return converted to bytes value +long yon_size_to_bytes(long size, int size_mod); + /**yon_get_size_get_from_letter(char size) * [EN] * @@ -1081,6 +1084,10 @@ int yon_get_size_get_from_letter(char size); */ char *yon_size_get_mod(int size); +double yon_size_long_convert_to_mod(double size, char mod); + +double yon_size_long_convert_automatic(unsigned long bytes, char *size); + /**yon_file_path_proceed_spaces(char *path) * [EN] *