From 852573432fdbe567916ecc7a09662b3a44bd3cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Wed, 27 Dec 2017 10:22:40 +0100 Subject: [PATCH] Filesystem abstraction prototype - Windows version of Cwd() --- p-filesystem.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/p-filesystem.cc b/p-filesystem.cc index 9751e00..adef205 100644 --- a/p-filesystem.cc +++ b/p-filesystem.cc @@ -368,10 +368,20 @@ T_FSPath Filesystem::Cwd( ) noexcept // TODO windows version 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 ) { assert( errno == ERANGE ); buffer.resize( buffer.size( ) + 256 ); } +#endif T_FSPath path{ &buffer[ 0 ] }; assert( path.isValid( ) );