[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55039] trunk/blender/source/blender/ blenlib/intern/storage.c: patch [#34103] storage_bli_file_size.patch

Campbell Barton ideasman42 at gmail.com
Tue Mar 5 05:11:57 CET 2013


Revision: 55039
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55039
Author:   campbellbarton
Date:     2013-03-05 04:11:55 +0000 (Tue, 05 Mar 2013)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/storage.c

Modified: trunk/blender/source/blender/blenlib/intern/storage.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/storage.c	2013-03-05 03:59:38 UTC (rev 55038)
+++ trunk/blender/source/blender/blenlib/intern/storage.c	2013-03-05 04:11:55 UTC (rev 55039)
@@ -506,11 +506,10 @@
  */
 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_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;
 }
 
 /**




More information about the Bf-blender-cvs mailing list