Page MenuHome

storage_bli_file_size.patch

storage_bli_file_size.patch

commit eba3f5bb233001d55d472a4f83b126ca74bcadfb
Author: Lawrence D'Oliveiro <ldo@geek-central.gen.nz>
Date: Mon Feb 18 10:18:09 2013 +0000
more efficient implementation of BLI_file_size that doesn't open the file
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 0f1a1e4..dee12e9 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -502,18 +502,12 @@ size_t BLI_file_descriptor_size(int file)
size_t BLI_file_size(const char *path)
/* returns the size of a file. */
{
- /* FIXME: opening and closing the file is inefficient. Why not use stat(2) instead? */
- int size, file = BLI_open(path, O_BINARY | O_RDONLY, 0);
-
- if (file == -1)
+ struct stat stats;
+ if (BLI_stat(path, &stats) == -1)
return -1;
-
- size = BLI_file_descriptor_size(file);
- close(file);
- return size;
+ return stats.st_size;
}
-
int BLI_exists(const char *name)
/* returns the st_mode from statting the specified path name, or 0 if it couldn't be statted
(most likely doesn't exist or no access). */

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e4/c7/4013e622a56d059f8ec9401ec360

Event Timeline