[Core] Added POSIX support (Experimental)
Thanks to Danman I don't think it actually compile although tried my best to correct code. Former-commit-id: c3366c2c924f7392f4d46824dafca63ecf7f1fea
This commit is contained in:
97
src/Nazara/Core/Posix/DirectoryImpl.cpp
Normal file
97
src/Nazara/Core/Posix/DirectoryImpl.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
// Copyright (C) 2012 Alexandre Janniaux
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Posix/DirectoryImpl.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzDirectoryImpl::NzDirectoryImpl(const NzDirectory* parent)
|
||||
{
|
||||
NazaraUnused(parent);
|
||||
}
|
||||
|
||||
void NzDirectoryImpl::Close()
|
||||
{
|
||||
closedir(m_handle);
|
||||
}
|
||||
|
||||
NzString NzDirectoryImpl::GetResultName() const
|
||||
{
|
||||
return m_result.d_name;
|
||||
}
|
||||
|
||||
nzUInt64 NzDirectoryImpl::GetResultSize() const
|
||||
{
|
||||
struct stat64 resulststat;
|
||||
stat64(m_result.d_name, &resulststat);
|
||||
|
||||
return static_cast<nzUInt64>(resulststat.st_size);
|
||||
}
|
||||
|
||||
bool NzDirectoryImpl::IsResultDirectory() const
|
||||
{
|
||||
return S_ISDIR(m_result.d_name);
|
||||
}
|
||||
|
||||
bool NzDirectoryImpl::NextResult()
|
||||
{
|
||||
if ((m_result = readdir64(m_handle)))
|
||||
return true;
|
||||
else
|
||||
{
|
||||
if (errno != ENOENT)
|
||||
NazaraError("Unable to get next result: " + NzGetLastSystemError());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzDirectoryImpl::Open(const NzString& dirPath)
|
||||
{
|
||||
m_handle = opendir(dirPath.GetConstBuffer());
|
||||
if (!m_handle)
|
||||
{
|
||||
NazaraError("Unable to open directory: " + NzGetLastSystemError());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzDirectoryImpl::Create(const NzString& dirPath)
|
||||
{
|
||||
mode_t permissions; // TODO: check permissions
|
||||
|
||||
return mkdir(dirPath.GetConstBuffer(), permissions) != -1;;
|
||||
}
|
||||
|
||||
bool NzDirectoryImpl::Exists(const NzString& dirPath)
|
||||
{
|
||||
if (S_ISDIR(dirPath.GetConstBuffer()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
NzString NzDirectoryImpl::GetCurrent()
|
||||
{
|
||||
NzString currentPath;
|
||||
char* path = new char[_PC_PATH_MAX];
|
||||
|
||||
if (getcwd(path, _PC_PATH_MAX))
|
||||
currentPath = path;
|
||||
else
|
||||
NazaraError("Unable to get current directory: " + NzGetLastSystemError());
|
||||
|
||||
delete[] path;
|
||||
|
||||
return currentPath;
|
||||
}
|
||||
|
||||
bool NzDirectoryImpl::Remove(const NzString& dirPath)
|
||||
{
|
||||
bool success = rmdir(dirPath.GetConstBuffer()) != -1;
|
||||
|
||||
return success;
|
||||
}
|
||||
Reference in New Issue
Block a user