From 07f8f86b181a2c3888fd6904ead3947a27771479 Mon Sep 17 00:00:00 2001 From: hama Date: Mon, 2 Feb 2015 21:26:12 +0100 Subject: [PATCH] win32 corrections --- base/ReByteBuffer.cpp | 3 ++- base/rebase.hpp | 2 ++ os/ReDirTools.cpp | 20 ++++++++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/base/ReByteBuffer.cpp b/base/ReByteBuffer.cpp index 234bd8e..c81b062 100644 --- a/base/ReByteBuffer.cpp +++ b/base/ReByteBuffer.cpp @@ -202,7 +202,7 @@ ReByteBuffer& ReByteBuffer::appendHexDump(const char* data, size_t length, ensureSize(32); int offsetLength = 0; if (offsetFormat != NULL){ - snprintf(m_buffer, 31, offsetFormat, offset + length); + _snprintf(m_buffer, 31, offsetFormat, offset + length); offsetLength = strlen(m_buffer); } ensureSize((length + bytesPerLine - 1) / bytesPerLine @@ -243,6 +243,7 @@ ReByteBuffer& ReByteBuffer::appendHexDump(const char* data, size_t length, data += bytesPerLine; offset += bytesPerLine; } + return *this; } /** @brief Appends a time (given in milli seconds) as 'dd:HH:MM.mmm'. diff --git a/base/rebase.hpp b/base/rebase.hpp index 6c15189..221c98b 100644 --- a/base/rebase.hpp +++ b/base/rebase.hpp @@ -51,6 +51,8 @@ typedef u_int8_t uint8_t; typedef _int64 int64_t; typedef unsigned long long uint64_t; typedef unsigned char uint8_t; + typedef unsigned long uint32_t; + typedef long int int32_t; # define S_ISDIR(mode) (((mode) & _S_IFDIR) != 0) # define ALLPERMS 0 # define _mkdir(name, mode) _mkdir(name) diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 50ab77b..7b016a1 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -23,7 +23,7 @@ enum LOCATION_DIRTOOL { LC_SET_PROPERTIES_2, // 50110 LC_SET_PROPERTIES_3, // 50111 }; -const char* ReDirTools::m_version = "2015.01.06"; +const char* ReDirTools::m_version = "2015.01.30"; static const char* s_helpSummary[] = { "dirtool or dt ", @@ -1208,6 +1208,9 @@ bool ReDirSync::copyFile(const char* source, ReFileProperties_t* properties, #elif defined __WIN32__ BOOL dummy; rc = CopyFileEx(source, target, NULL, NULL, &dummy, COPY_FILE_NO_BUFFERING) != 0; + int errNo = 0; + if (! rc) + errNo = GetLastError(); #endif return rc; } @@ -1275,6 +1278,8 @@ bool ReDirSync::makeDirectory(const char* directory, int minLength, // for all parents and the full path itself: while(ixSlash >= 0){ ixSlash = path.indexOf(OS_SEPARATOR_CHAR, ixSlash + 1); + if (ixSlash >= path.length() - 1) + break; // is the slash in front of the first node, e.g. 'e:\'? if (ixSlash == start + 1) // not a real node: take the next node @@ -1324,8 +1329,8 @@ void ReDirSync::synchronize(int argc, const char* argv[]){ if (m_programArgs.getArgCount() < 2) help(i18n("missing argument(s) (source / target)")); ReByteBuffer target(m_programArgs.getArg(m_programArgs.getArgCount() - 1)); - if (! target.endsWith(sep, 1)) - target.append(sep, 1); + if (target.endsWith(sep, 1)) + target.setLength(target.length() - 1); if (stat(target.str(), &info) != 0) help(i18n("target does not exist: $1"), target.str()); else if (! S_ISDIR(info.st_mode)) @@ -1348,14 +1353,17 @@ void ReDirSync::synchronize(int argc, const char* argv[]){ for (int ix = 0; ix < m_programArgs.getArgCount() - 1; ix++){ source.set(m_programArgs.getArg(ix), -1); target.setLength(lengthTargetBase); - - if (stat(target.str(), &info) != 0) + bool endsWithSlash = source.endsWith(sep, 1); + if (endsWithSlash) + source.setLength(source.length() - 1); + if (stat(source.str(), &info) != 0) help(i18n("source does not exist: $1"), source.str()); else if (! S_ISDIR(info.st_mode)) help(i18n("source is not a directory: $1"), source.str()); - if (! source.endsWith(sep, 1)){ + if (! endsWithSlash){ // the basename of the source will be appended to the target: int startNode = source.rindexOf(sep, 1, 0, source.length() - 1); + target.append(OS_SEPARATOR, 1); target.append(source.str() + startNode + 1, -1); } size_t ixSourceRelative = source.length(); -- 2.39.5