Filesystem: refactor

This commit is contained in:
zvon 2020-01-15 18:21:27 +01:00
parent d9351c583f
commit 1036431f2e
2 changed files with 5 additions and 12 deletions

View File

@ -1,27 +1,20 @@
#ifndef FSLIB_H #ifndef FSLIB_H
#define FSLIB_H #define FSLIB_H
#include <string.h> #include <cstring>
#include <string> #include <string>
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#else
#include <dirent.h>
#endif
// set apropriate data types for each operating system
#ifdef _WIN32
using string = std::wstring; using string = std::wstring;
using char_t = wchar_t; using char_t = wchar_t;
#else #else
#include <dirent.h>
using string = std::string; using string = std::string;
using char_t = char; using char_t = char;

View File

@ -6,6 +6,8 @@ FSLib::Directory::Directory( const string &path_ ) : dir_path( path_ ) {}
FSLib::Directory::Iterator::Iterator( const Directory &d_ ) FSLib::Directory::Iterator::Iterator( const Directory &d_ )
: d( opendir( d_.path() ) ) { : d( opendir( d_.path() ) ) {
current_entry = readdir( d ); current_entry = readdir( d );
// skip "." and ".."
if ( current_entry != nullptr && if ( current_entry != nullptr &&
( !strcmp( current_entry->d_name, "." ) || ( !strcmp( current_entry->d_name, "." ) ||
!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 ) { string FSLib::canonical( const string &path ) {
char_t *canonical_path = new char_t[PATH_MAX]; char_t *canonical_path = new char_t[PATH_MAX];
auto failed = realpath( path.c_str(), canonical_path ) == nullptr; auto failed = realpath( path.c_str(), canonical_path ) == nullptr;
if ( failed ) { if ( failed ) {