Filesystem: refactor
This commit is contained in:
parent
d9351c583f
commit
1036431f2e
@ -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;
|
||||||
|
|
||||||
|
@ -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 ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user