[coreboot-gerrit] New patch to review for coreboot: Don't use fileno() to get file size

Stefan Reinauer (stefan.reinauer@coreboot.org) gerrit at coreboot.org
Mon Sep 14 17:49:02 CET 2015


Stefan Reinauer (stefan.reinauer at coreboot.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11636

-gerrit

commit 029438246a669e6327e6452fe385c067e8c863ca
Author: Stefan Reinauer <reinauer at chromium.org>
Date:   Mon Sep 14 10:46:44 2015 -0700

    Don't use fileno() to get file size
    
    fileno() is a mess on some operating systems. Don't
    deliberately convert between FILE * and file handles.
    
    Change-Id: I5be62a731f928333ea2e5843d81f541453fdb396
    Signed-off-by: Stefan Reinauer <stefan.reinauer at coreboot.org>
---
 util/cbfstool/common.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index f8ce2f9..44e40a9 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -46,14 +46,13 @@ int is_big_endian(void)
 
 static off_t get_file_size(FILE *f)
 {
-	struct stat s;
-	int fd = fileno(f);
-	if (fd == -1) return -1;
-	if (fstat(fd, &s) == -1) return -1;
-	return s.st_size;
+	off_t fsize;
+	fseek(f, 0, SEEK_END);
+	fsize = ftell(f);
+	fseek(f, 0, SEEK_SET);
 }
-/* Buffer and file I/O */
 
+/* Buffer and file I/O */
 int buffer_create(struct buffer *buffer, size_t size, const char *name)
 {
 	buffer->name = strdup(name);



More information about the coreboot-gerrit mailing list