Merge pull request #10 from danman5555/master

Fix compilation error for POSIX files.

Former-commit-id: 4b4afe42ae8b43015bedf5a9ce215358e21840bc
This commit is contained in:
Lynix 2013-01-04 17:02:52 -08:00
commit 78b6874d08
8 changed files with 34 additions and 28 deletions

View File

@ -17,12 +17,12 @@ nzUInt64 NzClockImplGetMicroseconds()
{
timeval clock;
gettimeofday(&clock, nullptr);
return static_cast<nzUInt64>(clock.tv_sec*1000000 + (clock.tv_nsec/1000));
return static_cast<nzUInt64>(clock.tv_sec*1000000 + clock.tv_usec);
}
nzUInt64 NzClockImplGetMilliseconds()
{
timeval clock;
gettimeofday(&clock, nullptr);
return static_cast<nzUInt64>(clock.tv_sec*1000 + (clock.tv_nsec/1000000));
return static_cast<nzUInt64>(clock.tv_sec*1000 + (clock.tv_usec/1000));
}

View File

@ -28,7 +28,7 @@ void NzConditionVariableImpl::SignalAll()
void NzConditionVariableImpl::Wait(NzMutexImpl* mutex)
{
pthread_cond_wait(&m_cv, mutex);
pthread_cond_wait(&m_cv, &mutex->m_handle);
}
bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout)
@ -43,5 +43,5 @@ bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout)
ti.tv_sec = tv.tv_sec + (timeout / 1000) + (ti.tv_nsec / 1000000000);
ti.tv_nsec %= 1000000000;
pthread_cond_timedwait(&m_cv,mutex, &tv);
return pthread_cond_timedwait(&m_cv,&mutex->m_handle, &ti) != 0;
}

View File

@ -18,20 +18,24 @@ void NzDirectoryImpl::Close()
NzString NzDirectoryImpl::GetResultName() const
{
return m_result.d_name;
return m_result->d_name;
}
nzUInt64 NzDirectoryImpl::GetResultSize() const
{
struct stat64 resulststat;
stat64(m_result.d_name, &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);
struct stat64 filestats;
if (stat64(m_result->d_name, &filestats) == -1) // error
return false;
return S_ISDIR(filestats.st_mode);
}
bool NzDirectoryImpl::NextResult()
@ -68,10 +72,11 @@ bool NzDirectoryImpl::Create(const NzString& dirPath)
bool NzDirectoryImpl::Exists(const NzString& dirPath)
{
if (S_ISDIR(dirPath.GetConstBuffer()))
return true;
struct stat64 filestats;
if (stat64(dirPath.GetConstBuffer(), &filestats) == -1) // error
return false;
return S_ISDIR(filestats.st_mode) || S_ISREG(filestats.st_mode);
}
NzString NzDirectoryImpl::GetCurrent()

View File

@ -4,7 +4,6 @@
#include <Nazara/Core/Posix/FileImpl.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Posix/Time.hpp>
#include <Nazara/Core/Debug.hpp>
#include <stdio.h>
#include <unistd.h>
@ -26,7 +25,7 @@ bool NzFileImpl::EndOfFile() const
{
if (!m_endOfFileUpdated)
{
stat64 fileSize;
struct stat64 fileSize;
if (fstat64(m_fileDescriptor, &fileSize) == -1)
fileSize.st_size = 0;
@ -192,7 +191,7 @@ bool NzFileImpl::Delete(const NzString& filePath)
bool NzFileImpl::Exists(const NzString& filePath)
{
char* path = filePath.GetConstBuffer();
const char* path = filePath.GetConstBuffer();
if (access(path, F_OK) != -1)
return true;

View File

@ -12,20 +12,20 @@ NzMutexImpl::NzMutexImpl()
NzMutexImpl::~NzMutexImpl()
{
pthread_mutex_destroy(m_handle);
pthread_mutex_destroy(&m_handle);
}
void NzMutexImpl::Lock()
{
pthread_mutex_lock(m_handle);
pthread_mutex_lock(&m_handle);
}
bool NzMutexImpl::TryLock()
{
return pthread_mutex_trylock(m_handle) == 0;
return pthread_mutex_trylock(&m_handle) == 0;
}
void NzMutexImpl::Unlock()
{
pthread_mutex_unlock(m_handle);
pthread_mutex_unlock(&m_handle);
}

View File

@ -7,11 +7,11 @@
#include <Nazara/Core/Error.hpp>
#include <limits>
#include <Nazara/Core/Debug.hpp>
#include <sys/time.h>
NzSemaphoreImpl::NzSemaphoreImpl(unsigned int count)
{
m_semaphore = sem_init(&m_semaphore, 0, count);
if (!m_semaphore)
if(sem_init(&m_semaphore, 0, count) != 0)
NazaraError("Failed to create semaphore: " + NzGetLastSystemError());
}
@ -22,8 +22,8 @@ NzSemaphoreImpl::~NzSemaphoreImpl()
unsigned int NzSemaphoreImpl::GetCount() const
{
int count;
sem_getvalue(&m_semaphore, &count);
int count=0;
sem_getvalue(const_cast<sem_t*>(&m_semaphore), &count);
return static_cast<unsigned int>(count);
}
@ -49,13 +49,16 @@ void NzSemaphoreImpl::Wait()
bool NzSemaphoreImpl::Wait(nzUInt32 timeout)
{
timeval tv;
gettimeofday(&tv, nullptr);
timespec ti;
ti.tv_nsec = (tv.tv_usec + (timeout % 1000)) * 1000000;
ti.tv_sec = tv.tv_sec + (timeout / 1000) + (ti.tv_nsec / 1000000000);
ti.tv_nsec %= 1000000000;
#if NAZARA_CORE_SAFE
if (sem_timedwait(m_semaphore, timeout) == -1)
if (sem_timedwait(&m_semaphore, &ti) != 0)
{
NazaraError("Failed to wait for semaphore: " + NzGetLastSystemError());
return false;
@ -63,6 +66,6 @@ bool NzSemaphoreImpl::Wait(nzUInt32 timeout)
return true;
#else
return sem_timedwait(&m_semaphore, ti) == 0 && errno != ETIMEDOUT;
return sem_timedwait(&m_semaphore, &ti) != 0;
#endif
}

View File

@ -5,7 +5,6 @@
#include <Nazara/Core/Posix/ThreadImpl.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Functor.hpp>
#include <process.h>
#include <unistd.h>
#include <sys/time.h>
#include <Nazara/Core/Debug.hpp>
@ -27,13 +26,13 @@ void NzThreadImpl::Join()
pthread_join(m_handle, nullptr);
}
unsigned int NzThreadImpl::ThreadProc(void* userdata)
void* NzThreadImpl::ThreadProc(void* userdata)
{
NzFunctor* func = static_cast<NzFunctor*>(userdata);
func->Run();
delete func;
return 0;
return nullptr;
}
void NzThreadImpl::Sleep(nzUInt32 time)
@ -48,7 +47,7 @@ void NzThreadImpl::Sleep(nzUInt32 time)
// get the current time
timeval tv;
gettimeofday(&tv, NULL);
gettimeofday(&tv, nullptr);
// construct the time limit (current time + time to wait)
timespec ti;

View File

@ -23,7 +23,7 @@ class NzThreadImpl
static void Sleep(nzUInt32 time);
private:
static unsigned int ThreadProc(void* userdata);
static void* ThreadProc(void* userdata);
pthread_t m_handle;
};