Filesystem: refactor
This commit is contained in:
parent
d9351c583f
commit
1036431f2e
@ -1,27 +1,20 @@
|
||||
#ifndef FSLIB_H
|
||||
#define FSLIB_H
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
#endif
|
||||
|
||||
// set apropriate data types for each operating system
|
||||
#ifdef _WIN32
|
||||
|
||||
using string = std::wstring;
|
||||
using char_t = wchar_t;
|
||||
|
||||
#else
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
using string = std::string;
|
||||
using char_t = char;
|
||||
|
||||
|
@ -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 ) {
|
||||
|
Loading…
Reference in New Issue
Block a user