diff options
| author | LillyJadeKatrin <lilly.kitty.1988@gmail.com> | 2023-07-07 08:31:26 -0400 |
|---|---|---|
| committer | LillyJadeKatrin <lilly.kitty.1988@gmail.com> | 2023-10-01 09:04:06 -0400 |
| commit | 335cf4f2db4160ebbf387aeb19dc637182c91c5a (patch) | |
| tree | 5e0c604dad0d5591a7343da34be1aa328b6fae01 /Source/Core/Common | |
| parent | f8445782bff425dd95a8c7ccba06769d9fb0adf0 (diff) | |
Added CopyReader to BlobReader and all subclasses
A deep-copy method CopyReader has been added to BlobReader (virtual) and all of its subclasses (override). This should create a second BlobReader to open the same set of data but with an independent read pointer so that it doesn't interfere with any reads done on the original Reader.
As part of this, IOFile has added code to create a deep copy IOFile pointer onto the same file, with code based on the platform in question to find the file ID from the file pointer and open a new one. There has also been a small piece added to FileInfo to enable a deep copy, but its only subclass at this time already had a copy constructor so this was relatively minor.
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/IOFile.cpp | 9 | ||||
| -rw-r--r-- | Source/Core/Common/IOFile.h | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/Source/Core/Common/IOFile.cpp b/Source/Core/Common/IOFile.cpp index cf7762ea68..cc22979bbe 100644 --- a/Source/Core/Common/IOFile.cpp +++ b/Source/Core/Common/IOFile.cpp @@ -101,6 +101,15 @@ bool IOFile::Close() return m_good; } +IOFile IOFile::Duplicate(const char openmode[]) const +{ +#ifdef _WIN32 + return IOFile(_fdopen(_dup(_fileno(m_file)), openmode)); +#else // _WIN32 + return IOFile(fdopen(dup(fileno(m_file)), openmode)); +#endif // _WIN32 +} + void IOFile::SetHandle(std::FILE* file) { Close(); diff --git a/Source/Core/Common/IOFile.h b/Source/Core/Common/IOFile.h index 62fdd7186e..4b12c31888 100644 --- a/Source/Core/Common/IOFile.h +++ b/Source/Core/Common/IOFile.h @@ -51,6 +51,8 @@ public: SharedAccess sh = SharedAccess::Default); bool Close(); + IOFile Duplicate(const char openmode[]) const; + template <typename T> bool ReadArray(T* elements, size_t count, size_t* num_read = nullptr) { |
