[Bf-blender-cvs] [768091dd0a1] filebrowser_redesign: Use base 10 for file size strings (MB, KB, ... instead of MiB, KiB, ...)
Julian Eisel
noreply at git.blender.org
Mon Jul 22 23:18:23 CEST 2019
Commit: 768091dd0a1c7f42651e6b9637de0f68fb0f0cc0
Author: Julian Eisel
Date: Mon Jul 22 23:15:46 2019 +0200
Branches: filebrowser_redesign
https://developer.blender.org/rB768091dd0a1c7f42651e6b9637de0f68fb0f0cc0
Use base 10 for file size strings (MB, KB, ... instead of MiB, KiB, ...)
===================================================================
M source/blender/blenlib/intern/BLI_filelist.c
===================================================================
diff --git a/source/blender/blenlib/intern/BLI_filelist.c b/source/blender/blenlib/intern/BLI_filelist.c
index 91f16ca9b7b..c2b51d6bb29 100644
--- a/source/blender/blenlib/intern/BLI_filelist.c
+++ b/source/blender/blenlib/intern/BLI_filelist.c
@@ -261,36 +261,17 @@ unsigned int BLI_filelist_dir_contents(const char *dirname, struct direntry **r_
*/
void BLI_filelist_entry_size_to_string(const struct stat *st,
const uint64_t sz,
- const bool compact,
+ /* Used to change MB -> M, etc. - is that really useful? */
+ const bool UNUSED(compact),
char r_size[FILELIST_DIRENTRY_SIZE_LEN])
{
- double size;
- const char *fmt;
- const char *units[] = {"KiB", "MiB", "GiB", "TiB", NULL};
- const char *units_compact[] = {"K", "M", "G", "T", NULL};
- const char *unit = "B";
-
/*
* Seems st_size is signed 32-bit value in *nix and Windows. This
* will buy us some time until files get bigger than 4GB or until
* everyone starts using __USE_FILE_OFFSET64 or equivalent.
*/
- size = (double)(st ? st->st_size : sz);
-
- if (size > 1024.0) {
- const char **u;
- for (u = compact ? units_compact : units, size /= 1024.0; size > 1024.0 && *(u + 1);
- u++, size /= 1024.0) {
- /* pass */
- }
- fmt = size > 100.0 ? "%.0f %s" : (size > 10.0 ? "%.1f %s" : "%.2f %s");
- unit = *u;
- }
- else {
- fmt = "%.0f %s";
- }
-
- BLI_snprintf(r_size, sizeof(*r_size) * FILELIST_DIRENTRY_SIZE_LEN, fmt, size, unit);
+ double size = (double)(st ? st->st_size : sz);
+ BLI_str_format_byte_unit(r_size, size, true);
}
/**
More information about the Bf-blender-cvs
mailing list