Filesystem abstraction prototype - Windows version of Cwd()

This commit is contained in:
Emmanuel BENOîT 2017-12-27 10:22:40 +01:00
parent 2d3f98aba1
commit 852573432f

View file

@ -368,10 +368,20 @@ T_FSPath Filesystem::Cwd( ) noexcept
// TODO windows version // TODO windows version
T_Buffer< char > buffer{ 256 }; T_Buffer< char > buffer{ 256 };
#if _WIN32
auto req{ buffer.bytes( ) };
do {
if ( req > buffer.bytes( ) ) {
buffer.resize( req + 1 );
}
req = GetCurrentDirectory( buffer.bytes( ) , &buffer[ 0 ] );
} while ( req > buffer.bytes( ) );
#else
while ( getcwd( &buffer[ 0 ] , buffer.bytes( ) ) == nullptr ) { while ( getcwd( &buffer[ 0 ] , buffer.bytes( ) ) == nullptr ) {
assert( errno == ERANGE ); assert( errno == ERANGE );
buffer.resize( buffer.size( ) + 256 ); buffer.resize( buffer.size( ) + 256 );
} }
#endif
T_FSPath path{ &buffer[ 0 ] }; T_FSPath path{ &buffer[ 0 ] };
assert( path.isValid( ) ); assert( path.isValid( ) );