Skip to content

Commit

Permalink
Fix error messages when opening file streams on MinGW
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Jan 17, 2024
1 parent 8857bc7 commit 8a69c77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/internal/cfileinstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/internal/cfileoutstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 8a69c77

Please sign in to comment.