14 #if !defined(PLATFORM_MINGW) || !defined(CPP_UTILITIES_USE_NATIVE_FILE_BUFFER) 21 : m_filebuf(new __gnu_cxx::stdio_filebuf<char>)
23 rdbuf(m_filebuf.get());
26 NativeFileStream::~NativeFileStream()
30 void NativeFileStream::open(
const string &path, ios_base::openmode flags)
33 int requiredSize = MultiByteToWideChar(CP_UTF8, 0, path.data(), -1,
nullptr, 0);
34 if (requiredSize <= 0) {
37 auto widePath = make_unique<wchar_t[]>(
static_cast<size_t>(requiredSize));
38 requiredSize = MultiByteToWideChar(CP_UTF8, 0, path.data(), -1, widePath.get(), requiredSize);
39 if (requiredSize <= 0) {
43 int nativeFlags = (flags & ios_base::binary ? _O_BINARY : 0);
45 if ((flags & ios_base::out) && (flags & ios_base::in)) {
46 nativeFlags |= _O_RDWR;
47 }
else if (flags & ios_base::out) {
48 nativeFlags |= _O_WRONLY | _O_CREAT;
49 permissions = _S_IREAD | _S_IWRITE;
50 }
else if (flags & ios_base::in) {
51 nativeFlags |= _O_RDONLY;
53 if (flags & ios_base::trunc) {
54 nativeFlags |= _O_TRUNC;
57 int fd = _wopen(widePath.get(), nativeFlags, permissions);
61 m_filebuf = make_unique<__gnu_cxx::stdio_filebuf<char>>(fd, flags);
62 rdbuf(m_filebuf.get());
65 void NativeFileStream::close()
CPP_UTILITIES_EXPORT void throwIoFailure(const char *what)
Throws an std::ios_base::failure with the specified message.
Contains utility classes helping to read and write streams.
std::fstream NativeFileStream