summaryrefslogtreecommitdiff
path: root/util/arm_boot_tools
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/arm_boot_tools
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/arm_boot_tools')
-rw-r--r--util/arm_boot_tools/mksunxiboot/mksunxiboot.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/util/arm_boot_tools/mksunxiboot/mksunxiboot.c b/util/arm_boot_tools/mksunxiboot/mksunxiboot.c
index af8450c338..cb8e8f9e76 100644
--- a/util/arm_boot_tools/mksunxiboot/mksunxiboot.c
+++ b/util/arm_boot_tools/mksunxiboot/mksunxiboot.c
@@ -11,6 +11,9 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <errno.h>
/* boot head definition from sun4i boot code */
@@ -108,12 +111,11 @@ static void fill_header(struct boot_file_head *hdr, size_t load_size)
static long int fsize(FILE *file)
{
- long int size;
-
- fseek(file, 0L, SEEK_END);
- size = ftell(file);
- fseek(file, 0L, SEEK_SET);
- return size;
+ struct stat s;
+ int fd = fileno(file);
+ if (fd == -1) return -1;
+ if (fstat(fd, &s) == -1) return -1;
+ return s.st_size;
}
int main(int argc, char *argv[])
@@ -145,6 +147,10 @@ int main(int argc, char *argv[])
/* Get input file size */
file_size = fsize(fd_in);
+ if (file_size == -1) {
+ fprintf(stderr, "can't determine file size\n");
+ return EXIT_FAILURE;
+ }
if ((file_data = malloc(file_size)) == NULL) {
fprintf(stderr, "Cannot allocate memory\n");
return EXIT_FAILURE;