From aac5485fcac6736f6ded186ed8d2ec8743d08de0 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sat, 27 Jun 2015 23:39:48 +0200 Subject: Fix T45216: File Browser shows negative sizes for large files. Simply backport small part of work from asset-experiments here (using double and adding tera-bytes unit), looks like off_t is not always 64bits even on a 64bit OS... --- source/blender/blenlib/intern/BLI_filelist.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/intern/BLI_filelist.c b/source/blender/blenlib/intern/BLI_filelist.c index e9ed785efc7..786eaa74df8 100644 --- a/source/blender/blenlib/intern/BLI_filelist.c +++ b/source/blender/blenlib/intern/BLI_filelist.c @@ -218,7 +218,7 @@ static void bli_adddirstrings(struct BuildDirCtx *dir_ctx) const char *types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"}; /* symbolic display, indexed by mode field value */ int num; - off_t st_size; + double size; struct direntry *file; struct tm *tm; time_t zero = 0; @@ -288,19 +288,22 @@ static void bli_adddirstrings(struct BuildDirCtx *dir_ctx) * will buy us some time until files get bigger than 4GB or until * everyone starts using __USE_FILE_OFFSET64 or equivalent. */ - st_size = file->s.st_size; + size = (double)file->s.st_size; - if (st_size > 1024 * 1024 * 1024) { - BLI_snprintf(file->size, sizeof(file->size), "%.2f GiB", ((double)st_size) / (1024 * 1024 * 1024)); + if (size > 1024.0 * 1024.0 * 1024.0 * 1024.0) { + BLI_snprintf(file->size, sizeof(file->size), "%.1f TiB", size / (1024.0 * 1024.0 * 1024.0 * 1024.0)); } - else if (st_size > 1024 * 1024) { - BLI_snprintf(file->size, sizeof(file->size), "%.1f MiB", ((double)st_size) / (1024 * 1024)); + else if (size > 1024.0 * 1024.0 * 1024.0) { + BLI_snprintf(file->size, sizeof(file->size), "%.1f GiB", size / (1024.0 * 1024.0 * 1024.0)); } - else if (st_size > 1024) { - BLI_snprintf(file->size, sizeof(file->size), "%d KiB", (int)(st_size / 1024)); + else if (size > 1024.0 * 1024.0) { + BLI_snprintf(file->size, sizeof(file->size), "%.1f MiB", size / (1024.0 * 1024.0)); + } + else if (size > 1024.0) { + BLI_snprintf(file->size, sizeof(file->size), "%.1f KiB", size / 1024.0); } else { - BLI_snprintf(file->size, sizeof(file->size), "%d B", (int)st_size); + BLI_snprintf(file->size, sizeof(file->size), "%d B", (int)size); } } } -- cgit v1.2.3