Merge pull request #95 from bitshares/jmj_readsome
mac fc::io::readsome fix
This commit is contained in:
commit
e9886b0628
2 changed files with 13 additions and 7 deletions
|
|
@ -65,11 +65,17 @@ namespace fc {
|
||||||
const boost::filesystem::path& bfp = file;
|
const boost::filesystem::path& bfp = file;
|
||||||
my->ifs.open( bfp, std::ios::binary );
|
my->ifs.open( bfp, std::ios::binary );
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ifstream::readsome( char* buf, size_t len ) {
|
size_t ifstream::readsome( char* buf, size_t len ) {
|
||||||
auto s = size_t(my->ifs.readsome( buf, len ));
|
auto s = size_t(my->ifs.readsome( buf, len ));
|
||||||
if( s <= 0 ) {
|
if( s <= 0 )
|
||||||
|
{
|
||||||
read( buf, 1 );
|
read( buf, 1 );
|
||||||
s = 1;
|
s = 1;
|
||||||
|
if (len > 1)
|
||||||
|
{
|
||||||
|
s += size_t(my->ifs.readsome( &buf[1], len - 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,11 +112,11 @@ BOOST_AUTO_TEST_CASE(fstream_test)
|
||||||
BOOST_CHECK_THROW( in2.readsome( buf, 3, 0 ), fc::eof_exception );
|
BOOST_CHECK_THROW( in2.readsome( buf, 3, 0 ), fc::eof_exception );
|
||||||
|
|
||||||
{
|
{
|
||||||
out.flush();
|
out.close();
|
||||||
std::fstream test( outf.path().to_native_ansi_path(), std::fstream::in );
|
std::fstream test( outf.path().to_native_ansi_path(), std::fstream::in );
|
||||||
BOOST_CHECK_EQUAL( 11u, test.readsome( (&(*buf)), 11 ) );
|
test.read( (&(*buf)), 11 );
|
||||||
BOOST_CHECK_EQUAL( "Hello world", std::string( (&(*buf)), 11 ) );
|
BOOST_CHECK_EQUAL( "Hello world", std::string( (&(*buf)), 11 ) );
|
||||||
BOOST_CHECK_EQUAL( 0u, test.readsome( (&(*buf)), 11 ) );
|
BOOST_CHECK(!test.read( (&(*buf)), 11 ));
|
||||||
test.close();
|
test.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,11 +166,11 @@ BOOST_AUTO_TEST_CASE(buffered_fstream_test)
|
||||||
BOOST_CHECK_THROW( bin2.readsome( buf, 3, 0 ), fc::eof_exception );
|
BOOST_CHECK_THROW( bin2.readsome( buf, 3, 0 ), fc::eof_exception );
|
||||||
|
|
||||||
{
|
{
|
||||||
bout.flush();
|
bout.close();
|
||||||
std::fstream test( outf.path().to_native_ansi_path(), std::fstream::in );
|
std::fstream test( outf.path().to_native_ansi_path(), std::fstream::in );
|
||||||
BOOST_CHECK_EQUAL( 11u, test.readsome( (&(*buf)), 11 ) );
|
test.read( (&(*buf)), 11 );
|
||||||
BOOST_CHECK_EQUAL( "Hello world", std::string( (&(*buf)), 11 ) );
|
BOOST_CHECK_EQUAL( "Hello world", std::string( (&(*buf)), 11 ) );
|
||||||
BOOST_CHECK_EQUAL( 0u, test.readsome( (&(*buf)), 11 ) );
|
BOOST_CHECK(!test.read( (&(*buf)), 11 ));
|
||||||
test.close();
|
test.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue