mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-28 17:43:36 +00:00
nuke non-portable Windows file operations
This commit is contained in:
parent
05adecade7
commit
ff7baaac3b
|
|
@ -49,13 +49,9 @@ bool FileSeek(std::FILE* file, int64_t offset, int origin) {
|
|||
// SecurityException - if a security manager exists and its checkRead method
|
||||
// denies read access to the file.
|
||||
FileInputStream::FileInputStream(const File& file) : m_fileHandle(nullptr) {
|
||||
#if defined(_WIN32)
|
||||
m_fileHandle = _wfopen(file.getPath().c_str(), "rb");
|
||||
#else
|
||||
const std::string nativePath =
|
||||
std::filesystem::path(file.getPath()).string();
|
||||
m_fileHandle = std::fopen(nativePath.c_str(), "rb");
|
||||
#endif
|
||||
|
||||
if (m_fileHandle == nullptr) {
|
||||
assert(0);
|
||||
|
|
|
|||
|
|
@ -26,13 +26,9 @@ FileOutputStream::FileOutputStream(const File& file) : m_fileHandle(nullptr) {
|
|||
return;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
m_fileHandle = _wfopen(file.getPath().c_str(), "wb");
|
||||
#else
|
||||
const std::string nativePath =
|
||||
std::filesystem::path(file.getPath()).string();
|
||||
m_fileHandle = std::fopen(nativePath.c_str(), "wb");
|
||||
#endif
|
||||
|
||||
if (m_fileHandle == nullptr) {
|
||||
// TODO 4J Stu - Any form of error/exception handling
|
||||
|
|
|
|||
|
|
@ -6,19 +6,12 @@
|
|||
|
||||
namespace {
|
||||
std::FILE* OpenBinaryFileForReadWrite(const File& file) {
|
||||
#if defined(_WIN32)
|
||||
std::FILE* stream = _wfopen(file.getPath().c_str(), "r+b");
|
||||
if (stream == nullptr) {
|
||||
stream = _wfopen(file.getPath().c_str(), "w+b");
|
||||
}
|
||||
#else
|
||||
const std::string nativePath =
|
||||
std::filesystem::path(file.getPath()).string();
|
||||
std::FILE* stream = std::fopen(nativePath.c_str(), "r+b");
|
||||
if (stream == nullptr) {
|
||||
stream = std::fopen(nativePath.c_str(), "w+b");
|
||||
}
|
||||
#endif
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,19 +7,12 @@
|
|||
|
||||
namespace {
|
||||
std::FILE* OpenBinaryFileForReadWrite(const File& file) {
|
||||
#if defined(_WIN32)
|
||||
std::FILE* stream = _wfopen(file.getPath().c_str(), "r+b");
|
||||
if (stream == nullptr) {
|
||||
stream = _wfopen(file.getPath().c_str(), "w+b");
|
||||
}
|
||||
#else
|
||||
const std::string nativePath =
|
||||
std::filesystem::path(file.getPath()).string();
|
||||
std::FILE* stream = std::fopen(nativePath.c_str(), "r+b");
|
||||
if (stream == nullptr) {
|
||||
stream = std::fopen(nativePath.c_str(), "w+b");
|
||||
}
|
||||
#endif
|
||||
return stream;
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
|||
Loading…
Reference in a new issue