[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-ppc] [Qemu-devel] [PATCH 1/2] extract file_load() function fro
From: |
Yin Olivia-R63875 |
Subject: |
Re: [Qemu-ppc] [Qemu-devel] [PATCH 1/2] extract file_load() function from rom_add_file() for reusing |
Date: |
Fri, 17 Aug 2012 09:40:30 +0000 |
Hi Peter,
Thanks for the reminder. I'll update the second patch to use
g_file_get_contents().
Best Regards,
Olivia
> -----Original Message-----
> From: Peter Maydell [mailto:address@hidden
> Sent: Thursday, August 16, 2012 7:36 PM
> To: Yin Olivia-R63875
> Cc: address@hidden; address@hidden
> Subject: Re: [Qemu-devel] [PATCH 1/2] extract file_load() function from
> rom_add_file() for reusing
>
> On 14 August 2012 08:49, Olivia Yin <address@hidden> wrote:
> > Sanity check in rom_add_file() could be reused by other image loaders.
> >
> > Signed-off-by: Olivia Yin <address@hidden>
> > ---
> > This patch is based on branch 'ppc-next' of Alex's upstream QEMU repo:
> > http://repo.or.cz/r/qemu/agraf.git
> >
> > hw/loader.c | 61 +++++++++++++++++++++++++++++++--------------------
> -------
> > 1 files changed, 33 insertions(+), 28 deletions(-)
> >
> > diff --git a/hw/loader.c b/hw/loader.c index 33acc2f..f2099b6 100644
> > --- a/hw/loader.c
> > +++ b/hw/loader.c
> > @@ -86,6 +86,36 @@ int load_image(const char *filename, uint8_t *addr)
> > return size;
> > }
> >
> > +static int file_load(const char *file, uint8_t **data) {
> > + int fd = -1;
> > + ssize_t rc, size;
> > +
> > + fd = open(file, O_RDONLY | O_BINARY);
> > + if (fd == -1) {
> > + fprintf(stderr, "Could not open file '%s': %s\n",
> > + file, strerror(errno));
> > + return -1;
> > + }
> > +
> > + size = lseek(fd, 0, SEEK_END);
> > + *data = g_malloc0(size);
> > + lseek(fd, 0, SEEK_SET);
> > + rc = read(fd, *data, size);
> > + if (rc != size) {
> > + fprintf(stderr, "file %-20s: read error: rc=%zd
> (expected %zd)\n",
> > + file, rc, size);
> > + goto err;
> > + }
> > + close(fd);
> > + return size;
> > +err:
> > + if (fd != -1)
> > + close(fd);
> > + g_free(*data);
> > + return -1;
> > +}
>
> Isn't this function effectively a reimplementation of the glib
> g_file_get_contents() function? It would probably be better to just make
> the callers use that instead.
>
> -- PMM