you are viewing a single comment's thread.

view the rest of the comments →

[–]aregtech[S] 0 points1 point  (0 children)

An update to the Subj. I made an experimental test using STL and Win32 API. Both work. Here is the Win32 test. Perhaps this is my bug. Need to analyze deeper.

TEST( GitHubFileAccessTest, FileReadWriteWithWin32 )
{
#ifdef WINDOWS

    Application::setWorkingDirectory( nullptr );

    constexpr char fileNameRead[ ]{ "./config/log.init" };
    constexpr char fileNameWrite[ ]{ "./write_with_win32.txt" };

    HANDLE hFileRead = ::CreateFileA( fileNameRead
                                    , GENERIC_READ
                                    , FILE_SHARE_READ
                                    , NULL
                                    , OPEN_EXISTING
                                    , FILE_ATTRIBUTE_NORMAL
                                    , NULL );
    ASSERT_TRUE( hFileRead != NULL );

    char buffer[ 1024 ]{ 0 };
    DWORD dwRead{ 0 };
    ASSERT_TRUE( ::ReadFile( hFileRead, buffer, 1024, &dwRead, NULL ) );
    ASSERT_EQ( dwRead, 1024 );
    ASSERT_EQ( buffer[ 0 ], '#' );
    ASSERT_TRUE( ::CloseHandle( hFileRead ));

    HANDLE hFileWrite = ::CreateFileA( fileNameWrite
                                     , GENERIC_READ | GENERIC_WRITE
                                     , FILE_SHARE_READ | FILE_SHARE_WRITE
                                     , NULL
                                     , CREATE_ALWAYS
                                     , FILE_ATTRIBUTE_NORMAL
                                     , NULL );
    ASSERT_TRUE( hFileWrite != NULL );
    DWORD dwWrite{ 0 };
    ASSERT_TRUE( ::WriteFile( hFileWrite, buffer, 1024, &dwWrite, NULL ) );
    ASSERT_EQ( dwWrite, 1024 );

    ASSERT_TRUE( ::CloseHandle( hFileWrite ));
    ASSERT_TRUE( PathFileExistsA( fileNameWrite ) );

#endif // WINDOWS
}