From 0bc48cb700b05a5b051b58a9c45d42a06554bfcf Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Sat, 21 Feb 2015 01:10:51 +0100 Subject: [PATCH] win corrections --- base/rebase.hpp | 2 +- cunit/cuReDirTools.cpp | 6 +++++- cunit/cuReHashList.cpp | 1 - cunit/cuReMD5.cpp | 2 +- os/ReDirTools.cpp | 16 ++++++++++++---- os/ReDirTools.hpp | 2 +- os/ReTraverser.hpp | 2 ++ os/reos.hpp | 5 ++++- 8 files changed, 26 insertions(+), 10 deletions(-) diff --git a/base/rebase.hpp b/base/rebase.hpp index d22d67b..a45037e 100644 --- a/base/rebase.hpp +++ b/base/rebase.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -24,6 +23,7 @@ #if defined __linux__ +# include # include # include # include diff --git a/cunit/cuReDirTools.cpp b/cunit/cuReDirTools.cpp index 578c223..d2d8994 100644 --- a/cunit/cuReDirTools.cpp +++ b/cunit/cuReDirTools.cpp @@ -78,7 +78,11 @@ private: ReDirList().run(2, argv); } int secOfFileTime(ReFileTime_t data){ +#if defined __linux__ return data.tv_sec; +#elif defined __WIN32__ + return (int) ReDirStatus_t::filetimeToTime(&data); +#endif } void testCopyFile(){ #if defined __linux__ @@ -246,7 +250,7 @@ private: checkEqu(expected.count(), current.count()); ReByteBuffer line; ReStringList cols; - for (int ix = 0; ix < current.count(); ix++){ + for (size_t ix = 0; ix < current.count(); ix++){ line.setLength(0).append(current.strOf(ix), -1); cols.split(expected.strOf(ix), '*'); checkT(line.startsWith(cols.strOf(0))); diff --git a/cunit/cuReHashList.cpp b/cunit/cuReHashList.cpp index a8ee236..6990a6e 100644 --- a/cunit/cuReHashList.cpp +++ b/cunit/cuReHashList.cpp @@ -32,7 +32,6 @@ private: list.setSizes(4, maxKeys <= 0xffff ? 2 : 3); ReByteBuffer key, value; int64_t start = timer(); - ReSeqArray::Tag tag; int ix; int collisions = 0; for(ix = 0; ix < maxKeys; ix++){ diff --git a/cunit/cuReMD5.cpp b/cunit/cuReMD5.cpp index 4bd88fc..f17df7c 100644 --- a/cunit/cuReMD5.cpp +++ b/cunit/cuReMD5.cpp @@ -68,7 +68,7 @@ private: max2 = random.nextInt(20); while(text.length() > 0){ int part = random.nextInt(32, 32 + 1 + max2); - if (part > text.length()) + if (part > (int) text.length()) part = text.length(); md5.update((uint8_t*) text.str(), part); text.remove(0, part); diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 0544b3b..232b230 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -747,7 +747,7 @@ void ReTool::processSingleFile(const char* filename){ #if defined __linux__ bool found = strcmp(entry.node(), name.str()) == 0; #elif defined __WIN32__ - bool found = stricmp(entry.node(), name.str()) == 0; + bool found = _stricmp(entry.node(), name.str()) == 0; #endif if (found && m_filter.match(entry)){ processFile(&entry); @@ -1301,6 +1301,10 @@ static bool isAbsoluteTime(ReFileTime_t& time){ #if defined __linux__ return time.tv_sec >= time1980; #elif defined __WIN32__ + static ReFileTime_t time2 = { 0, 0 }; + if (time2.dwHighDateTime == 0 && time2.dwLowDateTime == 0) + ReDirStatus_t::timeToFiletime(time1980, time2); + return time2 > time; #endif } static void addRelativeTime(ReFileTime_t& absTime, const ReFileTime_t& relTime){ @@ -1311,8 +1315,12 @@ static void addRelativeTime(ReFileTime_t& absTime, const ReFileTime_t& relTime){ } absTime.tv_sec += relTime.tv_sec; #elif defined __WIN32__ + uint64_t absValue = ((uint64_t) absTime.dwHighDateTime << 32) | absTime.dwLowDateTime; + uint64_t relValue = ((uint64_t) relTime.dwHighDateTime << 32) | relTime.dwLowDateTime; + absValue += relValue; + absTime.dwHighDateTime = (uint32_t) (absValue >> 32); + absTime.dwLowDateTime = (uint32_t) absValue; #endif - } /** * Processes one file. @@ -1396,10 +1404,10 @@ ReErrNo_t ReDirTouch::touch(const char* filename, const ReFileTime_t& modified, HANDLE handle = CreateFile(filename, FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (handle == UNDEF_HANDLE) + if (handle == INVALID_HANDLE_VALUE) rc = GetLastError(); else { - if (SetFileTime(handle, (LPFILETIME) NULL,(LPFILETIME) NULL,&thefiletime) != 0) + if (! SetFileTime(handle, (LPFILETIME) NULL, &accessed, &modified)) rc = GetLastError(); CloseHandle(handle); } diff --git a/os/ReDirTools.hpp b/os/ReDirTools.hpp index 259f415..c539d58 100644 --- a/os/ReDirTools.hpp +++ b/os/ReDirTools.hpp @@ -68,7 +68,7 @@ typedef struct stat ReFileProperties_t; typedef struct { FILETIME m_modified; FILETIME m_accessed; - FileSize_t m_size; + ReFileSize_t m_size; } ReFileProperties_t; #endif diff --git a/os/ReTraverser.hpp b/os/ReTraverser.hpp index 2b967f5..8606b0a 100644 --- a/os/ReTraverser.hpp +++ b/os/ReTraverser.hpp @@ -25,6 +25,7 @@ inline bool filetimeIsUndefined(ReFileTime_t& time){ #if defined __linux__ return time.tv_sec == 0 && time.tv_nsec == 0; #elif defined __WIN32__ + return time.dwHighDateTime == 0 && time.dwLowDateTime == 0; #endif } /** Sets the filetime to undefined. @@ -34,6 +35,7 @@ inline void setFiletimeUndef(ReFileTime_t& time){ #if defined __linux__ time.tv_sec = time.tv_nsec = 0; #elif defined __WIN32__ + time.dwHighDateTime = time.dwLowDateTime = 0; #endif } diff --git a/os/reos.hpp b/os/reos.hpp index f9aeaf4..74083da 100644 --- a/os/reos.hpp +++ b/os/reos.hpp @@ -28,8 +28,11 @@ */ inline bool operator >(const ReFileTime_t& time1, const ReFileTime_t& time2){ #if defined __linux__ - return time1.tv_sec > time1.tv_sec || time1.tv_sec == time2.tv_sec && time1.tv_nsec > time2.tv_nsec; + return time1.tv_sec > time2.tv_sec || time1.tv_sec == time2.tv_sec && time1.tv_nsec > time2.tv_nsec; #else + return time1.dwHighDateTime > time2.dwHighDateTime + || time1.dwHighDateTime == time2.dwHighDateTime + && time1.dwLowDateTime > time2.dwLowDateTime; #endif } #include "os/ReTraverser.hpp" -- 2.39.5