diff --git a/p-filesystem.cc b/p-filesystem.cc index 5fc8f39..a6697e9 100644 --- a/p-filesystem.cc +++ b/p-filesystem.cc @@ -5,10 +5,12 @@ #include using namespace ebcl; + #ifdef _WIN32 # define M_PATHSEP_ '\\' #else # define M_PATHSEP_ '/' +# include #endif @@ -324,3 +326,21 @@ T_FSPath T_FSPath::canonical( ) const noexcept } return np; } + + +/*= Filesystem ===============================================================*/ + +T_FSPath Filesystem::Cwd( ) noexcept +{ + // TODO windows version + + T_Buffer< char > buffer{ 256 }; + while ( getcwd( &buffer[ 0 ] , buffer.bytes( ) ) == nullptr ) { + assert( errno == ERANGE ); + buffer.resize( buffer.size( ) + 256 ); + } + + T_FSPath path{ &buffer[ 0 ] }; + assert( path.isValid( ) ); + return path; +} diff --git a/p-filesystem.hh b/p-filesystem.hh index 83e35c4..7b7e9bc 100644 --- a/p-filesystem.hh +++ b/p-filesystem.hh @@ -116,11 +116,12 @@ M_LSHIFT_OP( T_StringBuilder , T_FSPath const& ); /*= FILESYSTEM ===============================================================*/ -class T_Filesystem +class Filesystem final { + Filesystem( ) = delete; public: - // Return the absolute path to the current directory - static T_FSPath currentDirectory( ) noexcept; + // Return the absolute path to the current working directory + static T_FSPath Cwd( ) noexcept; };