diff options
author | 2021-10-05 03:34:45 +1100 | |
---|---|---|
committer | 2021-10-05 03:34:45 +1100 | |
commit | aeb9eae87469e67bc6a91caf3840c34c11d959fc (patch) | |
tree | 45bffedf374dbce47caca633ad7bda547592e6c9 /src/lib/util/chd.cpp | |
parent | 33723892a3f06e678d817b36aef84364c32848ec (diff) |
util: Further API cleanups: (#8661)
* Turned `core_file` into an implementation of `random_read_write`.
* Turned PNG errors into a standard error category.
* Added a helper for generating what look like derived classes on-the-fly.
Diffstat (limited to 'src/lib/util/chd.cpp')
-rw-r--r-- | src/lib/util/chd.cpp | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/lib/util/chd.cpp b/src/lib/util/chd.cpp index 29792fc36df..1b4800c74f1 100644 --- a/src/lib/util/chd.cpp +++ b/src/lib/util/chd.cpp @@ -702,17 +702,14 @@ std::error_condition chd_file::create(std::string_view filename, uint64_t logica std::error_condition filerr = util::core_file::open(filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file); if (filerr) return filerr; - util::random_read_write::ptr io = util::core_file_read_write(std::move(file)); - if (!io) - return std::errc::not_enough_memory; // create the file normally, then claim the file - std::error_condition chderr = create(std::move(io), logicalbytes, hunkbytes, unitbytes, compression); + std::error_condition chderr = create(std::move(file), logicalbytes, hunkbytes, unitbytes, compression); // if an error happened, close and delete the file if (chderr) { - io.reset(); + file.reset(); osd_file::remove(std::string(filename)); // FIXME: allow osd_file to use std::string_view } return chderr; @@ -745,17 +742,14 @@ std::error_condition chd_file::create(std::string_view filename, uint64_t logica std::error_condition filerr = util::core_file::open(filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file); if (filerr) return filerr; - util::random_read_write::ptr io = util::core_file_read_write(std::move(file)); - if (!io) - return std::errc::not_enough_memory; // create the file normally, then claim the file - std::error_condition chderr = create(std::move(io), logicalbytes, hunkbytes, compression, parent); + std::error_condition chderr = create(std::move(file), logicalbytes, hunkbytes, compression, parent); // if an error happened, close and delete the file if (chderr) { - io.reset(); + file.reset(); osd_file::remove(std::string(filename)); // FIXME: allow osd_file to use std::string_view } return chderr; @@ -787,12 +781,9 @@ std::error_condition chd_file::open(std::string_view filename, bool writeable, c std::error_condition filerr = util::core_file::open(filename, openflags, file); if (filerr) return filerr; - util::random_read_write::ptr io = util::core_file_read_write(std::move(file)); - if (!io) - return std::errc::not_enough_memory; // now open the CHD - std::error_condition err = open(std::move(io), writeable, parent); + std::error_condition err = open(std::move(file), writeable, parent); if (err) return err; |