Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-03-05 08:11:55 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-03-05 08:11:55 +0400
commit2fc10e330335882390dfe7c70bcc78e975642b19 (patch)
treefbafbd29b45db8bf0bfbf95844e038ac386a9ffa /source/blender/blenlib/intern/storage.c
parentb8315afeed0bc4ec1c9d9f7772957d372807b8b2 (diff)
patch [#34103] storage_bli_file_size.patch
from Lawrence D'Oliveiro (ldo) more efficient implementation of BLI_file_size that doesn't open the file.
Diffstat (limited to 'source/blender/blenlib/intern/storage.c')
-rw-r--r--source/blender/blenlib/intern/storage.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 0b45ff7fb6c..6bc8980c646 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -506,11 +506,10 @@ void BLI_free_filelist(struct direntry *filelist, unsigned int nrentries)
*/
size_t BLI_file_descriptor_size(int file)
{
- struct stat buf;
-
- if (file < 0) return (-1);
- fstat(file, &buf); /* CHANGE */
- return (buf.st_size);
+ struct stat st;
+ if ((file < 0) || (fstat(file, &st) == -1))
+ return -1;
+ return st.st_size;
}
/**
@@ -518,15 +517,10 @@ size_t BLI_file_descriptor_size(int file)
*/
size_t BLI_file_size(const char *path)
{
- /* 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;
}
/**