static char *try_uncompress_with_tzx(const char *name) { char *tmp_name = NULL; size_t l = strlen(name); int exit_status; char *argv[4]; /* Check whether the name sounds like a tzx file. */ if (l < 4 || strcasecmp(name + l - 4, ".tzx") != 0) { return NULL; } /* `exec*()' does not want these to be constant... */ argv[0] = lib_stralloc("64tzxtap"); argv[1] = archdep_filename_parameter(name); argv[2] = NULL; ZDEBUG(("try_uncompress_with_tzx: spawning 64tzxtap %s", name)); exit_status = archdep_spawn("64tzxtap", argv, &tmp_name, NULL); lib_free(argv[0]); lib_free(argv[1]); if (exit_status == 0) { ZDEBUG(("try_uncompress_with_tzx: OK")); return tmp_name; } else { ZDEBUG(("try_uncompress_with_tzx: failed")); ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } }
int c128_snapshot_write(const char *name, int save_roms, int save_disks, int event_mode) { snapshot_t *s; s = snapshot_create(name, ((BYTE)(SNAP_MAJOR)), ((BYTE)(SNAP_MINOR)), SNAP_MACHINE_NAME); if (s == NULL) { return -1; } sound_snapshot_prepare(); if (maincpu_snapshot_write_module(s) < 0 || c128_snapshot_write_module(s, save_roms) < 0 || ciacore_snapshot_write_module(machine_context.cia1, s) < 0 || ciacore_snapshot_write_module(machine_context.cia2, s) < 0 || sid_snapshot_write_module(s) < 0 || drive_snapshot_write_module(s, save_disks, save_roms) < 0 || vicii_snapshot_write_module(s) < 0 || event_snapshot_write_module(s, event_mode) < 0 || tapeport_snapshot_write_module(s, save_disks) < 0 || keyboard_snapshot_write_module(s) < 0 || joyport_snapshot_write_module(s, JOYPORT_1) < 0 || joyport_snapshot_write_module(s, JOYPORT_2) < 0 || userport_snapshot_write_module(s) < 0) { snapshot_close(s); ioutil_remove(name); return -1; } snapshot_close(s); return 0; }
int scpu64_snapshot_write(const char *name, int save_roms, int save_disks, int event_mode) { snapshot_t *s; s = snapshot_create(name, ((BYTE)(SNAP_MAJOR)), ((BYTE)(SNAP_MINOR)), machine_get_name()); if (s == NULL) { return -1; } sound_snapshot_prepare(); /* Execute drive CPUs to get in sync with the main CPU. */ drivecpu_execute_all(maincpu_clk); if (maincpu_snapshot_write_module(s) < 0 || scpu64_snapshot_write_module(s, save_roms) < 0 || ciacore_snapshot_write_module(machine_context.cia1, s) < 0 || ciacore_snapshot_write_module(machine_context.cia2, s) < 0 || sid_snapshot_write_module(s) < 0 || drive_snapshot_write_module(s, save_disks, save_roms) < 0 || vicii_snapshot_write_module(s) < 0 || scpu64_glue_snapshot_write_module(s) < 0 || event_snapshot_write_module(s, event_mode) < 0 || keyboard_snapshot_write_module(s) || joystick_snapshot_write_module(s)) { snapshot_close(s); ioutil_remove(name); return -1; } snapshot_close(s); return 0; }
int cbm2_snapshot_write(const char *name, int save_roms, int save_disks, int event_mode) { snapshot_t *s; s = snapshot_create(name, SNAP_MAJOR, SNAP_MINOR, machine_get_name()); if (s == NULL) { return -1; } sound_snapshot_prepare(); if (maincpu_snapshot_write_module(s) < 0 || cbm2_snapshot_write_module(s, save_roms) < 0 || crtc_snapshot_write_module(s) < 0 || ciacore_snapshot_write_module(machine_context.cia1, s) < 0 || tpicore_snapshot_write_module(machine_context.tpi1, s) < 0 || tpicore_snapshot_write_module(machine_context.tpi2, s) < 0 || acia1_snapshot_write_module(s) < 0 || sid_snapshot_write_module(s) < 0 || drive_snapshot_write_module(s, save_disks, save_roms) < 0 || event_snapshot_write_module(s, event_mode) < 0 || tape_snapshot_write_module(s, save_disks) < 0 || keyboard_snapshot_write_module(s) || joystick_snapshot_write_module(s)) { snapshot_close(s); ioutil_remove(name); return -1; } snapshot_close(s); return 0; }
int vic20_snapshot_write(const char *name, int save_roms, int save_disks, int event_mode) { snapshot_t *s; int ieee488; s = snapshot_create(name, ((BYTE)(SNAP_MAJOR)), ((BYTE)(SNAP_MINOR)), machine_name); if (s == NULL) { return -1; } sound_snapshot_prepare(); /* FIXME: Missing sound. */ if (maincpu_snapshot_write_module(s) < 0 || vic20_snapshot_write_module(s, save_roms) < 0 || vic_snapshot_write_module(s) < 0 || viacore_snapshot_write_module(machine_context.via1, s) < 0 || viacore_snapshot_write_module(machine_context.via2, s) < 0 || drive_snapshot_write_module(s, save_disks, save_roms) < 0 || event_snapshot_write_module(s, event_mode) < 0 || tapeport_snapshot_write_module(s, save_disks) < 0 || keyboard_snapshot_write_module(s) < 0 || joyport_snapshot_write_module(s, JOYPORT_1) < 0 || userport_snapshot_write_module(s) < 0) { snapshot_close(s); ioutil_remove(name); return -1; } resources_get_int("IEEE488", &ieee488); if (ieee488) { if (viacore_snapshot_write_module(machine_context.ieeevia1, s) < 0 || viacore_snapshot_write_module(machine_context.ieeevia2, s) < 0) { snapshot_close(s); ioutil_remove(name); return 1; } } snapshot_close(s); return 0; }
static int fsdevice_flush_remove(char *arg) { int er; er = CBMDOS_IPE_OK; if (ioutil_remove(arg)) { er = CBMDOS_IPE_NOT_EMPTY; if (ioutil_errno(IOUTIL_ERRNO_EPERM)) { er = CBMDOS_IPE_PERMISSION; } } return er; }
/* Handle close of a (compressed file). `ptr' points to the zfile to close. */ static int handle_close(zfile_t *ptr) { ZDEBUG(("handle_close: closing `%s' (`%s'), write_mode = %d", ptr->tmp_name ? ptr->tmp_name : "(null)", ptr->orig_name, ptr->write_mode)); if (ptr->tmp_name) { /* Recompress into the original file. */ if (ptr->orig_name && ptr->write_mode && zfile_compress(ptr->tmp_name, ptr->orig_name, ptr->type)) { return -1; } /* Remove temporary file. */ if (ioutil_remove(ptr->tmp_name) < 0) { log_error(zlog, "Cannot unlink `%s': %s", ptr->tmp_name, strerror(errno)); } } handle_close_action(ptr); /* Remove item from list. */ if (ptr->prev != NULL) { ptr->prev->next = ptr->next; } else { zfile_list = ptr->next; } if (ptr->next != NULL) { ptr->next->prev = ptr->prev; } if (ptr->orig_name) { lib_free(ptr->orig_name); } if (ptr->tmp_name) { lib_free(ptr->tmp_name); } if (ptr->request_string) { lib_free(ptr->request_string); } lib_free(ptr); return 0; }
unsigned int rawfile_remove(const char *src_name, const char *path) { char *complete_src; int rc; if (path == NULL) complete_src = lib_stralloc(src_name); else complete_src = util_concat(path, FSDEV_DIR_SEP_STR, src_name, NULL); rc = ioutil_remove(complete_src); lib_free(complete_src); if (rc < 0) return FILEIO_FILE_NOT_FOUND; return FILEIO_FILE_SCRATCHED; }
int pet_snapshot_write(const char *name, int save_roms, int save_disks, int event_mode) { snapshot_t *s; int ef = 0; s = snapshot_create(name, SNAP_MAJOR, SNAP_MINOR, machine_name); if (s == NULL) { return -1; } sound_snapshot_prepare(); if (maincpu_snapshot_write_module(s) < 0 || cpu6809_snapshot_write_module(s) < 0 || pet_snapshot_write_module(s, save_roms) < 0 || crtc_snapshot_write_module(s) < 0 || pia1_snapshot_write_module(s) < 0 || pia2_snapshot_write_module(s) < 0 || petdww_snapshot_write_module(s) < 0 || viacore_snapshot_write_module(machine_context.via, s) < 0 || drive_snapshot_write_module(s, save_disks, save_roms) < 0 || event_snapshot_write_module(s, event_mode) < 0 || tapeport_snapshot_write_module(s, save_disks) < 0 || keyboard_snapshot_write_module(s) < 0 || userport_snapshot_write_module(s) < 0) { ef = -1; } if ((!ef) && petres.superpet) { ef = acia1_snapshot_write_module(s); } snapshot_close(s); if (ef) { ioutil_remove(name); } return ef; }
/* Handle close-action of a file. `ptr' points to the zfile to close. */ static int handle_close_action(zfile_t *ptr) { if (ptr == NULL || ptr->orig_name == NULL) return -1; switch(ptr->action) { case ZFILE_KEEP: break; case ZFILE_REQUEST: /* ui_zfile_close_request(ptr->orig_name, ptr->request_string); break; */ case ZFILE_DEL: if (ioutil_remove(ptr->orig_name) < 0) log_error(zlog, "Cannot unlink `%s': %s", ptr->orig_name, strerror(errno)); break; } return 0; }
int c64dtv_snapshot_write(const char *name, int save_roms, int save_disks, int event_mode) { snapshot_t *s; s = snapshot_create(name, ((BYTE)(SNAP_MAJOR)), ((BYTE)(SNAP_MINOR)), machine_name); if (s == NULL) { return -1; } sound_snapshot_prepare(); /* Execute drive CPUs to get in sync with the main CPU. */ drive_cpu_execute_all(maincpu_clk); if (maincpu_snapshot_write_module(s) < 0 || c64dtv_snapshot_write_module(s, save_roms) < 0 || c64dtvdma_snapshot_write_module(s) < 0 || c64dtvblitter_snapshot_write_module(s) < 0 || c64dtvmisc_snapshot_write_module(s) < 0 || ciacore_snapshot_write_module(machine_context.cia1, s) < 0 || ciacore_snapshot_write_module(machine_context.cia2, s) < 0 || sid_snapshot_write_module(s) < 0 || drive_snapshot_write_module(s, save_disks, save_roms) < 0 || vicii_snapshot_write_module(s) < 0 || event_snapshot_write_module(s, event_mode) < 0 || keyboard_snapshot_write_module(s) < 0 || joyport_snapshot_write_module(s, JOYPORT_1) < 0 || joyport_snapshot_write_module(s, JOYPORT_2) < 0 || userport_snapshot_write_module(s) < 0) { snapshot_close(s); ioutil_remove(name); return -1; } snapshot_close(s); return 0; }
/* If `name' has a bzip-like extension, try to uncompress it into a temporary file using bzip. If this succeeds, return the name of the temporary file; return NULL otherwise. */ static char *try_uncompress_with_bzip(const char *name) { char *tmp_name = NULL; size_t l = strlen(name); int exit_status; char *argv[4]; /* Check whether the name sounds like a bzipped file by checking the extension. MSDOS and UNIX variants of bzip v2 use the extension '.bz2'. bzip v1 is obsolete. */ if (l < 5 || strcasecmp(name + l - 4, ".bz2") != 0) { return NULL; } /* `exec*()' does not want these to be constant... */ argv[0] = lib_stralloc("bzip2"); argv[1] = lib_stralloc("-cd"); argv[2] = archdep_filename_parameter(name); argv[3] = NULL; ZDEBUG(("try_uncompress_with_bzip: spawning bzip -cd %s", name)); exit_status = archdep_spawn("bzip2", argv, &tmp_name, NULL); lib_free(argv[0]); lib_free(argv[1]); lib_free(argv[2]); if (exit_status == 0) { ZDEBUG(("try_uncompress_with_bzip: OK")); return tmp_name; } else { ZDEBUG(("try_uncompress_with_bzip: failed")); ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } }
/* Compress `src' into `dest' using algorithm `type'. */ static int zfile_compress(const char *src, const char *dest, enum compression_type type) { char *dest_backup_name; int retval; /* This shouldn't happen */ if (type == COMPR_ARCHIVE) { log_error(zlog, "compress: trying to compress archive-file."); return -1; } /* This shouldn't happen */ if (type == COMPR_ZIPCODE) { log_error(zlog, "compress: trying to compress zipcode-file."); return -1; } /* This shouldn't happen */ if (type == COMPR_LYNX) { log_error(zlog, "compress: trying to compress lynx-file."); return -1; } /* This shouldn't happen */ if (type == COMPR_TZX) { log_error(zlog, "compress: trying to compress tzx-file."); return -1; } /* Check whether `compression_type' is a known one. */ if (type != COMPR_GZIP && type != COMPR_BZIP) { log_error(zlog, "compress: unknown compression type"); return -1; } /* If we have no write permissions for `dest', give up. */ if (ioutil_access(dest, IOUTIL_ACCESS_W_OK) < 0) { ZDEBUG(("compress: no write permissions for `%s'", dest)); return -1; } if (ioutil_access(dest, IOUTIL_ACCESS_R_OK) < 0) { ZDEBUG(("compress: no read permissions for `%s'", dest)); dest_backup_name = NULL; } else { /* If `dest' exists, make a backup first. */ dest_backup_name = archdep_make_backup_filename(dest); if (dest_backup_name != NULL) { ZDEBUG(("compress: making backup %s... ", dest_backup_name)); } #ifdef WIN32 if (dest_backup_name != NULL) { ioutil_remove(dest_backup_name); } #endif if (dest_backup_name != NULL && ioutil_rename(dest, dest_backup_name) < 0) { ZDEBUG(("failed.")); log_error(zlog, "Could not make pre-compression backup."); return -1; } else { ZDEBUG(("OK.")); } } switch (type) { case COMPR_GZIP: retval = compress_with_gzip(src, dest); break; case COMPR_BZIP: retval = compress_with_bzip(src, dest); break; default: retval = -1; } if (retval == -1) { /* Compression failed: restore original file. */ #ifdef WIN32 if (dest_backup_name != NULL) { ioutil_remove(dest); } #endif if (dest_backup_name != NULL && ioutil_rename(dest_backup_name, dest) < 0) { log_error(zlog, "Could not restore backup file after failed compression."); } } else { /* Compression succeeded: remove backup file. */ if (dest_backup_name != NULL && ioutil_remove(dest_backup_name) < 0) { log_error(zlog, "Warning: could not remove backup file."); /* Do not return an error anyway (no data is lost). */ } } if (dest_backup_name) { lib_free(dest_backup_name); } return retval; }
/* If `name' has a gzip-like extension, try to uncompress it into a temporary file using gzip or zlib if available. If this succeeds, return the name of the temporary file; return NULL otherwise. */ static char *try_uncompress_with_gzip(const char *name) { #ifdef HAVE_ZLIB FILE *fddest; gzFile fdsrc; char *tmp_name = NULL; int len; if (!archdep_file_is_gzip(name)) { return NULL; } fddest = archdep_mkstemp_fd(&tmp_name, MODE_WRITE); if (fddest == NULL) { return NULL; } fdsrc = gzopen(name, MODE_READ); if (fdsrc == NULL) { fclose(fddest); ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } do { char buf[256]; len = gzread(fdsrc, (void *)buf, 256); if (len > 0) { if (fwrite((void *)buf, 1, (size_t)len, fddest) < len) { gzclose(fdsrc); fclose(fddest); ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } } } while (len > 0); gzclose(fdsrc); fclose(fddest); return tmp_name; #else char *tmp_name = NULL; int exit_status; char *argv[4]; if (!archdep_file_is_gzip(name)) { return NULL; } /* `exec*()' does not want these to be constant... */ argv[0] = lib_stralloc("gzip"); argv[1] = lib_stralloc("-cd"); argv[2] = archdep_filename_parameter(name); argv[3] = NULL; ZDEBUG(("try_uncompress_with_gzip: spawning gzip -cd %s", name)); exit_status = archdep_spawn("gzip", argv, &tmp_name, NULL); lib_free(argv[0]); lib_free(argv[1]); lib_free(argv[2]); if (exit_status == 0) { ZDEBUG(("try_uncompress_with_gzip: OK")); return tmp_name; } else { ZDEBUG(("try_uncompress_with_gzip: failed")); ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } #endif }
/* If `name' has a correct extension, try to list its contents and search for the first file with a proper extension; if found, extract it. If this succeeds, return the name of the temporary file; if the archive file is valid but `write_mode' is non-zero, return a zero-length string; in all the other cases, return NULL. */ static char *try_uncompress_archive(const char *name, int write_mode, const char *program, const char *listopts, const char *extractopts, const char *extension, const char *search) { char *tmp_name = NULL; size_t l = strlen(name), len, nameoffset; int found = 0; int exit_status; char *argv[8]; FILE *fd; char tmp[1024]; /* Do we have correct extension? */ len = strlen(extension); if (l <= len || strcasecmp(name + l - len, extension) != 0) { return NULL; } /* First run listing and search for first recognizeable extension. */ argv[0] = lib_stralloc(program); argv[1] = lib_stralloc(listopts); argv[2] = archdep_filename_parameter(name); argv[3] = NULL; ZDEBUG(("try_uncompress_archive: spawning `%s %s %s'", program, listopts, name)); exit_status = archdep_spawn(program, argv, &tmp_name, NULL); lib_free(argv[0]); lib_free(argv[1]); lib_free(argv[2]); /* No luck? */ if (exit_status != 0) { ZDEBUG(("try_uncompress_archive: `%s %s' failed.", program, listopts)); ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } ZDEBUG(("try_uncompress_archive: `%s %s' successful.", program, listopts)); fd = fopen(tmp_name, MODE_READ); if (!fd) { ZDEBUG(("try_uncompress_archive: cannot read `%s %s' output.", program, tmp_name)); ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } ZDEBUG(("try_uncompress_archive: searching for the first valid file.")); /* Search for `search' first (if any) to see the offset where filename begins, then search for first recognizeable file. */ nameoffset = search ? -1 : 0; len = search ? strlen(search) : 0; while (!feof(fd) && !found) { if (fgets(tmp, 1024, fd) == NULL) { break; } l = strlen(tmp); while (l > 0) { tmp[--l] = 0; if (((nameoffset < 0) || (nameoffset > 1024)) && l >= len && !strcasecmp(tmp + l - len, search) != 0) { nameoffset = l - 4; } if (nameoffset >= 0 && nameoffset <= 1024 && is_valid_extension(tmp, l, nameoffset)) { ZDEBUG(("try_uncompress_archive: found `%s'.", tmp + nameoffset)); found = 1; break; } } } fclose(fd); ioutil_remove(tmp_name); if (!found) { ZDEBUG(("try_uncompress_archive: no valid file found.")); lib_free(tmp_name); return NULL; } /* This would be a valid ZIP file, but we cannot handle ZIP files in write mode. Return a null temporary file name to report this. */ if (write_mode) { ZDEBUG(("try_uncompress_archive: cannot open file in write mode.")); lib_free(tmp_name); return ""; } /* And then file inside zip. If we have a zipcode extract all of them to the same file. */ argv[0] = lib_stralloc(program); argv[1] = lib_stralloc(extractopts); argv[2] = archdep_filename_parameter(name); if (is_zipcode_name(tmp + nameoffset)) { argv[3] = lib_stralloc(tmp + nameoffset); argv[4] = lib_stralloc(tmp + nameoffset); argv[5] = lib_stralloc(tmp + nameoffset); argv[6] = lib_stralloc(tmp + nameoffset); argv[7] = NULL; argv[3][0] = '1'; argv[4][0] = '2'; argv[5][0] = '3'; argv[6][0] = '4'; } else { argv[3] = archdep_quote_parameter(tmp + nameoffset); argv[4] = NULL; } ZDEBUG(("try_uncompress_archive: spawning `%s %s %s %s'.", program, extractopts, name, tmp + nameoffset)); exit_status = archdep_spawn(program, argv, &tmp_name, NULL); lib_free(argv[0]); lib_free(argv[1]); lib_free(argv[2]); lib_free(argv[3]); if (is_zipcode_name(tmp + nameoffset)) { lib_free(argv[4]); lib_free(argv[5]); lib_free(argv[6]); } if (exit_status != 0) { ZDEBUG(("try_uncompress_archive: `%s %s' failed.", program, extractopts)); ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } ZDEBUG(("try_uncompress_archive: `%s %s' successful.", program, tmp_name)); return tmp_name; }
/* If this file looks like a zipcode, try to extract is using c1541. We have to figure this out by reading the contents of the file */ static char *try_uncompress_zipcode(const char *name, int write_mode) { char *tmp_name = NULL; int i, count, sector, sectors = 0; FILE *fd; char tmp[256]; char *argv[5]; int exit_status; /* The 2nd char has to be '!'? */ util_fname_split(name, NULL, &tmp_name); if (tmp_name == NULL) { return NULL; } if (strlen(tmp_name) < 3 || tmp_name[1] != '!') { lib_free(tmp_name); return NULL; } lib_free(tmp_name); /* Can we read this file? */ fd = fopen(name, MODE_READ); if (fd == NULL) { return NULL; } /* Read first track to see if this is zipcode. */ fseek(fd, 4, SEEK_SET); for (count = 1; count < 21; count++) { i = zipcode_read_sector(fd, 1, §or, tmp); if (i || sector < 0 || sector > 20 || (sectors & (1 << sector))) { fclose(fd); return NULL; } sectors |= 1 << sector; } fclose(fd); /* it is a zipcode. We cannot support write_mode */ if (write_mode) { return ""; } /* format image first */ tmp_name = archdep_tmpnam(); /* ok, now extract the zipcode */ argv[0] = lib_stralloc(C1541_NAME); argv[1] = lib_stralloc("-zcreate"); argv[2] = lib_stralloc(tmp_name); argv[3] = archdep_filename_parameter(name); argv[4] = NULL; exit_status = archdep_spawn(C1541_NAME, argv, NULL, NULL); lib_free(argv[0]); lib_free(argv[1]); lib_free(argv[2]); lib_free(argv[3]); if (exit_status) { ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } /* everything ok */ return tmp_name; }
/* If the file looks like a lynx image, try to extract it using c1541. We have to figure this out by reading the contsnts of the file */ static char *try_uncompress_lynx(const char *name, int write_mode) { char *tmp_name; size_t i; int count; FILE *fd; char tmp[256]; char *argv[20]; int exit_status; /* can we read this file? */ fd = fopen(name, MODE_READ); if (fd == NULL) { return NULL; } /* is this lynx -image? */ i = fread(tmp, 1, 2, fd); if (i != 2 || tmp[0] != 1 || tmp[1] != 8) { fclose(fd); return NULL; } count = 0; while (1) { i = fread(tmp, 1, 1, fd); if (i != 1) { fclose(fd); return NULL; } if (tmp[0]) { count = 0; } else { count++; } if (count == 3) { break; } } i = fread(tmp, 1, 1, fd); if (i != 1 || tmp[0] != 13) { fclose(fd); return NULL; } count = 0; while (1) { i = fread(&tmp[count], 1, 1, fd); if (i != 1 || count == 254) { fclose(fd); return NULL; } if (tmp[count++] == 13) { break; } } tmp[count] = 0; if (!atoi(tmp)) { fclose(fd); return NULL; } /* XXX: this is not a full check, but perhaps enough? */ fclose(fd); /* it is a lynx image. We cannot support write_mode */ if (write_mode) { return ""; } tmp_name = archdep_tmpnam(); /* now create the image */ argv[0] = lib_stralloc("c1541"); argv[1] = lib_stralloc("-format"); argv[2] = lib_stralloc("lynximage,00"); argv[3] = lib_stralloc("x64"); argv[4] = lib_stralloc(tmp_name); argv[5] = lib_stralloc("-unlynx"); argv[6] = archdep_filename_parameter(name); argv[7] = NULL; exit_status = archdep_spawn("c1541", argv, NULL, NULL); lib_free(argv[0]); lib_free(argv[1]); lib_free(argv[2]); lib_free(argv[3]); lib_free(argv[4]); lib_free(argv[5]); lib_free(argv[6]); if (exit_status) { ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } /* everything ok */ return tmp_name; }