From: Fabien Siron <fabien.siron@epita.fr>
To: qemu-trivial@nongnu.org
Cc: qemu-devel@nongnu.org, Fabien Siron <fabien.siron@epita.fr>
Subject: [Qemu-devel] [PATCH] hw/i386/pc: Use fstat in get_file_size()
Date: Sun, 5 Jun 2016 08:14:39 +0000 [thread overview]
Message-ID: <20160605081439.26794-1-fabien.siron@epita.fr> (raw)
As mentioned in the comment, fstat is quite simpler than playing with
ftell() and fseek()
Signed-off-by: Fabien Siron <fabien.siron@epita.fr>
---
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
reply other threads:[~2016-06-05 9:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160605081439.26794-1-fabien.siron@epita.fr \
--to=fabien.siron@epita.fr \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).