diff options
| author | 2021-09-10 09:39:10 -0700 | |
|---|---|---|
| committer | 2021-09-10 09:39:10 -0700 | |
| commit | fedb40f712d34bb2b6904487ce88dd124e26c7f5 (patch) | |
| tree | 3a539aa7f386b3c11ec76bdb266ca03a08039cfe /src/tools/castool.cpp | |
| parent | e505ac97bd2de9100d02d37fc0270504bf60b531 (diff) | |
| parent | a99d2f3295c21e6ae97cbffce8cf025860bfa4d6 (diff) | |
Merge branch 'master' into time-experiments2
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; } } |
