Filesystem: added some checks

This commit is contained in:
zvon 2020-01-18 21:31:09 +01:00
parent 1d69bdd770
commit d546d8442f
2 changed files with 8 additions and 3 deletions

View File

@ -1,4 +1,5 @@
#include "../filesystem.hpp"
#include <cstring>
#include <sys/stat.h>
FSLib::Directory::Directory( const string &path_ ) : dir_path( path_ ) {}
@ -19,6 +20,7 @@ FSLib::Directory::Iterator::Iterator( const Directory &d_,
: d( opendir( d_.path() ) ), current_entry( current_entry_ ) {}
FSLib::Directory::Iterator::~Iterator() {
if( d )
closedir( d );
}
@ -44,7 +46,8 @@ string FSLib::canonical( const string &path ) {
bool FSLib::isDirectory( const string &path ) {
struct stat path_stat;
stat( path.c_str(), &path_stat );
if( stat( path.c_str(), &path_stat ) != 0 )
return false;
return S_ISDIR( path_stat.st_mode );
}

View File

@ -1,5 +1,6 @@
#include "../filesystem.hpp"
#include <Shlwapi.h>
#include <cstring>
#include <windows.h>
FSLib::Directory::Directory( const string &path_ ) : dir_path( path_ ) {
@ -63,7 +64,8 @@ string FSLib::canonical( const string &path ) {
bool FSLib::isDirectory( const string &path ) {
struct _stat path_stat;
_wstat( path.c_str(), &path_stat );
if( _wstat( path.c_str(), &path_stat ) != 0 )
return false;
return path_stat.st_mode & _S_IFDIR;
}