From 8a69c77d7f714fffbaf5a2568263b87f60bcf8db Mon Sep 17 00:00:00 2001 From: Oz Date: Wed, 17 Jan 2024 21:01:11 +0100 Subject: [PATCH] Fix error messages when opening file streams on MinGW --- src/internal/cfileinstream.cpp | 5 +++++ src/internal/cfileoutstream.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/internal/cfileinstream.cpp b/src/internal/cfileinstream.cpp index 3de730ff..7d39d0ca 100644 --- a/src/internal/cfileinstream.cpp +++ b/src/internal/cfileinstream.cpp @@ -34,7 +34,12 @@ CFileInStream::CFileInStream( const fs::path& filePath ) : CStdInStream( mFileSt void CFileInStream::openFile( const fs::path& filePath ) { mFileStream.open( filePath, std::ios::in | std::ios::binary ); // flawfinder: ignore if ( mFileStream.fail() ) { +#if defined( __MINGW32__ ) || defined( __MINGW64__ ) + std::error_code error{ errno, std::generic_category() }; + throw BitException( "Failed to open the archive file", error, path_to_tstring( filePath ) ); +#else throw BitException( "Failed to open the archive file", last_error_code(), path_to_tstring( filePath ) ); +#endif } } diff --git a/src/internal/cfileoutstream.cpp b/src/internal/cfileoutstream.cpp index 6e8a6fdd..0bf1dc42 100644 --- a/src/internal/cfileoutstream.cpp +++ b/src/internal/cfileoutstream.cpp @@ -34,7 +34,12 @@ CFileOutStream::CFileOutStream( fs::path filePath, bool createAlways ) } mFileStream.open( mFilePath, std::ios::binary | std::ios::trunc ); // flawfinder: ignore if ( mFileStream.fail() ) { +#if defined( __MINGW32__ ) || defined( __MINGW64__ ) + std::error_code error{ errno, std::generic_category() }; + throw BitException( "Failed to open the output file", error, path_to_tstring( mFilePath ) ); +#else throw BitException( "Failed to open the output file", last_error_code(), path_to_tstring( mFilePath ) ); +#endif } mFileStream.rdbuf()->pubsetbuf( mBuffer.data(), kBufferSize );