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()
29 void NativeFileStream::open(
const string &path, ios_base::openmode flags)
32 int requiredSize = MultiByteToWideChar(CP_UTF8, 0, path.data(), -1,
nullptr, 0);
33 if(requiredSize <= 0) {
36 auto widePath = make_unique<wchar_t[]>(
static_cast<size_t>(requiredSize));
37 requiredSize = MultiByteToWideChar(CP_UTF8, 0, path.data(), -1, widePath.get(), requiredSize);
38 if(requiredSize <= 0) {
42 int nativeFlags = (flags & ios_base::binary ? _O_BINARY : 0);
44 if((flags & ios_base::out) && (flags & ios_base::in)) {
45 nativeFlags |= _O_RDWR;
46 }
else if(flags & ios_base::out) {
47 nativeFlags |= _O_WRONLY | _O_CREAT;
48 permissions = _S_IREAD | _S_IWRITE;
49 }
else if(flags & ios_base::in) {
50 nativeFlags |= _O_RDONLY;
52 if(flags & ios_base::trunc) {
53 nativeFlags |= _O_TRUNC;
56 int fd = _wopen(widePath.get(), nativeFlags, permissions);
60 m_filebuf = make_unique<__gnu_cxx::stdio_filebuf<char> >(fd, flags);
61 rdbuf(m_filebuf.get());
64 void NativeFileStream::close()
CPP_UTILITIES_EXPORT void throwIoFailure(const char *what)
Throws a std::ios_base::failure with the specified message.
Contains utility classes helping to read and write streams.
std::fstream NativeFileStream