All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-trivial] [PATCH] pc: Use fstat in get_file_size()
@ 2016-06-01 14:23 Fabien Siron
  2016-06-05  7:15   ` [Qemu-devel] " Michael Tokarev
  2016-06-05  7:15   ` [Qemu-devel] " Michael Tokarev
  0 siblings, 2 replies; 5+ messages in thread
From: Fabien Siron @ 2016-06-01 14:23 UTC (permalink / raw)
  To: qemu-trivial; +Cc: Fabien Siron

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, 5 insertions(+), 8 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 99437e0..fecb067 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -801,16 +801,13 @@ static FWCfgState *bochs_bios_init(AddressSpace *as, PCMachineState *pcms)
 
 static long get_file_size(FILE *f)
 {
-    long where, size;
+    struct stat stat;
+    int fd;
 
-    /* XXX: on Unix systems, using fstat() probably makes more sense */
+    fd = fileno(f);
+    fstat(fd, &stat);
 
-    where = ftell(f);
-    fseek(f, 0, SEEK_END);
-    size = ftell(f);
-    fseek(f, where, SEEK_SET);
-
-    return size;
+    return stat.st_size;
 }
 
 static void load_linux(PCMachineState *pcms,
-- 
2.8.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-06-05  7:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-01 14:23 [Qemu-trivial] [PATCH] pc: Use fstat in get_file_size() Fabien Siron
2016-06-05  7:15 ` Michael Tokarev
2016-06-05  7:15   ` [Qemu-devel] " Michael Tokarev
2016-06-05  7:15 ` [Qemu-trivial] " Michael Tokarev
2016-06-05  7:15   ` [Qemu-devel] " Michael Tokarev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.