diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-28 00:39:48 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-28 00:39:48 +0300 |
commit | aac5485fcac6736f6ded186ed8d2ec8743d08de0 (patch) | |
tree | 55968f31440aaacc8c636142b3d6037d71f697e2 /source/blender/blenlib | |
parent | 008da0ff5eeec0ce9bd1fff0151f003f18f0cdd2 (diff) |
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...
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/BLI_filelist.c | 21 |
1 files changed, 12 insertions, 9 deletions
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); } } } |