From 1036431f2ea70c663ff3b113e60fc84e53895371 Mon Sep 17 00:00:00 2001 From: zvon Date: Wed, 15 Jan 2020 18:21:27 +0100 Subject: [PATCH] Filesystem: refactor --- filesystem.hpp | 13 +++---------- unix/filesystem.cpp | 4 ++-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/filesystem.hpp b/filesystem.hpp index 9eb0a73..54d49e3 100644 --- a/filesystem.hpp +++ b/filesystem.hpp @@ -1,27 +1,20 @@ #ifndef FSLIB_H #define FSLIB_H -#include +#include #include #ifdef _WIN32 #include -#else - -#include - -#endif - -// set apropriate data types for each operating system -#ifdef _WIN32 - using string = std::wstring; using char_t = wchar_t; #else +#include + using string = std::string; using char_t = char; diff --git a/unix/filesystem.cpp b/unix/filesystem.cpp index 43df3e0..f0019ae 100644 --- a/unix/filesystem.cpp +++ b/unix/filesystem.cpp @@ -6,6 +6,8 @@ FSLib::Directory::Directory( const string &path_ ) : dir_path( path_ ) {} FSLib::Directory::Iterator::Iterator( const Directory &d_ ) : d( opendir( d_.path() ) ) { current_entry = readdir( d ); + + // skip "." and ".." if ( current_entry != nullptr && ( !strcmp( current_entry->d_name, "." ) || !strcmp( current_entry->d_name, ".." ) ) ) @@ -26,9 +28,7 @@ bool FSLib::exists( const string &path ) { } string FSLib::canonical( const string &path ) { - char_t *canonical_path = new char_t[PATH_MAX]; - auto failed = realpath( path.c_str(), canonical_path ) == nullptr; if ( failed ) {