[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-trivial] [PATCH] hw/i386/pc: Use fstat in get_file_size()
From: |
Fabien Siron |
Subject: |
[Qemu-trivial] [PATCH] hw/i386/pc: Use fstat in get_file_size() |
Date: |
Sun, 5 Jun 2016 08:14:39 +0000 |
As mentioned in the comment, fstat is quite simpler than playing with
ftell() and fseek()
Signed-off-by: Fabien Siron <address@hidden>
---
hw/i386/pc.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index e29ccc8..186dfe4 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -802,16 +802,9 @@ static FWCfgState *bochs_bios_init(AddressSpace *as,
PCMachineState *pcms)
static long get_file_size(FILE *f)
{
- long where, size;
+ struct stat st;
- /* XXX: on Unix systems, using fstat() probably makes more sense */
-
- where = ftell(f);
- fseek(f, 0, SEEK_END);
- size = ftell(f);
- fseek(f, where, SEEK_SET);
-
- return size;
+ return fstat(fileno(f), &st) < 0 ? -1: st.st_size;
}
static void load_linux(PCMachineState *pcms,
@@ -835,7 +828,7 @@ static void load_linux(PCMachineState *pcms,
/* load the kernel header */
f = fopen(kernel_filename, "rb");
- if (!f || !(kernel_size = get_file_size(f)) ||
+ if (!f || (kernel_size = get_file_size(f)) <= 0 ||
fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) !=
MIN(ARRAY_SIZE(header), kernel_size)) {
fprintf(stderr, "qemu: could not load kernel '%s': %s\n",
--
2.8.3
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-trivial] [PATCH] hw/i386/pc: Use fstat in get_file_size(),
Fabien Siron <=