comparison blastem.c @ 2211:5e6e589efbad

Strip off .gz extension for gzipped ROMs in load_media so system detection based on filename works with such files
author Michael Pavone <pavone@retrodev.com>
date Sun, 28 Aug 2022 22:42:36 -0700
parents 9826d50061a0
children 1e626d0ecf9c
comparison
equal deleted inserted replaced
2210:3e591869d135 2211:5e6e589efbad
192 if (stype) { 192 if (stype) {
193 *stype = SYSTEM_SEGACD; 193 *stype = SYSTEM_SEGACD;
194 } 194 }
195 return make_iso_media(dst, filename); 195 return make_iso_media(dst, filename);
196 } 196 }
197 free(ext); 197
198 ROMFILE f = romopen(filename, "rb"); 198 ROMFILE f = romopen(filename, "rb");
199 if (!f) { 199 if (!f) {
200 free(ext);
200 return 0; 201 return 0;
201 } 202 }
203 #ifndef DISABLE_ZLIB
204 char *to_free = NULL;
205 if (!gzdirect(f) && ext && !strcasecmp(ext, "gz")) {
206 size_t without_gz = strlen(filename) - 2;
207 to_free = calloc(1, without_gz);
208 memcpy(to_free, filename, without_gz - 1);
209 to_free[without_gz - 1] = 0;
210 free(ext);
211 filename = to_free;
212 ext = path_extension(filename);
213 }
214 #endif //DISABLE_ZLIB
202 215
203 if (sizeof(header) != romread(header, 1, sizeof(header), f)) { 216 if (sizeof(header) != romread(header, 1, sizeof(header), f)) {
204 fatal_error("Error reading from %s\n", filename); 217 fatal_error("Error reading from %s\n", filename);
205 } 218 }
206 219
239 dst->buffer = buf; 252 dst->buffer = buf;
240 ret = (uint32_t)readsize; 253 ret = (uint32_t)readsize;
241 } 254 }
242 dst->dir = path_dirname(filename); 255 dst->dir = path_dirname(filename);
243 dst->name = basename_no_extension(filename); 256 dst->name = basename_no_extension(filename);
244 dst->extension = path_extension(filename); 257 dst->extension = ext;
245 dst->size = ret; 258 dst->size = ret;
246 romclose(f); 259 romclose(f);
247 if (!strcasecmp(dst->extension, "cue")) { 260 if (!strcasecmp(dst->extension, "cue")) {
248 if (parse_cue(dst)) { 261 if (parse_cue(dst)) {
249 if (stype) { 262 if (stype) {
255 if (stype) { 268 if (stype) {
256 *stype = SYSTEM_SEGACD; 269 *stype = SYSTEM_SEGACD;
257 } 270 }
258 } 271 }
259 } 272 }
273 #ifndef DISABLE_ZLIB
274 if (to_free) {
275 free(to_free);
276 }
277 #endif
260 278
261 return ret; 279 return ret;
262 } 280 }
263 281
264 int break_on_sync = 0; 282 int break_on_sync = 0;