diff options
author | 2021-08-22 09:06:15 +1000 | |
---|---|---|
committer | 2021-08-22 09:06:15 +1000 | |
commit | e8bbea1fc6e94e14768509d322f6c624403ffb36 (patch) | |
tree | 74dd1606a900d83de8aecff17a6737af4113308d /src/tools/castool.cpp | |
parent | e319bde5fc3696d7f48f62b15b6366c4377fe5d1 (diff) |
formats, osd, util: Started refactoring file I/O stuff. (#8456)
Added more modern generic I/O interfaces with implementation backed by stdio, osd_file and core_file, replacing io_generic. Also replaced core_file's build-in zlib compression with a filter.
unzip.cpp, un7z.cpp: Added option to supply abstract I/O interface rather than filename.
Converted osd_file, core_file, archive_file, chd_file and device_image_interface to use std::error_condition rather than their own error enums.
Allow mounting TI-99 RPK from inside archives.
Diffstat (limited to 'src/tools/castool.cpp')
-rw-r--r-- | src/tools/castool.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/tools/castool.cpp b/src/tools/castool.cpp index e03a15203d5..896c0bde5c2 100644 --- a/src/tools/castool.cpp +++ b/src/tools/castool.cpp @@ -53,6 +53,7 @@ #include "formats/zx81_p.h" #include "corestr.h" +#include "ioprocs.h" #include <cassert> #include <cctype> @@ -162,7 +163,6 @@ int CLIB_DECL main(int argc, char *argv[]) int found =0; const cassette_image::Format * const *selected_formats = nullptr; cassette_image::ptr cassette; - FILE *f; if (argc > 1) { @@ -188,21 +188,26 @@ int CLIB_DECL main(int argc, char *argv[]) return -1; } - f = fopen(argv[3], "rb"); + FILE *f = fopen(argv[3], "rb"); if (!f) { fprintf(stderr, "File %s not found.\n",argv[3]); return -1; } - if (cassette_image::open_choices(f, &stdio_ioprocs, get_extension(argv[3]), selected_formats, cassette_image::FLAG_READONLY, cassette) != cassette_image::error::SUCCESS) { + auto io = util::stdio_read_write(f, 0x00); + f = nullptr; + if (!io) { + fprintf(stderr, "Out of memory.\n"); + return -1; + } + + if (cassette_image::open_choices(std::move(io), get_extension(argv[3]), selected_formats, cassette_image::FLAG_READONLY, cassette) != cassette_image::error::SUCCESS) { fprintf(stderr, "Invalid format of input file.\n"); - fclose(f); return -1; } cassette->dump(argv[4]); cassette.reset(); - fclose(f); goto theend; } } |