72 lines
1.9 KiB
C++
72 lines
1.9 KiB
C++
#pragma once
|
|
#include <cstdio>
|
|
|
|
#include <switch.h>
|
|
|
|
namespace nxst {
|
|
|
|
// RAII wrapper for FsFileSystem — auto-closes on destruction.
|
|
struct FsFileSystemHandle {
|
|
FsFileSystem fs{};
|
|
bool valid{false};
|
|
|
|
FsFileSystemHandle() = default;
|
|
~FsFileSystemHandle() {
|
|
if (valid)
|
|
fsFsClose(&fs);
|
|
} // NOLINT(modernize-use-equals-default)
|
|
|
|
FsFileSystemHandle(const FsFileSystemHandle&) = delete;
|
|
FsFileSystemHandle& operator=(const FsFileSystemHandle&) = delete;
|
|
|
|
FsFileSystem* get() {
|
|
return &fs;
|
|
}
|
|
|
|
void release() {
|
|
valid = false;
|
|
} // transfer ownership to devfs
|
|
};
|
|
|
|
// RAII wrapper for FILE* — auto-fclose on destruction.
|
|
struct FileHandle {
|
|
FILE* ptr{nullptr};
|
|
|
|
explicit FileHandle(FILE* file) : ptr(file) {}
|
|
~FileHandle() {
|
|
if (ptr != nullptr)
|
|
fclose(ptr);
|
|
} // NOLINT(modernize-use-equals-default)
|
|
|
|
FileHandle(const FileHandle&) = delete;
|
|
FileHandle& operator=(const FileHandle&) = delete;
|
|
|
|
explicit operator bool() const {
|
|
return ptr != nullptr;
|
|
}
|
|
FILE* get() const {
|
|
return ptr;
|
|
}
|
|
};
|
|
|
|
// RAII wrapper for AccountProfile — auto-closes on destruction.
|
|
struct AccountProfileHandle {
|
|
AccountProfile profile{};
|
|
bool valid{false};
|
|
|
|
AccountProfileHandle() = default;
|
|
~AccountProfileHandle() {
|
|
if (valid)
|
|
accountProfileClose(&profile);
|
|
} // NOLINT(modernize-use-equals-default)
|
|
|
|
AccountProfileHandle(const AccountProfileHandle&) = delete;
|
|
AccountProfileHandle& operator=(const AccountProfileHandle&) = delete;
|
|
|
|
AccountProfile* get() {
|
|
return &profile;
|
|
}
|
|
};
|
|
|
|
} // namespace nxst
|