summaryrefslogtreecommitdiff
path: root/zen
diff options
context:
space:
mode:
Diffstat (limited to 'zen')
-rwxr-xr-xzen/basic_math.h8
-rwxr-xr-xzen/build_info.h2
-rwxr-xr-xzen/crc.h2
-rwxr-xr-xzen/deprecate.h2
-rwxr-xr-xzen/dir_watcher.cpp2
-rwxr-xr-xzen/dir_watcher.h2
-rwxr-xr-xzen/error_log.h2
-rwxr-xr-xzen/file_access.cpp10
-rwxr-xr-xzen/file_access.h2
-rwxr-xr-xzen/file_error.h2
-rwxr-xr-xzen/file_id_def.h2
-rwxr-xr-xzen/file_io.cpp72
-rwxr-xr-xzen/file_io.h12
-rwxr-xr-xzen/file_traverser.cpp2
-rwxr-xr-xzen/file_traverser.h2
-rwxr-xr-xzen/fixed_list.h2
-rwxr-xr-xzen/format_unit.cpp2
-rwxr-xr-xzen/format_unit.h2
-rwxr-xr-xzen/globals.h2
-rwxr-xr-xzen/guid.h2
-rwxr-xr-xzen/i18n.h2
-rwxr-xr-xzen/optional.h2
-rwxr-xr-xzen/perf.h2
-rwxr-xr-xzen/process_priority.cpp2
-rwxr-xr-xzen/process_priority.h2
-rwxr-xr-xzen/recycler.cpp2
-rwxr-xr-xzen/recycler.h2
-rwxr-xr-xzen/scope_guard.h2
-rwxr-xr-xzen/serialize.h2
-rwxr-xr-xzen/shell_execute.h44
-rwxr-xr-xzen/shutdown.cpp36
-rwxr-xr-xzen/shutdown.h2
-rwxr-xr-xzen/stl_tools.h2
-rwxr-xr-xzen/string_base.h2
-rwxr-xr-xzen/string_tools.h2
-rwxr-xr-xzen/string_traits.h2
-rwxr-xr-xzen/symlink_target.h2
-rwxr-xr-xzen/sys_error.cpp2
-rwxr-xr-xzen/sys_error.h2
-rwxr-xr-xzen/thread.h2
-rwxr-xr-xzen/time.h2
-rwxr-xr-xzen/type_tools.h2
-rwxr-xr-xzen/type_traits.h2
-rwxr-xr-xzen/utf.h2
-rwxr-xr-xzen/warn_static.h2
-rwxr-xr-xzen/xml_io.cpp2
-rwxr-xr-xzen/xml_io.h2
-rwxr-xr-xzen/zstring.cpp8
-rwxr-xr-xzen/zstring.h2
49 files changed, 161 insertions, 113 deletions
diff --git a/zen/basic_math.h b/zen/basic_math.h
index 22f29ca7..1b6b7e97 100755
--- a/zen/basic_math.h
+++ b/zen/basic_math.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
@@ -288,9 +288,9 @@ double median(RandomAccessIterator first, RandomAccessIterator last) //note: inv
{
const size_t n = last - first;
if (n == 0)
- return 0;
+ return 0;
- std::nth_element(first, first + n / 2, last); //complexity: O(n)
+ std::nth_element(first, first + n / 2, last); //complexity: O(n)
const double midVal = *(first + n / 2);
if (n % 2 != 0)
@@ -306,7 +306,7 @@ double mad(RandomAccessIterator first, RandomAccessIterator last) //note: invali
//http://en.wikipedia.org/wiki/Median_absolute_deviation
const size_t n = last - first;
if (n == 0)
- return 0;
+ return 0;
const double m = median(first, last);
diff --git a/zen/build_info.h b/zen/build_info.h
index 8354f492..7b0aa9cf 100755
--- a/zen/build_info.h
+++ b/zen/build_info.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/crc.h b/zen/crc.h
index 67f0460e..6f6ca996 100755
--- a/zen/crc.h
+++ b/zen/crc.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/deprecate.h b/zen/deprecate.h
index c2a1ebfa..2a6bcb0d 100755
--- a/zen/deprecate.h
+++ b/zen/deprecate.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/dir_watcher.cpp b/zen/dir_watcher.cpp
index 4e759d55..17f2244d 100755
--- a/zen/dir_watcher.cpp
+++ b/zen/dir_watcher.cpp
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/dir_watcher.h b/zen/dir_watcher.h
index 5676555f..8045d184 100755
--- a/zen/dir_watcher.h
+++ b/zen/dir_watcher.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/error_log.h b/zen/error_log.h
index 0d62dd1f..1fcbdefb 100755
--- a/zen/error_log.h
+++ b/zen/error_log.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/file_access.cpp b/zen/file_access.cpp
index e7467325..1711e934 100755
--- a/zen/file_access.cpp
+++ b/zen/file_access.cpp
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
@@ -379,17 +379,17 @@ void setWriteTimeNative(const Zstring& itemPath, const struct ::timespec& modTim
using open()/futimens() for regular files and utimensat(AT_SYMLINK_NOFOLLOW) for symlinks is consistent with "cp" and "touch"!
*/
struct ::timespec newTimes[2] = {};
- newTimes[0].tv_sec = ::time(nullptr); //access time; using UTIME_OMIT for tv_nsec would trigger even more bugs: http://www.freefilesync.org/forum/viewtopic.php?t=1701
+ newTimes[0].tv_sec = ::time(nullptr); //access time; using UTIME_OMIT for tv_nsec would trigger even more bugs: https://www.freefilesync.org/forum/viewtopic.php?t=1701
newTimes[1] = modTime; //modification time
if (procSl == ProcSymlink::FOLLOW)
{
//hell knows why files on gvfs-mounted Samba shares fail to open(O_WRONLY) returning EOPNOTSUPP:
- //http://www.freefilesync.org/forum/viewtopic.php?t=2803 => utimensat() works (but not for gvfs SFTP)
+ //https://www.freefilesync.org/forum/viewtopic.php?t=2803 => utimensat() works (but not for gvfs SFTP)
if (::utimensat(AT_FDCWD, itemPath.c_str(), newTimes, 0) == 0)
return;
- //in other cases utimensat() returns EINVAL for CIFS/NTFS drives, but open+futimens works: http://www.freefilesync.org/forum/viewtopic.php?t=387
+ //in other cases utimensat() returns EINVAL for CIFS/NTFS drives, but open+futimens works: https://www.freefilesync.org/forum/viewtopic.php?t=387
const int fdFile = ::open(itemPath.c_str(), O_WRONLY | O_APPEND); //2017-07-04: O_WRONLY | O_APPEND seems to avoid EOPNOTSUPP on gvfs SFTP!
if (fdFile == -1)
THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(itemPath)), L"open");
@@ -649,7 +649,7 @@ FileCopyResult copyFileOsSpecific(const Zstring& sourceFile, //throw FileError,
//this triggers bugs on samba shares where the modification time is set to current time instead.
//Linux: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=340236
// http://comments.gmane.org/gmane.linux.file-systems.cifs/2854
- //OS X: http://www.freefilesync.org/forum/viewtopic.php?t=356
+ //OS X: https://www.freefilesync.org/forum/viewtopic.php?t=356
setWriteTimeNative(targetFile, sourceInfo.st_mtim, ProcSymlink::FOLLOW); //throw FileError
}
catch (const FileError& e)
diff --git a/zen/file_access.h b/zen/file_access.h
index 0a9b2d0c..743ad15d 100755
--- a/zen/file_access.h
+++ b/zen/file_access.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/file_error.h b/zen/file_error.h
index 18e790de..decc0f7e 100755
--- a/zen/file_error.h
+++ b/zen/file_error.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/file_id_def.h b/zen/file_id_def.h
index 8d429fbc..7772e3e3 100755
--- a/zen/file_id_def.h
+++ b/zen/file_id_def.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/file_io.cpp b/zen/file_io.cpp
index 68b41bcb..bb4848c6 100755
--- a/zen/file_io.cpp
+++ b/zen/file_io.cpp
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
@@ -115,6 +115,8 @@ size_t FileInput::tryRead(void* buffer, size_t bytesToRead) //throw FileError, E
bytesRead = ::read(getHandle(), buffer, bytesToRead);
}
while (bytesRead < 0 && errno == EINTR); //Compare copy_reg() in copy.c: ftp://ftp.gnu.org/gnu/coreutils/coreutils-8.23.tar.xz
+ //EINTR is not checked on macOS' copyfile: https://opensource.apple.com/source/copyfile/copyfile-146/copyfile.c.auto.html
+ //read() on macOS: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man2/read.2.html
if (bytesRead < 0)
THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot read file %x."), L"%x", fmtPath(getFilePath())), L"read");
@@ -129,23 +131,41 @@ size_t FileInput::tryRead(void* buffer, size_t bytesToRead) //throw FileError, E
size_t FileInput::read(void* buffer, size_t bytesToRead) //throw FileError, ErrorFileLocked, X; return "bytesToRead" bytes unless end of stream!
{
+ warn_static("implement PERF_AWESOME_BUFFER program wide for all buffers!?")
+
+ /*
+ FFS 8.9-9.5 perf issues on macOS: https://www.freefilesync.org/forum/viewtopic.php?t=4808
+ app-level buffering is essential to optimize random data sizes; e.g. "export file list":
+ => big perf improvement on Windows, Linux. No significant improvement on macOS in tests
+ impact on stream-based file copy:
+ => no drawback vs block-wise copy loop on Linux, HOWEVER: big perf issue on macOS!
+
+ Possible cause of macOS perf issue unclear:
+ - getting rid of std::vector::resize() and std::vector::erase() "fixed" the problem
+ => costly zero-initializing memory? problem with inlining? QOI issue of std:vector on clang/macOS?
+ - replacing std::copy() with memcpy() also *seems* to have improved speed "somewhat"
+ */
+
const size_t blockSize = getBlockSize();
- assert(memBuf_.size() <= blockSize);
+ assert(memBuf_.size() >= blockSize);
+ assert(bufPos_ <= bufPosEnd_ && bufPosEnd_ <= memBuf_.size());
+
char* it = static_cast<char*>(buffer);
char* const itEnd = it + bytesToRead;
for (;;)
{
- const size_t junkSize = std::min(static_cast<size_t>(itEnd - it), memBuf_.size());
- std::copy (memBuf_.begin(), memBuf_.begin() + junkSize, it);
- memBuf_.erase(memBuf_.begin(), memBuf_.begin() + junkSize);
- it += junkSize;
+ const size_t junkSize = std::min(static_cast<size_t>(itEnd - it), bufPosEnd_ - bufPos_);
+ std::memcpy(it, &memBuf_[bufPos_], junkSize);
+ bufPos_ += junkSize;
+ it += junkSize;
if (it == itEnd)
break;
+
//--------------------------------------------------------------------
- memBuf_.resize(blockSize);
const size_t bytesRead = tryRead(&memBuf_[0], blockSize); //throw FileError, ErrorFileLocked; may return short, only 0 means EOF! => CONTRACT: bytesToRead > 0
- memBuf_.resize(bytesRead);
+ bufPos_ = 0;
+ bufPosEnd_ = bytesRead;
if (notifyUnbufferedIO_) notifyUnbufferedIO_(bytesRead); //throw X
@@ -213,6 +233,7 @@ size_t FileOutput::tryWrite(const void* buffer, size_t bytesToWrite) //throw Fil
bytesWritten = ::write(getHandle(), buffer, bytesToWrite);
}
while (bytesWritten < 0 && errno == EINTR);
+ //write() on macOS: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man2/write.2.html
if (bytesWritten <= 0)
{
@@ -232,20 +253,32 @@ size_t FileOutput::tryWrite(const void* buffer, size_t bytesToWrite) //throw Fil
void FileOutput::write(const void* buffer, size_t bytesToWrite) //throw FileError, X
{
const size_t blockSize = getBlockSize();
- assert(memBuf_.size() <= blockSize);
- const char* it = static_cast<const char*>(buffer);
+ assert(memBuf_.size() >= blockSize);
+ assert(bufPos_ <= bufPosEnd_ && bufPosEnd_ <= memBuf_.size());
+
+ const char* it = static_cast<const char*>(buffer);
const char* const itEnd = it + bytesToWrite;
for (;;)
{
- const size_t junkSize = std::min(static_cast<size_t>(itEnd - it), blockSize - memBuf_.size());
- memBuf_.insert(memBuf_.end(), it, it + junkSize);
- it += junkSize;
+ if (memBuf_.size() - bufPos_ < blockSize) //support memBuf_.size() > blockSize to reduce memmove()s, but perf test shows: not really needed!
+ // || bufPos_ == bufPosEnd_) -> not needed while memBuf_.size() == blockSize
+ {
+ std::memmove(&memBuf_[0], &memBuf_[bufPos_], bufPosEnd_ - bufPos_);
+ bufPosEnd_ -= bufPos_;
+ bufPos_ = 0;
+ }
+
+ const size_t junkSize = std::min(static_cast<size_t>(itEnd - it), blockSize - (bufPosEnd_ - bufPos_));
+ std::memcpy(&memBuf_[bufPosEnd_], it, junkSize);
+ bufPosEnd_ += junkSize;
+ it += junkSize;
if (it == itEnd)
return;
+
//--------------------------------------------------------------------
- const size_t bytesWritten = tryWrite(&memBuf_[0], blockSize); //throw FileError; may return short! CONTRACT: bytesToWrite > 0
- memBuf_.erase(memBuf_.begin(), memBuf_.begin() + bytesWritten);
+ const size_t bytesWritten = tryWrite(&memBuf_[bufPos_], blockSize); //throw FileError; may return short! CONTRACT: bytesToWrite > 0
+ bufPos_ += bytesWritten;
if (notifyUnbufferedIO_) notifyUnbufferedIO_(bytesWritten); //throw X!
}
}
@@ -253,11 +286,12 @@ void FileOutput::write(const void* buffer, size_t bytesToWrite) //throw FileErro
void FileOutput::flushBuffers() //throw FileError, X
{
- assert(memBuf_.size() <= getBlockSize());
- while (!memBuf_.empty())
+ assert(bufPosEnd_ - bufPos_ <= getBlockSize());
+ assert(bufPos_ <= bufPosEnd_ && bufPosEnd_ <= memBuf_.size());
+ while (bufPos_ != bufPosEnd_)
{
- const size_t bytesWritten = tryWrite(&memBuf_[0], memBuf_.size()); //throw FileError; may return short! CONTRACT: bytesToWrite > 0
- memBuf_.erase(memBuf_.begin(), memBuf_.begin() + bytesWritten);
+ const size_t bytesWritten = tryWrite(&memBuf_[bufPos_], bufPosEnd_ - bufPos_); //throw FileError; may return short! CONTRACT: bytesToWrite > 0
+ bufPos_ += bytesWritten;
if (notifyUnbufferedIO_) notifyUnbufferedIO_(bytesWritten); //throw X!
}
}
diff --git a/zen/file_io.h b/zen/file_io.h
index c2071500..369cdc01 100755
--- a/zen/file_io.h
+++ b/zen/file_io.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
@@ -64,8 +64,11 @@ public:
private:
size_t tryRead(void* buffer, size_t bytesToRead); //throw FileError, ErrorFileLocked; may return short, only 0 means EOF! => CONTRACT: bytesToRead > 0!
- std::vector<char> memBuf_;
const IOCallback notifyUnbufferedIO_; //throw X
+
+ std::vector<char> memBuf_ = std::vector<char>(getBlockSize());
+ size_t bufPos_ = 0;
+ size_t bufPosEnd_= 0;
};
@@ -90,8 +93,11 @@ public:
private:
size_t tryWrite(const void* buffer, size_t bytesToWrite); //throw FileError; may return short! CONTRACT: bytesToWrite > 0
- std::vector<char> memBuf_;
IOCallback notifyUnbufferedIO_; //throw X
+
+ std::vector<char> memBuf_ = std::vector<char>(getBlockSize());
+ size_t bufPos_ = 0;
+ size_t bufPosEnd_ = 0;
};
//-----------------------------------------------------------------------------------------------
diff --git a/zen/file_traverser.cpp b/zen/file_traverser.cpp
index 916b6e8d..aa4c439e 100755
--- a/zen/file_traverser.cpp
+++ b/zen/file_traverser.cpp
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/file_traverser.h b/zen/file_traverser.h
index 1f7142de..19359148 100755
--- a/zen/file_traverser.h
+++ b/zen/file_traverser.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/fixed_list.h b/zen/fixed_list.h
index 27eb488c..535ffa31 100755
--- a/zen/fixed_list.h
+++ b/zen/fixed_list.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/format_unit.cpp b/zen/format_unit.cpp
index e62c9286..0f54a34b 100755
--- a/zen/format_unit.cpp
+++ b/zen/format_unit.cpp
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/format_unit.h b/zen/format_unit.h
index 3dcc6858..154ec542 100755
--- a/zen/format_unit.h
+++ b/zen/format_unit.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/globals.h b/zen/globals.h
index b85d5f77..32781f2a 100755
--- a/zen/globals.h
+++ b/zen/globals.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/guid.h b/zen/guid.h
index f47a141c..633547ad 100755
--- a/zen/guid.h
+++ b/zen/guid.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/i18n.h b/zen/i18n.h
index e6d97b7b..bb6dbac5 100755
--- a/zen/i18n.h
+++ b/zen/i18n.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/optional.h b/zen/optional.h
index 0efc34fe..a2a1a169 100755
--- a/zen/optional.h
+++ b/zen/optional.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/perf.h b/zen/perf.h
index bd21159c..72b57f52 100755
--- a/zen/perf.h
+++ b/zen/perf.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/process_priority.cpp b/zen/process_priority.cpp
index 5767e60c..e925f142 100755
--- a/zen/process_priority.cpp
+++ b/zen/process_priority.cpp
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/process_priority.h b/zen/process_priority.h
index ac96a8ae..bec8f9b5 100755
--- a/zen/process_priority.h
+++ b/zen/process_priority.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/recycler.cpp b/zen/recycler.cpp
index c84ef8f3..30b37cb2 100755
--- a/zen/recycler.cpp
+++ b/zen/recycler.cpp
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/recycler.h b/zen/recycler.h
index 54dd75ca..0e5ebbb1 100755
--- a/zen/recycler.h
+++ b/zen/recycler.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/scope_guard.h b/zen/scope_guard.h
index ccc6db0c..2048af9b 100755
--- a/zen/scope_guard.h
+++ b/zen/scope_guard.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/serialize.h b/zen/serialize.h
index 8f7e813c..381d102a 100755
--- a/zen/serialize.h
+++ b/zen/serialize.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/shell_execute.h b/zen/shell_execute.h
index 077f18e7..18e4854b 100755
--- a/zen/shell_execute.h
+++ b/zen/shell_execute.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
@@ -9,14 +9,14 @@
#include "file_error.h"
- #include "thread.h"
+ #include <unistd.h> //fork()
#include <stdlib.h> //::system()
namespace zen
{
//launch commandline and report errors via popup dialog
-//windows: COM needs to be initialized before calling this function!
+//Windows: COM needs to be initialized before calling this function!
enum ExecutionType
{
EXEC_TYPE_SYNC,
@@ -38,24 +38,34 @@ void shellExecute(const Zstring& command, ExecutionType type) //throw FileError
if (type == EXEC_TYPE_SYNC)
{
- //Posix::system - execute a shell command
+ //Posix ::system() - execute a shell command
const int rv = ::system(command.c_str()); //do NOT use std::system as its documentation says nothing about "WEXITSTATUS(rv)", ect...
- if (rv == -1 || WEXITSTATUS(rv) == 127) //http://linux.die.net/man/3/system "In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127)"
+ if (rv == -1 || WEXITSTATUS(rv) == 127)
throw FileError(_("Incorrect command line:") + L"\n" + utfTo<std::wstring>(command));
+ //http://linux.die.net/man/3/system "In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127)"
+ //Bonus: For an incorrect command line /bin/sh also returns with 127!
}
else
- {
- runAsync([=] { int rv = ::system(command.c_str()); (void)rv; });
-
- warn_static("finish:")
-
-
-
-
-
-
-
- }
+ {
+ //follow implemenation of ::system() except for waitpid():
+ const pid_t pid = ::fork();
+ if (pid < 0) //pids are never negative, empiric proof: https://linux.die.net/man/2/wait
+ THROW_LAST_FILE_ERROR(_("Incorrect command line:") + L"\n" + utfTo<std::wstring>(command), L"fork");
+
+ if (pid == 0) //child process
+ {
+ const char* argv[] = { "sh", "-c", command.c_str(), nullptr };
+ /*int rv =*/::execv("/bin/sh", const_cast<char**>(argv));
+ //safe to cast away const: http://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
+ // "The statement about argv[] and envp[] being constants is included to make explicit to future
+ // writers of language bindings that these objects are completely constant. Due to a limitation of
+ // the ISO C standard, it is not possible to state that idea in standard C."
+
+ //"execv() only returns if an error has occurred. The return value is -1, and errno is set to indicate the error."
+ ::_exit(127); //[!] avoid flushing I/O buffers or doing other clean up from child process like with "exit(127)"!
+ }
+ //else //parent process
+ }
}
}
}
diff --git a/zen/shutdown.cpp b/zen/shutdown.cpp
index b21ab8db..dd02814f 100755
--- a/zen/shutdown.cpp
+++ b/zen/shutdown.cpp
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
@@ -17,18 +17,16 @@ void zen::shutdownSystem() //throw FileError
{
//https://linux.die.net/man/2/reboot => needs admin rights!
- //should work without admin rights:
+ //"systemctl" should work without admin rights:
shellExecute("sleep 1; systemctl poweroff", EXEC_TYPE_ASYNC); //throw FileError
//sleep 1: give FFS some time to properly shut down!
- //Linux: main thread will wait on detached threads!
- warn_static("get rid of shellExecute's thread implementation!")
}
void zen::suspendSystem() //throw FileError
{
- //should work without admin rights:
+ //"systemctl" should work without admin rights:
shellExecute("systemctl suspend", EXEC_TYPE_ASYNC); //throw FileError
}
@@ -38,25 +36,25 @@ Command line alternatives:
#ifdef ZEN_WIN
#ifdef ZEN_WIN_VISTA_AND_LATER
- Shut down: shutdown /s /t 60
- Sleep: rundll32.exe powrprof.dll,SetSuspendState Sleep
- Log off: shutdown /l
+ Shut down: shutdown /s /t 60
+ Sleep: rundll32.exe powrprof.dll,SetSuspendState Sleep
+ Log off: shutdown /l
#else //XP
- Shut down: shutdown -s -t 60
- Standby: rundll32.exe powrprof.dll,SetSuspendState //this triggers standby OR hibernate, depending on whether hibernate setting is active! no suspend on XP?
- Log off: shutdown -l
+ Shut down: shutdown -s -t 60
+ Standby: rundll32.exe powrprof.dll,SetSuspendState //this triggers standby OR hibernate, depending on whether hibernate setting is active! no suspend on XP?
+ Log off: shutdown -l
#endif
#elif defined ZEN_LINUX
- Shut down: systemctl poweroff //alternative requiring admin: sudo shutdown -h 1
- Sleep: systemctl suspend //alternative requiring admin: sudo pm-suspend
- Log off: gnome-session-quit --no-prompt
- //alternative requiring admin: sudo killall Xorg
- //alternative without admin: dbus-send --session --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1
+ Shut down: systemctl poweroff //alternative requiring admin: sudo shutdown -h 1
+ Sleep: systemctl suspend //alternative requiring admin: sudo pm-suspend
+ Log off: gnome-session-quit --no-prompt
+ //alternative requiring admin: sudo killall Xorg
+ //alternative without admin: dbus-send --session --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1
#elif defined ZEN_MAC
- Shut down: osascript -e 'tell application "System Events" to shut down'
- Sleep: osascript -e 'tell application "System Events" to sleep'
- Log off: osascript -e 'tell application "System Events" to log out'
+ Shut down: osascript -e 'tell application "System Events" to shut down'
+ Sleep: osascript -e 'tell application "System Events" to sleep'
+ Log off: osascript -e 'tell application "System Events" to log out'
#endif
*/
diff --git a/zen/shutdown.h b/zen/shutdown.h
index e64dee41..b9d47df6 100755
--- a/zen/shutdown.h
+++ b/zen/shutdown.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/stl_tools.h b/zen/stl_tools.h
index 2fcecd11..ba4a6c89 100755
--- a/zen/stl_tools.h
+++ b/zen/stl_tools.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/string_base.h b/zen/string_base.h
index cb7ced20..30699c38 100755
--- a/zen/string_base.h
+++ b/zen/string_base.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/string_tools.h b/zen/string_tools.h
index 0a24ab2a..5058f78d 100755
--- a/zen/string_tools.h
+++ b/zen/string_tools.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/string_traits.h b/zen/string_traits.h
index f17e5e0d..502250c2 100755
--- a/zen/string_traits.h
+++ b/zen/string_traits.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/symlink_target.h b/zen/symlink_target.h
index 6ff7f327..2393013e 100755
--- a/zen/symlink_target.h
+++ b/zen/symlink_target.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/sys_error.cpp b/zen/sys_error.cpp
index fd4c8f1e..2acaca1d 100755
--- a/zen/sys_error.cpp
+++ b/zen/sys_error.cpp
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/sys_error.h b/zen/sys_error.h
index f4361e69..31eb8209 100755
--- a/zen/sys_error.h
+++ b/zen/sys_error.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/thread.h b/zen/thread.h
index 85e64493..0bff5adc 100755
--- a/zen/thread.h
+++ b/zen/thread.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/time.h b/zen/time.h
index 2ac67399..67156b9a 100755
--- a/zen/time.h
+++ b/zen/time.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/type_tools.h b/zen/type_tools.h
index d0a62ea2..a705d9bd 100755
--- a/zen/type_tools.h
+++ b/zen/type_tools.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/type_traits.h b/zen/type_traits.h
index 917b3258..f0f96b43 100755
--- a/zen/type_traits.h
+++ b/zen/type_traits.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/utf.h b/zen/utf.h
index bc1e3270..820148c6 100755
--- a/zen/utf.h
+++ b/zen/utf.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/warn_static.h b/zen/warn_static.h
index c2232f74..5b9a4fee 100755
--- a/zen/warn_static.h
+++ b/zen/warn_static.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/xml_io.cpp b/zen/xml_io.cpp
index 8192d6e6..a618f27c 100755
--- a/zen/xml_io.cpp
+++ b/zen/xml_io.cpp
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/xml_io.h b/zen/xml_io.h
index 6c2fc720..8d3346c6 100755
--- a/zen/xml_io.h
+++ b/zen/xml_io.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
diff --git a/zen/zstring.cpp b/zen/zstring.cpp
index fb62424a..2aa3b3f2 100755
--- a/zen/zstring.cpp
+++ b/zen/zstring.cpp
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
@@ -75,11 +75,11 @@ int cmpStringNaturalLinux(const char* lhs, size_t lhsLen, const char* rhs, size_
- implement strict weak ordering!
- don't follow broken "strnatcasecmp": https://github.com/php/php-src/blob/master/ext/standard/strnatcmp.c
1. incorrect non-ASCII CI-comparison
- 2. incorrect bounds checks
+ 2. incorrect bounds checks
3. incorrect trimming of *all* whitespace
- 4. arbitrary handling of leading 0 only at string begin
+ 4. arbitrary handling of leading 0 only at string begin
5. incorrect handling of whitespace following a number
- 6. code is a mess
+ 6. code is a mess
*/
for (;;)
{
diff --git a/zen/zstring.h b/zen/zstring.h
index 33f48990..2a4a549e 100755
--- a/zen/zstring.h
+++ b/zen/zstring.h
@@ -1,6 +1,6 @@
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
bgstack15