summaryrefslogtreecommitdiff
path: root/util/romcc/romcc.c
diff options
context:
space:
mode:
authorPatrick Georgi <patrick@georgi-clan.de>2014-08-11 09:27:18 +0200
committerPatrick Georgi <patrick@georgi-clan.de>2014-08-12 11:53:24 +0200
commit32eeff4b6eaf5e0bf1979cc9d08ac60d8d011354 (patch)
tree056545cb95de31f837822dabfbdbb3c7f4dc9f16 /util/romcc/romcc.c
parent77b182a31a17e237da2350b0290301f5ce51d9d8 (diff)
downloadcoreboot-32eeff4b6eaf5e0bf1979cc9d08ac60d8d011354.tar.xz
util: replace fseek/ftell/rewind with fstat
It's a more direct approach to get the file size. Change-Id: If49df26bf4996bd556c675f3a673d0003b4adf89 Signed-off-by: Patrick Georgi <patrick@georgi-clan.de> Reviewed-on: http://review.coreboot.org/6594 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'util/romcc/romcc.c')
-rw-r--r--util/romcc/romcc.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/util/romcc/romcc.c b/util/romcc/romcc.c
index 49b4dd4720..01d836cef3 100644
--- a/util/romcc/romcc.c
+++ b/util/romcc/romcc.c
@@ -223,6 +223,14 @@ static int exists(const char *dirname, const char *filename)
return does_exist;
}
+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;
+}
static char *slurp_file(const char *dirname, const char *filename, off_t *r_size)
{
@@ -246,9 +254,10 @@ static char *slurp_file(const char *dirname, const char *filename, off_t *r_size
die("Cannot open '%s' : %s\n",
filename, strerror(errno));
}
- fseek(file, 0, SEEK_END);
- size = ftell(file);
- fseek(file, 0, SEEK_SET);
+ size = get_file_size(file);
+ if (size == -1) {
+ die("Could not fetch size of '%s': %s\n", filename, strerror(errno));
+ }
*r_size = size +1;
buf = xmalloc(size +2, filename);
buf[size] = '\n'; /* Make certain the file is newline terminated */