--- uae/src/zfile.c 2018/04/24 16:40:07 1.1.1.3 +++ uae/src/zfile.c 2018/04/24 16:48:49 1.1.1.6 @@ -21,50 +21,54 @@ extern char *ixemul_dev_path; /* /dev/ extern int readdevice (const char *, char *); #endif -static struct zfile +struct zfile { struct zfile *next; FILE *f; char name[L_tmpnam]; -} *zlist; +}; + +static struct zfile *zlist = 0; /* * called on exit() */ -void zfile_exit(void) +void zfile_exit (void) { struct zfile *l; while ((l = zlist)) { zlist = l->next; - fclose(l->f); - unlink(l->name); /* sam: in case unlink() after fopen() fails */ - free(l); + fclose (l->f); + unlink (l->name); /* sam: in case unlink() after fopen() fails */ + free (l); } } /* * fclose() but for a compressed file */ -int zfile_close(FILE *f) +int zfile_close (FILE *f) { struct zfile *pl = NULL; struct zfile *l = zlist; int ret; - while(l && l->f!=f) { + while (l && l->f!=f) { pl = l; l = l->next; } - if (!l) - return fclose(f); - ret = fclose(l->f); - + if (l == 0) + return fclose (f); + ret = fclose (l->f); + printf ("unlink: `%s'\n", l->name); + unlink (l->name); + if(!pl) zlist = l->next; else pl->next = l->next; - free(l); + free (l); return ret; } @@ -77,7 +81,7 @@ static int gunzip (const char *decompres char cmd[1024]; if (!dst) return 1; - sprintf (cmd, "%s -c -d %s >%s", decompress, src, dst); + sprintf (cmd, "%s -c -d \"%s\" > \"%s\"", decompress, src, dst); return !system (cmd); } @@ -100,7 +104,7 @@ static int lha (const char *src, const c /* * (pk)unzip decompression */ -static int unzip(const char *src, const char *dst) +static int unzip (const char *src, const char *dst) { char cmd[1024]; if (!dst) @@ -114,7 +118,7 @@ static int unzip(const char *src, const /* * decompresses the file (or check if dest is null) */ -static int uncompress(const char *name, char *dest) +static int uncompress (const char *name, char *dest) { char *ext = strrchr (name, '.'); char nam[1024]; @@ -182,44 +186,45 @@ static int uncompress(const char *name, /* * fopen() for a compressed file */ -FILE *zfile_open(const char *name, const char *mode) +FILE *zfile_open (const char *name, const char *mode) { struct zfile *l; int fd = 0; - if(! uncompress (name, NULL)) + if (! uncompress (name, NULL)) return fopen (name, mode); l = malloc (sizeof *l); - if (!l) + if (! l) return NULL; - tmpnam(l->name); + tmpnam (l->name); - /* On the amiga this would make ixemul loose the break handler */ - /* ==> fixed in exmul v4.6 */ - fd = creat(l->name, 0666); + fd = creat (l->name, S_IRUSR | S_IWUSR); if (fd < 0) return NULL; - if (!uncompress (name, l->name)) { - free(l); + if (! uncompress (name, l->name)) { close (fd); - unlink(l->name); + printf ("unlink: `%s'\n", l->name); + unlink (l->name); + free (l); return NULL; } - l->f = uae_fopen_del (l->name, mode); + l->f = fopen (l->name, mode); close (fd); if (l->f == NULL) { - free(l); + printf ("unlink: `%s'\n", l->name); + unlink (l->name); + free (l); return NULL; } l->next = zlist; - zlist = l; + zlist = l; return l->f; } @@ -230,18 +235,18 @@ FILE *zfile_open(const char *name, const * Stubs for machines that this doesn't work on. */ -void zfile_exit(void) +void zfile_exit (void) { } -int zfile_close(FILE *f) +int zfile_close (FILE *f) { return fclose(f); } -FILE *zfile_open(const char *name, const char *mode) +FILE *zfile_open (const char *name, const char *mode) { - return fopen(name, mode); + return fopen (name, mode); } #endif