int rom_add_file(const char *file, const char *fw_dir, const char *fw_file,

                 target_phys_addr_t addr)

{

    Rom *rom;

    int rc, fd = -1;



    rom = qemu_mallocz(sizeof(*rom));

    rom->name = qemu_strdup(file);

    rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);

    if (rom->path == NULL) {

        rom->path = qemu_strdup(file);

    }



    fd = open(rom->path, O_RDONLY | O_BINARY);

    if (fd == -1) {

        fprintf(stderr, "Could not open option rom '%s': %s\n",

                rom->path, strerror(errno));

        goto err;

    }



    rom->fw_dir  = fw_dir  ? qemu_strdup(fw_dir)  : NULL;

    rom->fw_file = fw_file ? qemu_strdup(fw_file) : NULL;

    rom->addr    = addr;

    rom->romsize = lseek(fd, 0, SEEK_END);

    rom->data    = qemu_mallocz(rom->romsize);

    lseek(fd, 0, SEEK_SET);

    rc = read(fd, rom->data, rom->romsize);

    if (rc != rom->romsize) {

        fprintf(stderr, "rom: file %-20s: read error: rc=%d (expected %zd)\n",

                rom->name, rc, rom->romsize);

        goto err;

    }

    close(fd);

    rom_insert(rom);

    return 0;



err:

    if (fd != -1)

        close(fd);

    qemu_free(rom->data);

    qemu_free(rom->path);

    qemu_free(rom->name);

    qemu_free(rom);

    return -1;

}

int rom_add_file(const char *file, const char *fw_dir, const char *fw_file,

                 target_phys_addr_t addr)

{

    Rom *rom;

    int rc, fd = -1;



    rom = qemu_mallocz(sizeof(*rom));

    rom->name = qemu_strdup(file);

    rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);

    if (rom->path == NULL) {

        rom->path = qemu_strdup(file);

    }



    fd = open(rom->path, O_RDONLY | O_BINARY);

    if (fd == -1) {

        fprintf(stderr, "Could not open option rom '%s': %s\n",

                rom->path, strerror(errno));

        goto err;

    }



    rom->fw_dir  = fw_dir  ? qemu_strdup(fw_dir)  : NULL;

    rom->fw_file = fw_file ? qemu_strdup(fw_file) : NULL;

    rom->addr    = addr;

    rom->romsize = lseek(fd, 0, SEEK_END);

    rom->data    = qemu_mallocz(rom->romsize);

    lseek(fd, 0, SEEK_SET);

    rc = read(fd, rom->data, rom->romsize);

    if (rc != rom->romsize) {

        fprintf(stderr, "rom: file %-20s: read error: rc=%d (expected %zd)\n",

                rom->name, rc, rom->romsize);

        goto err;

    }

    close(fd);

    rom_insert(rom);

    return 0;



err:

    if (fd != -1)

        close(fd);

    qemu_free(rom->data);

    qemu_free(rom->path);

    qemu_free(rom->name);

    qemu_free(rom);

    return -1;

}

int FUNC_0(const char *VAR_0, const char *VAR_1, const char *VAR_2,

                 target_phys_addr_t VAR_3)

{

    Rom *rom;

    int VAR_4, VAR_5 = -1;



    rom = qemu_mallocz(sizeof(*rom));

    rom->name = qemu_strdup(VAR_0);

    rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);

    if (rom->path == NULL) {

        rom->path = qemu_strdup(VAR_0);

    }



    VAR_5 = open(rom->path, O_RDONLY | O_BINARY);

    if (VAR_5 == -1) {

        fprintf(stderr, "Could not open option rom '%s': %s\n",

                rom->path, strerror(errno));

        goto err;

    }



    rom->VAR_1  = VAR_1  ? qemu_strdup(VAR_1)  : NULL;

    rom->VAR_2 = VAR_2 ? qemu_strdup(VAR_2) : NULL;

    rom->VAR_3    = VAR_3;

    rom->romsize = lseek(VAR_5, 0, SEEK_END);

    rom->data    = qemu_mallocz(rom->romsize);

    lseek(VAR_5, 0, SEEK_SET);

    VAR_4 = read(VAR_5, rom->data, rom->romsize);

    if (VAR_4 != rom->romsize) {

        fprintf(stderr, "rom: VAR_0 %-20s: read error: VAR_4=%d (expected %zd)\n",

                rom->name, VAR_4, rom->romsize);

        goto err;

    }

    close(VAR_5);

    rom_insert(rom);

    return 0;



err:

    if (VAR_5 != -1)

        close(VAR_5);

    qemu_free(rom->data);

    qemu_free(rom->path);

    qemu_free(rom->name);

    qemu_free(rom);

    return -1;

}

int FUNC_0(const char *VAR_0, const char *VAR_1, const char *VAR_2,
target_phys_addr_t VAR_3)
{ Rom *rom; int VAR_4, VAR_5 = -1; rom = qemu_mallocz(sizeof(*rom)); rom->name = qemu_strdup(VAR_0); rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name); if (rom->path == NULL) { rom->path = qemu_strdup(VAR_0); } VAR_5 = open(rom->path, O_RDONLY | O_BINARY); if (VAR_5 == -1) { fprintf(stderr, "Could not open option rom '%s': %s\n",
rom->path, strerror(errno)); goto err; } rom->VAR_1  = VAR_1  ? qemu_strdup(VAR_1)  : NULL; rom->VAR_2 = VAR_2 ? qemu_strdup(VAR_2) : NULL; rom->VAR_3    = VAR_3; rom->romsize = lseek(VAR_5, 0, SEEK_END); rom->data    = qemu_mallocz(rom->romsize); lseek(VAR_5, 0, SEEK_SET); VAR_4 = read(VAR_5, rom->data, rom->romsize); if (VAR_4 != rom->romsize) { fprintf(stderr, "rom: VAR_0 %-20s: read error: VAR_4=%d (expected %zd)\n",
rom->name, VAR_4, rom->romsize); goto err; } close(VAR_5); rom_insert(rom); return 0; err:
if (VAR_5 != -1)
close(VAR_5); qemu_free(rom->data); qemu_free(rom->path); qemu_free(rom->name); qemu_free(rom); return -1; }