mirror of https://github.com/AxioDL/metaforce.git
hecl/hecl: Add smart pointer variant of Fopen
Provides a wrapper API over Fopen in order to prevent resource leaks.
This commit is contained in:
parent
bcfea9a09a
commit
9dcf7e7f08
|
@ -275,6 +275,16 @@ inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLockType
|
|||
return fp;
|
||||
}
|
||||
|
||||
struct UniqueFileDeleter {
|
||||
void operator()(FILE* file) const noexcept { std::fclose(file); }
|
||||
};
|
||||
using UniqueFilePtr = std::unique_ptr<FILE, UniqueFileDeleter>;
|
||||
|
||||
inline UniqueFilePtr FopenUnique(const SystemChar* path, const SystemChar* mode,
|
||||
FileLockType lock = FileLockType::None) {
|
||||
return UniqueFilePtr{Fopen(path, mode, lock)};
|
||||
}
|
||||
|
||||
inline int FSeek(FILE* fp, int64_t offset, int whence) {
|
||||
#if _WIN32
|
||||
return _fseeki64(fp, offset, whence);
|
||||
|
|
Loading…
Reference in New Issue