summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Reinauer <reinauer@chromium.org>2015-09-14 10:46:44 -0700
committerStefan Reinauer <stefan.reinauer@coreboot.org>2015-09-17 19:17:06 +0000
commit1bb487c474c378cf61bd28f83b9eb87162ffc1c4 (patch)
tree808cc485cf77413c737f71a9e5def9fa56e1c648
parentd66f1da846f8e524a6211518c46a993d563b4ffc (diff)
cbfstool: 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@coreboot.org> Reviewed-on: http://review.coreboot.org/11636 Tested-by: build bot (Jenkins) Reviewed-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
-rw-r--r--util/cbfstool/common.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index f8ce2f9e12..e0474b3435 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -46,14 +46,14 @@ 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);
+ return fsize;
}
-/* 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);