Filesystem abstraction prototype - Filesystem::Cwd()
This commit is contained in:
parent
f5b4113806
commit
2e8d460f1f
2 changed files with 24 additions and 3 deletions
|
@ -5,10 +5,12 @@
|
|||
#include <p-filesystem.hh>
|
||||
using namespace ebcl;
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
# define M_PATHSEP_ '\\'
|
||||
#else
|
||||
# define M_PATHSEP_ '/'
|
||||
# include <unistd.h>
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue