diff options
Diffstat (limited to 'zen')
47 files changed, 414 insertions, 386 deletions
diff --git a/zen/basic_math.h b/zen/basic_math.h index a15d811a..4dc9b43b 100644 --- a/zen/basic_math.h +++ b/zen/basic_math.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef BASIC_MATH_H_3472639843265675 #define BASIC_MATH_H_3472639843265675 diff --git a/zen/build_info.h b/zen/build_info.h index c430a49a..31c1d456 100644 --- a/zen/build_info.h +++ b/zen/build_info.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef BUILD_INFO_H_5928539285603428657 #define BUILD_INFO_H_5928539285603428657 @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef CRC_H_23489275827847235 #define CRC_H_23489275827847235 diff --git a/zen/deprecate.h b/zen/deprecate.h index 5cac14c3..04bac442 100644 --- a/zen/deprecate.h +++ b/zen/deprecate.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef DEPRECATE_H_234897087787348 #define DEPRECATE_H_234897087787348 diff --git a/zen/dir_watcher.cpp b/zen/dir_watcher.cpp index 00b48b4f..0c55a963 100644 --- a/zen/dir_watcher.cpp +++ b/zen/dir_watcher.cpp @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #include "dir_watcher.h" #include <algorithm> @@ -130,7 +130,7 @@ public: } private: - typedef Zbase<wchar_t> BasicWString; //thread safe string class for UI texts + using BasicWString = Zbase<wchar_t>; //thread safe string class for UI texts std::mutex lockAccess; std::vector<DirWatcher::Entry> changedFiles; @@ -438,7 +438,7 @@ DirWatcher::DirWatcher(const Zstring& dirPath) : //throw FileError const ErrorCode ec = getLastError(); //copy before directly/indirectly making other system calls! if (ec == ENOSPC) //fix misleading system message "No space left on device" throw FileError(replaceCpy(_("Cannot monitor directory %x."), L"%x", fmtPath(subDirPath)), - formatSystemError(L"inotify_add_watch", ec, L"The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource.")); + formatSystemError(L"inotify_add_watch", numberTo<std::wstring>(ec), L"The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource.")); throw FileError(replaceCpy(_("Cannot monitor directory %x."), L"%x", fmtPath(subDirPath)), formatSystemError(L"inotify_add_watch", ec)); } diff --git a/zen/dir_watcher.h b/zen/dir_watcher.h index eb0bd695..28396ae3 100644 --- a/zen/dir_watcher.h +++ b/zen/dir_watcher.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef DIR_WATCHER_348577025748023458 #define DIR_WATCHER_348577025748023458 diff --git a/zen/error_log.h b/zen/error_log.h index d282ea4b..5d188e9d 100644 --- a/zen/error_log.h +++ b/zen/error_log.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef ERROR_LOG_H_8917590832147915 #define ERROR_LOG_H_8917590832147915 @@ -26,7 +26,7 @@ enum MessageType TYPE_FATAL_ERROR = 0x8, }; -typedef Zbase<wchar_t> MsgString; //std::wstring may employ small string optimization: we cannot accept bloating the "ErrorLog::entries" memory block below (think 1 million items) +using MsgString = Zbase<wchar_t>; //std::wstring may employ small string optimization: we cannot accept bloating the "ErrorLog::entries" memory block below (think 1 million items) struct LogEntry { @@ -48,7 +48,7 @@ public: int getItemCount(int typeFilter = TYPE_INFO | TYPE_WARNING | TYPE_ERROR | TYPE_FATAL_ERROR) const; //subset of std::vector<> interface: - typedef std::vector<LogEntry>::const_iterator const_iterator; + using const_iterator = std::vector<LogEntry>::const_iterator; const_iterator begin() const { return entries.begin(); } const_iterator end () const { return entries.end (); } bool empty() const { return entries.empty(); } diff --git a/zen/file_access.cpp b/zen/file_access.cpp index c2072a26..d8a1f3b7 100644 --- a/zen/file_access.cpp +++ b/zen/file_access.cpp @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #include "file_access.h" #include <map> @@ -810,7 +810,7 @@ void setFileTimeByHandle(HANDLE hFile, //throw FileError } -void setWriteTimeNative(const Zstring& filePath, +void setWriteTimeNative(const Zstring& itemPath, const FILETIME& lastWriteTime, const FILETIME* creationTime, //optional ProcSymlink procSl) //throw FileError @@ -839,21 +839,21 @@ void setWriteTimeNative(const Zstring& filePath, DWORD attribs = INVALID_FILE_ATTRIBUTES; ZEN_ON_SCOPE_EXIT( if (attribs != INVALID_FILE_ATTRIBUTES) - ::SetFileAttributes(applyLongPathPrefix(filePath).c_str(), attribs); + ::SetFileAttributes(applyLongPathPrefix(itemPath).c_str(), attribs); ); auto removeReadonly = [&]() -> bool //throw FileError; may need to remove the readonly-attribute (e.g. on FAT usb drives) { if (attribs == INVALID_FILE_ATTRIBUTES) { - const DWORD tmpAttr = ::GetFileAttributes(applyLongPathPrefix(filePath).c_str()); + const DWORD tmpAttr = ::GetFileAttributes(applyLongPathPrefix(itemPath).c_str()); if (tmpAttr == INVALID_FILE_ATTRIBUTES) - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot read file attributes of %x."), L"%x", fmtPath(filePath)), L"GetFileAttributes"); + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot read file attributes of %x."), L"%x", fmtPath(itemPath)), L"GetFileAttributes"); if (tmpAttr & FILE_ATTRIBUTE_READONLY) { - if (!::SetFileAttributes(applyLongPathPrefix(filePath).c_str(), FILE_ATTRIBUTE_NORMAL)) - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write file attributes of %x."), L"%x", fmtPath(filePath)), L"SetFileAttributes"); + if (!::SetFileAttributes(applyLongPathPrefix(itemPath).c_str(), FILE_ATTRIBUTE_NORMAL)) + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write file attributes of %x."), L"%x", fmtPath(itemPath)), L"SetFileAttributes"); attribs = tmpAttr; //reapplied on scope exit return true; @@ -864,7 +864,7 @@ void setWriteTimeNative(const Zstring& filePath, auto openFile = [&](bool conservativeApproach) { - return ::CreateFile(applyLongPathPrefix(filePath).c_str(), //_In_ LPCTSTR lpFileName, + return ::CreateFile(applyLongPathPrefix(itemPath).c_str(), //_In_ LPCTSTR lpFileName, (conservativeApproach ? //some NAS seem to have issues with FILE_WRITE_ATTRIBUTES, even worse, they may fail silently! //http://sourceforge.net/tracker/?func=detail&atid=1093081&aid=3536680&group_id=234430 @@ -906,20 +906,20 @@ void setWriteTimeNative(const Zstring& filePath, continue; //3. after these herculean stunts we give up... - throw FileError(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(filePath)), formatSystemError(L"CreateFile", ec)); + throw FileError(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(itemPath)), formatSystemError(L"CreateFile", ec)); } } break; } ZEN_ON_SCOPE_EXIT(::CloseHandle(hFile)); - setFileTimeByHandle(hFile, creationTime, lastWriteTime, filePath); //throw FileError + setFileTimeByHandle(hFile, creationTime, lastWriteTime, itemPath); //throw FileError } #ifndef NDEBUG //verify written data FILETIME creationTimeDbg = {}; FILETIME lastWriteTimeDbg = {}; - HANDLE hFile = ::CreateFile(applyLongPathPrefix(filePath).c_str(), //_In_ LPCTSTR lpFileName, + HANDLE hFile = ::CreateFile(applyLongPathPrefix(itemPath).c_str(), //_In_ LPCTSTR lpFileName, FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, //_In_ DWORD dwDesiredAccess, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, //_In_ DWORD dwShareMode, nullptr, //_In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, @@ -942,26 +942,7 @@ void setWriteTimeNative(const Zstring& filePath, #elif defined ZEN_LINUX -void setWriteTimeFallback(const Zstring& filePath, std::int64_t modTime, ProcSymlink procSl) //throw FileError -{ - struct ::timeval writeTime[2] = {}; - writeTime[0].tv_sec = ::time(nullptr); //access time (seconds) - writeTime[1].tv_sec = modTime; //modification time (seconds) - - if (procSl == ProcSymlink::FOLLOW) - { - if (::utimes(filePath.c_str(), writeTime) != 0) - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(filePath)), L"utimes"); - } - else - { - if (::lutimes(filePath.c_str(), writeTime) != 0) - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(filePath)), L"lutimes"); - } -} - - -void setWriteTimeNative(const Zstring& filePath, std::int64_t modTime, ProcSymlink procSl) //throw FileError +void setWriteTimeNative(const Zstring& itemPath, const struct ::timespec& modTime, ProcSymlink procSl) //throw FileError { /* [2013-05-01] sigh, we can't use utimensat() on NTFS volumes on Ubuntu: silent failure!!! what morons are programming this shit??? @@ -970,36 +951,33 @@ void setWriteTimeNative(const Zstring& filePath, std::int64_t modTime, ProcSymli [2015-03-09] - cannot reproduce issues with NTFS and utimensat() on Ubuntu - utimensat() is supposed to obsolete utime/utimes and is also used by "cp" and "touch" - - solves utimes() EINVAL bug for certain CIFS/NTFS drives: http://www.freefilesync.org/forum/viewtopic.php?t=387 - => don't use utimensat() directly, but open file descriptor manually, else EINVAL, again! - - => let's give utimensat another chance: + => let's give utimensat another chance: + 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[1].tv_sec = modTime; //modification time + 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[1] = modTime; //modification time - //=> using open()/futimens() for regular files and utimensat(AT_SYMLINK_NOFOLLOW) for symlinks is consistent with "cp" and "touch"! if (procSl == ProcSymlink::FOLLOW) { - const int fdFile = ::open(filePath.c_str(), O_WRONLY); - if (fdFile == -1) - { - if (errno == EACCES) //bullshit, access denied even with 0777 permissions! => utimes should work! - return setWriteTimeFallback(filePath, modTime, procSl); //throw FileError + //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 + if (::utimensat(AT_FDCWD, itemPath.c_str(), newTimes, 0) == 0) + return; - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(filePath)), L"open"); - } + //in other cases utimensat() returns EINVAL for CIFS/NTFS drives, but open+futimens works: http://www.freefilesync.org/forum/viewtopic.php?t=387 + const int fdFile = ::open(itemPath.c_str(), O_WRONLY); + if (fdFile == -1) + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(itemPath)), L"open"); ZEN_ON_SCOPE_EXIT(::close(fdFile)); if (::futimens(fdFile, newTimes) != 0) - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(filePath)), L"futimens"); + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(itemPath)), L"futimens"); } else { - if (::utimensat(AT_FDCWD, filePath.c_str(), newTimes, AT_SYMLINK_NOFOLLOW) != 0) - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(filePath)), L"utimensat"); + if (::utimensat(AT_FDCWD, itemPath.c_str(), newTimes, AT_SYMLINK_NOFOLLOW) != 0) + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(itemPath)), L"utimensat"); } } @@ -1013,7 +991,7 @@ struct AttrBufFileTimes } __attribute__((aligned(4), packed)); -void setWriteTimeNative(const Zstring& filePath, +void setWriteTimeNative(const Zstring& itemPath, const struct ::timespec& writeTime, const struct ::timespec* createTime, //optional ProcSymlink procSl) //throw FileError @@ -1035,18 +1013,18 @@ void setWriteTimeNative(const Zstring& filePath, attrBuf.writeTime.tv_sec = writeTime.tv_sec; attrBuf.writeTime.tv_nsec = writeTime.tv_nsec; - const int rv = ::setattrlist(filePath.c_str(), //const char* path, + const int rv = ::setattrlist(itemPath.c_str(), //const char* path, &attribs, //struct ::attrlist* attrList, createTime ? &attrBuf.createTime : &attrBuf.writeTime, //void* attrBuf, (createTime ? sizeof(attrBuf.createTime) : 0) + sizeof(attrBuf.writeTime), //size_t attrBufSize, procSl == ProcSymlink::DIRECT ? FSOPT_NOFOLLOW : 0); //unsigned long options if (rv != 0) - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(filePath)), L"setattrlist"); + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot write modification time of %x."), L"%x", fmtPath(itemPath)), L"setattrlist"); } /* void getFileTimeRaw(int fd, //throw FileError - const Zstring& filePath, //for error reporting only + const Zstring& itemPath, //for error reporting only struct ::timespec& createTime, //out struct ::timespec& writeTime) // { @@ -1063,7 +1041,7 @@ void getFileTimeRaw(int fd, //throw FileError sizeof(attrBuf), //size_t attrBufSize, 0); //unsigned long options if (rv != 0) - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot read file attributes of %x."), L"%x", fmtPath(filePath)), L"fgetattrlist"); + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot read file attributes of %x."), L"%x", fmtPath(itemPath)), L"fgetattrlist"); createTime.tv_sec = attrBuf.createTime.tv_sec; createTime.tv_nsec = attrBuf.createTime.tv_nsec; @@ -1111,7 +1089,9 @@ void zen::setFileTime(const Zstring& filePath, std::int64_t modTime, ProcSymlink setWriteTimeNative(filePath, timetToFileTime(modTime), nullptr, procSl); //throw FileError #elif defined ZEN_LINUX - setWriteTimeNative(filePath, modTime, procSl); //throw FileError + struct ::timespec writeTime = {}; + writeTime.tv_sec = modTime; + setWriteTimeNative(filePath, writeTime, procSl); //throw FileError #elif defined ZEN_MAC struct ::timespec writeTime = {}; @@ -1217,15 +1197,15 @@ void copyItemPermissions(const Zstring& sourcePath, const Zstring& targetPath, P try { //enable privilege: required to read/write SACL information (only) - activatePrivilege(SE_SECURITY_NAME); //throw FileError + activatePrivilege(PrivilegeName::SECURITY); //throw FileError //Note: trying to copy SACL (SACL_SECURITY_INFORMATION) may return ERROR_PRIVILEGE_NOT_HELD (1314) on Samba shares. This is not due to missing privileges! //However, this is okay, since copying NTFS permissions doesn't make sense in this case anyway //the following privilege may be required according to https://msdn.microsoft.com/en-us/library/aa364399 (although not needed nor active in my tests) - activatePrivilege(SE_BACKUP_NAME); //throw FileError + activatePrivilege(PrivilegeName::BACKUP); //throw FileError //enable privilege: required to copy owner information - activatePrivilege(SE_RESTORE_NAME); //throw FileError + activatePrivilege(PrivilegeName::RESTORE); //throw FileError } catch (const FileError& e)//add some more context description (e.g. user is not an admin) { @@ -1674,22 +1654,21 @@ void zen::copySymlink(const Zstring& sourceLink, const Zstring& targetLink, bool setWriteTimeNative(targetLink, sourceAttr.ftLastWriteTime, &sourceAttr.ftCreationTime, ProcSymlink::DIRECT); //throw FileError -#elif defined ZEN_LINUX +#else struct ::stat sourceInfo = {}; if (::lstat(sourceLink.c_str(), &sourceInfo) != 0) THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot read file attributes of %x."), L"%x", fmtPath(sourceLink)), L"lstat"); - setWriteTimeNative(targetLink, sourceInfo.st_mtime, ProcSymlink::DIRECT); //throw FileError - +#ifdef ZEN_LINUX + setWriteTimeNative(targetLink, sourceInfo.st_mtim, ProcSymlink::DIRECT); //throw FileError #elif defined ZEN_MAC - struct ::stat sourceInfo = {}; - if (::lstat(sourceLink.c_str(), &sourceInfo) != 0) - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot read file attributes of %x."), L"%x", fmtPath(sourceLink)), L"lstat"); - if (hasNativeSupportForExtendedAtrributes(targetLink)) //throw FileError ::copyfile(sourceLink.c_str(), targetLink.c_str(), nullptr, COPYFILE_XATTR | COPYFILE_NOFOLLOW); //ignore errors, see related comments in copyFileOsSpecific() setWriteTimeNative(targetLink, sourceInfo.st_mtimespec, &sourceInfo.st_birthtimespec, ProcSymlink::DIRECT); //throw FileError +#else +#error WTF +#endif #endif if (copyFilePermissions) @@ -1835,9 +1814,9 @@ InSyncAttributes copyFileWindowsBackupStream(const Zstring& sourceFile, //throw { //try to get backup read and write privileges: help solve most "access denied" errors with FILE_FLAG_BACKUP_SEMANTICS: //http://www.freefilesync.org/forum/viewtopic.php?t=1714 - try { activatePrivilege(SE_BACKUP_NAME); } + try { activatePrivilege(PrivilegeName::BACKUP); } catch (const FileError&) {} - try { activatePrivilege(SE_RESTORE_NAME); } + try { activatePrivilege(PrivilegeName::RESTORE); } catch (const FileError&) {} //open sourceFile for reading @@ -1903,8 +1882,8 @@ InSyncAttributes copyFileWindowsBackupStream(const Zstring& sourceFile, //throw CREATE_NEW, //_In_ DWORD dwCreationDisposition, //FILE_FLAG_OVERLAPPED must not be used! FILE_FLAG_NO_BUFFERING should not be used! (fileInfoSource.dwFileAttributes & validAttribs) | - FILE_FLAG_SEQUENTIAL_SCAN | - FILE_FLAG_BACKUP_SEMANTICS, //_In_ DWORD dwFlagsAndAttributes, + FILE_FLAG_SEQUENTIAL_SCAN | //_In_ DWORD dwFlagsAndAttributes, + FILE_FLAG_BACKUP_SEMANTICS, //-> also required by FSCTL_SET_SPARSE nullptr); //_In_opt_ HANDLE hTemplateFile if (hFileTarget == INVALID_HANDLE_VALUE) { @@ -2186,9 +2165,9 @@ InSyncAttributes copyFileWindowsDefault(const Zstring& sourceFile, //throw FileE { //try to get backup read and write privileges: may help solve some "access denied" errors bool backupPrivilegesActive = true; - try { activatePrivilege(SE_BACKUP_NAME); } + try { activatePrivilege(PrivilegeName::BACKUP); } catch (const FileError&) { backupPrivilegesActive = false; } - try { activatePrivilege(SE_RESTORE_NAME); } + try { activatePrivilege(PrivilegeName::RESTORE); } catch (const FileError&) { backupPrivilegesActive = false; } auto guardTarget = zen::makeGuard<ScopeGuardRunMode::ON_FAIL>([&] { try { removeFile(targetFile); } catch (FileError&) {} }); @@ -2402,7 +2381,7 @@ InSyncAttributes copyFileOsSpecific(const Zstring& sourceFile, //throw FileError //sourceInfo.st_birthtime; -> only seconds-precision //sourceInfo.st_mtime; -> #else - setWriteTimeNative(targetFile, sourceInfo.st_mtime, ProcSymlink::FOLLOW); //throw FileError + setWriteTimeNative(targetFile, sourceInfo.st_mtim, ProcSymlink::FOLLOW); //throw FileError #endif InSyncAttributes newAttrib; @@ -2410,7 +2389,7 @@ InSyncAttributes copyFileOsSpecific(const Zstring& sourceFile, //throw FileError #ifdef ZEN_MAC newAttrib.modificationTime = sourceInfo.st_mtimespec.tv_sec; //use same time variable like setWriteTimeNative() for consistency #else - newAttrib.modificationTime = sourceInfo.st_mtime; + newAttrib.modificationTime = sourceInfo.st_mtim.tv_sec; // #endif newAttrib.sourceFileId = extractFileId(sourceInfo); newAttrib.targetFileId = extractFileId(targetInfo); diff --git a/zen/file_access.h b/zen/file_access.h index fb99ce33..fdb787bd 100644 --- a/zen/file_access.h +++ b/zen/file_access.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef FILE_ACCESS_H_8017341345614857 #define FILE_ACCESS_H_8017341345614857 diff --git a/zen/file_error.h b/zen/file_error.h index 61a2e89c..374d0b2c 100644 --- a/zen/file_error.h +++ b/zen/file_error.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef FILE_ERROR_H_839567308565656789 #define FILE_ERROR_H_839567308565656789 diff --git a/zen/file_id_def.h b/zen/file_id_def.h index 2880121c..3eeb79a9 100644 --- a/zen/file_id_def.h +++ b/zen/file_id_def.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef FILE_ID_DEF_H_013287632486321493 #define FILE_ID_DEF_H_013287632486321493 diff --git a/zen/file_io.cpp b/zen/file_io.cpp index d0a1bfa3..6243980b 100644 --- a/zen/file_io.cpp +++ b/zen/file_io.cpp @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #include "file_io.h" #include "file_access.h" @@ -73,7 +73,7 @@ FileInput::FileInput(const Zstring& filepath) : //throw FileError, ErrorFileLock FileBase(filepath), fileHandle(getInvalidHandle()) { #ifdef ZEN_WIN - try { activatePrivilege(SE_BACKUP_NAME); } + try { activatePrivilege(PrivilegeName::BACKUP); } catch (const FileError&) {} auto createHandle = [&](DWORD dwShareMode) @@ -222,9 +222,9 @@ FileOutput::FileOutput(const Zstring& filepath, AccessFlag access) : //throw Fil FileBase(filepath), fileHandle(getInvalidHandle()) { #ifdef ZEN_WIN - try { activatePrivilege(SE_BACKUP_NAME); } + try { activatePrivilege(PrivilegeName::BACKUP); } catch (const FileError&) {} - try { activatePrivilege(SE_RESTORE_NAME); } + try { activatePrivilege(PrivilegeName::RESTORE); } catch (const FileError&) {} const DWORD dwCreationDisposition = access == FileOutput::ACC_OVERWRITE ? CREATE_ALWAYS : CREATE_NEW; diff --git a/zen/file_io.h b/zen/file_io.h index 23296c6c..e6da486d 100644 --- a/zen/file_io.h +++ b/zen/file_io.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef FILE_IO_H_89578342758342572345 #define FILE_IO_H_89578342758342572345 @@ -26,9 +26,9 @@ namespace zen //OS-buffered file IO optimized for sequential read/write accesses + better error reporting + long path support + following symlinks #ifdef ZEN_WIN - typedef HANDLE FileHandle; + using FileHandle = HANDLE; #elif defined ZEN_LINUX || defined ZEN_MAC - typedef int FileHandle; + using FileHandle = int; #endif class FileBase diff --git a/zen/file_traverser.cpp b/zen/file_traverser.cpp index bedc9154..b4599d03 100644 --- a/zen/file_traverser.cpp +++ b/zen/file_traverser.cpp @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #include "file_traverser.h" #include "file_error.h" diff --git a/zen/file_traverser.h b/zen/file_traverser.h index 9f850e01..5fffe0e2 100644 --- a/zen/file_traverser.h +++ b/zen/file_traverser.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef FILER_TRAVERSER_H_127463214871234 #define FILER_TRAVERSER_H_127463214871234 diff --git a/zen/fixed_list.h b/zen/fixed_list.h index 362577d5..dba0996e 100644 --- a/zen/fixed_list.h +++ b/zen/fixed_list.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef FIXED_LIST_H_01238467085684139453534 #define FIXED_LIST_H_01238467085684139453534 @@ -46,11 +46,11 @@ public: NodeT* it_; }; - typedef T value_type; - typedef ListIterator< Node, T> iterator; - typedef ListIterator<const Node, const T> const_iterator; - typedef T& reference; - typedef const T& const_reference; + using value_type = T; + using iterator = ListIterator< Node, T>; + using const_iterator = ListIterator<const Node, const T>; + using reference = T&; + using const_reference = const T&; iterator begin() { return firstInsert; } iterator end () { return iterator(); } diff --git a/zen/format_unit.cpp b/zen/format_unit.cpp index 6a0e1668..c7b2504d 100644 --- a/zen/format_unit.cpp +++ b/zen/format_unit.cpp @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #include "format_unit.h" #include "basic_math.h" diff --git a/zen/format_unit.h b/zen/format_unit.h index fcc42dfa..1f9177f0 100644 --- a/zen/format_unit.h +++ b/zen/format_unit.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef FMT_UNIT_8702184019487324 #define FMT_UNIT_8702184019487324 diff --git a/zen/globals.h b/zen/globals.h new file mode 100644 index 00000000..5f3dd64a --- /dev/null +++ b/zen/globals.h @@ -0,0 +1,57 @@ +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** + +#ifndef GLOBALS_H_8013740213748021573485 +#define GLOBALS_H_8013740213748021573485 + +#include <atomic> +#include <memory> +#include "scope_guard.h" + +namespace zen +{ +//solve static destruction order fiasco by providing scoped ownership and serialized access to global variables +template <class T> +class Global +{ +public: + Global() {} + explicit Global(std::unique_ptr<T>&& newInst) { set(std::move(newInst)); } + ~Global() { set(nullptr); } + + std::shared_ptr<T> get() //=> return std::shared_ptr to let instance life time be handled by caller (MT usage!) + { + while (spinLock.exchange(true)) ; + ZEN_ON_SCOPE_EXIT(spinLock = false); + if (inst) + return *inst; + return nullptr; + } + + void set(std::unique_ptr<T>&& newInst) + { + std::shared_ptr<T>* tmpInst = nullptr; + if (newInst) + tmpInst = new std::shared_ptr<T>(std::move(newInst)); + { + while (spinLock.exchange(true)) ; + ZEN_ON_SCOPE_EXIT(spinLock = false); + std::swap(inst, tmpInst); + } + delete tmpInst; + } + +private: + //avoid static destruction order fiasco: there may be accesses to "Global<T>::get()" during process shutdown + //e.g. show message in debug_minidump.cpp or some detached thread assembling an error message! + //=> use trivially-destructible POD only!!! + std::shared_ptr<T>* inst = nullptr; + //serialize access: can't use std::mutex because of non-trival destructor + std::atomic<bool> spinLock { false }; +}; +} + +#endif //GLOBALS_H_8013740213748021573485 @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef GUID_H_80425780237502345 #define GUID_H_80425780237502345 @@ -1,15 +1,15 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef I18_N_H_3843489325044253425456 #define I18_N_H_3843489325044253425456 #include <string> -#include <memory> #include <cstdint> +#include "globals.h" #include "string_tools.h" #include "format_unit.h" @@ -67,7 +67,6 @@ std::wstring translate(const std::wstring& text) { if (std::shared_ptr<const TranslationHandler> t = getTranslator()) //std::shared_ptr => temporarily take (shared) ownership while using the interface! return t->translate(text); - return text; } @@ -99,55 +98,26 @@ std::wstring translate(const std::wstring& singular, const std::wstring& plural, inline -std::shared_ptr<const TranslationHandler>*& getTranslationInstance() +Global<const TranslationHandler>& refTranslationGlobals() { - //avoid static destruction order fiasco: there may be accesses to "getTranslator()" during process shutdown - //e.g. show message in debug_minidump.cpp or some detached thread assembling an error message! - //=> use POD instead of a plain std::shared_ptr<>!!! - static std::shared_ptr<const TranslationHandler>* inst = nullptr; //external linkage even in header! + //getTranslator() may be called even after static objects of this translation unit are destroyed! + static Global<const TranslationHandler> inst; //external linkage even in header! return inst; } - - -struct CleanUpTranslationHandler -{ - ~CleanUpTranslationHandler() - { - std::shared_ptr<const TranslationHandler>*& handler = getTranslationInstance(); - assert(!handler); //clean up at a better time rather than during static destruction! MT issues! - auto oldHandler = handler; - handler = nullptr; //getTranslator() may be called even after static objects of this translation unit are destroyed! - delete oldHandler; - } -}; } -//setTranslator/getTranslator() operating on a global are obviously racy for MT usage -//=> make them fast to cover the rare case of a language change and the not-so-rare case of language clean-up during shutdown -//=> can't synchronize with std::mutex which is non-POD and again leads to global destruction order fiasco -//=> return std::shared_ptr to let instance life time be handled by caller (MT!) inline void setTranslator(std::unique_ptr<const TranslationHandler>&& newHandler) { - static implementation::CleanUpTranslationHandler cuth; //external linkage even in header! - - std::shared_ptr<const TranslationHandler>*& handler = implementation::getTranslationInstance(); - auto oldHandler = handler; - handler = nullptr; - delete oldHandler; - if (newHandler) - handler = new std::shared_ptr<const TranslationHandler>(std::move(newHandler)); + implementation::refTranslationGlobals().set(std::move(newHandler)); } inline std::shared_ptr<const TranslationHandler> getTranslator() { - std::shared_ptr<const TranslationHandler>*& handler = implementation::getTranslationInstance(); - if (handler) - return *handler; - return nullptr; + return implementation::refTranslationGlobals().get(); } } diff --git a/zen/optional.h b/zen/optional.h index c01d95ff..83915110 100644 --- a/zen/optional.h +++ b/zen/optional.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef OPTIONAL_H_2857428578342203589 #define OPTIONAL_H_2857428578342203589 @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef PERF_H_83947184145342652456 #define PERF_H_83947184145342652456 diff --git a/zen/process_priority.cpp b/zen/process_priority.cpp index 2d1abafa..7ef7bc0f 100644 --- a/zen/process_priority.cpp +++ b/zen/process_priority.cpp @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #include "process_priority.h" #include "i18n.h" diff --git a/zen/process_priority.h b/zen/process_priority.h index 48b95c9e..ce2d0157 100644 --- a/zen/process_priority.h +++ b/zen/process_priority.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef PROCESS_PRIORITY_H_83421759082143245 #define PROCESS_PRIORITY_H_83421759082143245 diff --git a/zen/recycler.cpp b/zen/recycler.cpp index 32ba7cb0..7f9e0a01 100644 --- a/zen/recycler.cpp +++ b/zen/recycler.cpp @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #include "recycler.h" #include "file_access.h" diff --git a/zen/recycler.h b/zen/recycler.h index 4b5658cb..4a5f4b2b 100644 --- a/zen/recycler.h +++ b/zen/recycler.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef RECYCLER_H_18345067341545 #define RECYCLER_H_18345067341545 diff --git a/zen/scope_guard.h b/zen/scope_guard.h index f8c32127..69d4b060 100644 --- a/zen/scope_guard.h +++ b/zen/scope_guard.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef SCOPE_GUARD_H_8971632487321434 #define SCOPE_GUARD_H_8971632487321434 @@ -20,7 +20,7 @@ inline int getUncaughtExceptionCount() { return std::uncaught_exceptions(); } #elif defined ZEN_LINUX || defined ZEN_MAC //std::uncaught_exceptions() currently unsupported on GCC and Clang => clean up ASAP #ifdef ZEN_LINUX - static_assert(__GNUC__ < 5 || (__GNUC__ == 5 && (__GNUC_MINOR__ < 3 || (__GNUC_MINOR__ == 3 && __GNUC_PATCHLEVEL__ <= 1))), "check std::uncaught_exceptions support"); + static_assert(__GNUC__ < 6 || (__GNUC__ == 6 && (__GNUC_MINOR__ < 1 || (__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ <= 1))), "check std::uncaught_exceptions support"); #else static_assert(__clang_major__ < 7 || (__clang_major__ == 7 && __clang_minor__ <= 3), "check std::uncaught_exceptions support"); #endif diff --git a/zen/serialize.h b/zen/serialize.h index aee650e6..bc047fee 100644 --- a/zen/serialize.h +++ b/zen/serialize.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef SERIALIZE_H_839405783574356 #define SERIALIZE_H_839405783574356 @@ -25,16 +25,16 @@ binary container for data storage: must support "basic" std::vector interface (e */ //binary container reference implementations -typedef Zbase<char> Utf8String; //ref-counted + COW text stream + guaranteed performance: exponential growth +using Utf8String = Zbase<char>; //ref-counted + COW text stream + guaranteed performance: exponential growth class ByteArray; //ref-counted byte stream + guaranteed performance: exponential growth -> no COW, but 12% faster than Utf8String (due to no null-termination?) class ByteArray //essentially a std::vector<char> with ref-counted semantics, but no COW! => *almost* value type semantics, but not quite { public: - typedef std::vector<char>::value_type value_type; - typedef std::vector<char>::iterator iterator; - typedef std::vector<char>::const_iterator const_iterator; + using value_type = std::vector<char>::value_type; + using iterator = std::vector<char>::iterator; + using const_iterator = std::vector<char>::const_iterator; iterator begin() { return buffer->begin(); } iterator end () { return buffer->end (); } diff --git a/zen/shell_execute.h b/zen/shell_execute.h index 813de479..5ebdd04d 100644 --- a/zen/shell_execute.h +++ b/zen/shell_execute.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef SHELL_EXECUTE_H_23482134578134134 #define SHELL_EXECUTE_H_23482134578134134 diff --git a/zen/stl_tools.h b/zen/stl_tools.h index 058609e6..07925981 100644 --- a/zen/stl_tools.h +++ b/zen/stl_tools.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef STL_TOOLS_H_84567184321434 #define STL_TOOLS_H_84567184321434 diff --git a/zen/string_base.h b/zen/string_base.h index 365e359e..b54c3b2e 100644 --- a/zen/string_base.h +++ b/zen/string_base.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef STRING_BASE_H_083217454562342526 #define STRING_BASE_H_083217454562342526 @@ -196,7 +196,7 @@ private: { Descriptor(size_t len, size_t cap) : length (static_cast<std::uint32_t>(len)), - capacity(static_cast<std::uint32_t>(cap)) { static_assert(ATOMIC_INT_LOCK_FREE == 2, ""); } //2: "the types are always lock-free" + capacity(static_cast<std::uint32_t>(cap)) { static_assert(ATOMIC_INT_LOCK_FREE == 2, ""); } //2: "The atomic type is always lock-free" std::atomic<unsigned int> refCount { 1 }; //std:atomic is uninitialized by default! std::uint32_t length; @@ -232,11 +232,11 @@ public: //operator const Char* () const; //NO implicit conversion to a C-string!! Many problems... one of them: if we forget to provide operator overloads, it'll just work with a Char*... //STL accessors - typedef Char* iterator; - typedef const Char* const_iterator; - typedef Char& reference; - typedef const Char& const_reference; - typedef Char value_type; + using iterator = Char*; + using const_iterator = const Char*; + using reference = Char&; + using const_reference = const Char&; + using value_type = Char; Zbase(const_iterator first, const_iterator last); Char* begin(); diff --git a/zen/string_tools.h b/zen/string_tools.h index ed6a1a54..3bda665f 100644 --- a/zen/string_tools.h +++ b/zen/string_tools.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef STRING_TOOLS_H_213458973046 #define STRING_TOOLS_H_213458973046 diff --git a/zen/string_traits.h b/zen/string_traits.h index 12701dc3..f17e5e0d 100644 --- a/zen/string_traits.h +++ b/zen/string_traits.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef STRING_TRAITS_H_813274321443234 #define STRING_TRAITS_H_813274321443234 diff --git a/zen/symlink_target.h b/zen/symlink_target.h index 17168a03..e3f526ba 100644 --- a/zen/symlink_target.h +++ b/zen/symlink_target.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef SYMLINK_TARGET_H_801783470198357483 #define SYMLINK_TARGET_H_801783470198357483 @@ -88,7 +88,7 @@ Zstring getSymlinkRawTargetString_impl(const Zstring& linkPath) //throw FileErro //reading certain symlinks/junctions requires admin rights! try - { activatePrivilege(SE_BACKUP_NAME); } //throw FileError + { activatePrivilege(PrivilegeName::BACKUP); } //throw FileError catch (FileError&) {} //This shall not cause an error in user mode! const HANDLE hLink = ::CreateFile(applyLongPathPrefix(linkPath).c_str(), //_In_ LPCTSTR lpFileName, diff --git a/zen/sys_error.h b/zen/sys_error.h index 16e59266..5897b413 100644 --- a/zen/sys_error.h +++ b/zen/sys_error.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef SYS_ERROR_H_3284791347018951324534 #define SYS_ERROR_H_3284791347018951324534 @@ -25,15 +25,15 @@ namespace zen { //evaluate GetLastError()/errno and assemble specific error message #ifdef ZEN_WIN - typedef DWORD ErrorCode; + using ErrorCode = DWORD; #elif defined ZEN_LINUX || defined ZEN_MAC - typedef int ErrorCode; + using ErrorCode = int; #endif ErrorCode getLastError(); std::wstring formatSystemError(const std::wstring& functionName, ErrorCode ec); -std::wstring formatSystemError(const std::wstring& functionName, ErrorCode ec, const std::wstring& errorMsg); +std::wstring formatSystemError(const std::wstring& functionName, const std::wstring& errorCode, const std::wstring& errorMsg); //A low-level exception class giving (non-translated) detail information only - same conceptional level like "GetLastError()"! class SysError @@ -102,13 +102,16 @@ std::wstring formatSystemErrorRaw(ErrorCode ec) //return empty string on error std::wstring formatSystemError(const std::wstring& functionName, long long lastError) = delete; //intentional overload ambiguity to catch usage errors with HRESULT! inline -std::wstring formatSystemError(const std::wstring& functionName, ErrorCode ec) { return formatSystemError(functionName, ec, formatSystemErrorRaw(ec)); } +std::wstring formatSystemError(const std::wstring& functionName, ErrorCode ec) +{ + return formatSystemError(functionName, numberTo<std::wstring>(ec), formatSystemErrorRaw(ec)); +} inline -std::wstring formatSystemError(const std::wstring& functionName, ErrorCode ec, const std::wstring& errorMsg) +std::wstring formatSystemError(const std::wstring& functionName, const std::wstring& errorCode, const std::wstring& errorMsg) { - std::wstring output = replaceCpy(_("Error Code %x:"), L"%x", numberTo<std::wstring>(ec)); + std::wstring output = replaceCpy(_("Error Code %x:"), L"%x", errorCode); if (!errorMsg.empty()) { diff --git a/zen/thread.h b/zen/thread.h index f747f965..fd9dc76d 100644 --- a/zen/thread.h +++ b/zen/thread.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef THREAD_H_7896323423432235246427 #define THREAD_H_7896323423432235246427 @@ -151,7 +151,7 @@ namespace impl template <class Function> inline auto runAsync(Function&& fun, TrueType /*copy-constructible*/) { - typedef decltype(fun()) ResultType; + using ResultType = decltype(fun()); //note: std::packaged_task does NOT support move-only function objects! std::packaged_task<ResultType()> pt(std::forward<Function>(fun)); @@ -334,7 +334,8 @@ private: activeCondition = cv; } - std::atomic<bool> interrupted{ false }; //std:atomic is uninitialized by default! + std::atomic<bool> interrupted{ false }; //std:atomic is uninitialized by default!!! + //"The default constructor is trivial: no initialization takes place other than zero initialization of static and thread-local objects." std::condition_variable* activeCondition = nullptr; std::mutex lockConditionPtr; //serialize pointer access (only!) diff --git a/zen/tick_count.h b/zen/tick_count.h index 89910e14..5ba4fd1b 100644 --- a/zen/tick_count.h +++ b/zen/tick_count.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef TICK_COUNT_H_3807326223463457 #define TICK_COUNT_H_3807326223463457 @@ -42,11 +42,11 @@ class TickVal { public: #ifdef ZEN_WIN - typedef LARGE_INTEGER NativeVal; + using NativeVal = LARGE_INTEGER; #elif defined ZEN_LINUX - typedef timespec NativeVal; + using NativeVal = timespec; #elif defined ZEN_MAC - typedef uint64_t NativeVal; + using NativeVal = uint64_t; #endif TickVal() {} @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef TIME_H_8457092814324342453627 #define TIME_H_8457092814324342453627 @@ -214,7 +214,7 @@ struct PredefinedFormatTag {}; template <class String, class String2> inline String formatTime(const String2& format, const TimeComp& comp, UserDefinedFormatTag) //format as specified by "std::strftime", returns empty string on failure { - typedef typename GetCharType<String>::Type CharType; + using CharType = typename GetCharType<String>::Type; std::tm ctc = toClibTimeComponents(comp); std::mktime(&ctc); // unfortunately std::strftime() needs all elements of "struct tm" filled, e.g. tm_wday, tm_yday //note: although std::mktime() explicitly expects "local time", calculating weekday and day of year *should* be time-zone and DST independent @@ -227,7 +227,7 @@ String formatTime(const String2& format, const TimeComp& comp, UserDefinedFormat template <class String, class FormatType> inline String formatTime(FormatType, const TimeComp& comp, PredefinedFormatTag) { - typedef typename GetCharType<String>::Type CharType; + using CharType = typename GetCharType<String>::Type; return formatTime<String>(GetFormat<FormatType>().format(CharType()), comp, UserDefinedFormatTag()); } } @@ -260,13 +260,13 @@ time_t localToTimeT(const TimeComp& comp) //returns -1 on error template <class String, class String2> inline String formatTime(const String2& format, const TimeComp& comp) { - typedef typename SelectIf< + using FormatTag = typename SelectIf< IsSameType<String2, FormatDateTag >::value || IsSameType<String2, FormatTimeTag >::value || IsSameType<String2, FormatDateTimeTag >::value || IsSameType<String2, FormatIsoDateTag >::value || IsSameType<String2, FormatIsoTimeTag >::value || - IsSameType<String2, FormatIsoDateTimeTag>::value, implementation::PredefinedFormatTag, implementation::UserDefinedFormatTag>::Type FormatTag; + IsSameType<String2, FormatIsoDateTimeTag>::value, implementation::PredefinedFormatTag, implementation::UserDefinedFormatTag>::Type; return implementation::formatTime<String>(format, comp, FormatTag()); } @@ -275,7 +275,7 @@ String formatTime(const String2& format, const TimeComp& comp) template <class String, class String2> bool parseTime(const String& format, const String2& str, TimeComp& comp) //return true on success { - typedef typename GetCharType<String>::Type CharType; + using CharType = typename GetCharType<String>::Type; static_assert(IsSameType<CharType, typename GetCharType<String2>::Type>::value, ""); const CharType* itFmt = strBegin(format); diff --git a/zen/type_tools.h b/zen/type_tools.h index a1e628a1..d0a62ea2 100644 --- a/zen/type_tools.h +++ b/zen/type_tools.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef TYPE_TOOLS_H_45237590734254545 #define TYPE_TOOLS_H_45237590734254545 diff --git a/zen/type_traits.h b/zen/type_traits.h index c0da43ed..917b3258 100644 --- a/zen/type_traits.h +++ b/zen/type_traits.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef TYPE_TRAITS_H_3425628658765467 #define TYPE_TRAITS_H_3425628658765467 @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef UTF_H_01832479146991573473545 #define UTF_H_01832479146991573473545 @@ -19,6 +19,9 @@ TargetString utfCvrtTo(const SourceString& str); const char BYTE_ORDER_MARK_UTF8[] = "\xEF\xBB\xBF"; +template <class CharString> +bool isValidUtf8(const CharString& str); //check for UTF-8 encoding errors + //---- explicit conversion: wide <-> utf8 ---- template <class CharString, class WideString> CharString wideToUtf8(const WideString& str); //example: std::string tmp = wideToUtf8<std::string>(L"abc"); @@ -53,9 +56,9 @@ size_t findUnicodePos(const UtfString& str, size_t unicodePos); //return positio //----------------------- implementation ---------------------------------- namespace implementation { -typedef std::uint32_t CodePoint; -typedef std::uint16_t Char16; -typedef unsigned char Char8; +using CodePoint = std::uint32_t; +using Char16 = std::uint16_t; +using Char8 = unsigned char; const CodePoint LEAD_SURROGATE = 0xd800; const CodePoint TRAIL_SURROGATE = 0xdc00; //== LEAD_SURROGATE_MAX + 1 @@ -413,6 +416,21 @@ CharString wideToUtf8(const WideString& str, Int2Type<4>) //other OS: convert ut } +template <class CharString> inline +bool isValidUtf8(const CharString& str) +{ + using namespace implementation; + bool valid = true; + utf8ToCodePoint(strBegin(str), strBegin(str) + strLength(str), + [&](CodePoint cp) + { + if (cp == REPLACEMENT_CHAR) + valid = false; //perf: should we use an (expensive) exception for iteration break? + }); + return valid; +} + + template <class WideString, class CharString> inline WideString utf8ToWide(const CharString& str) { diff --git a/zen/warn_static.h b/zen/warn_static.h index bba17cb7..44d7bd73 100644 --- a/zen/warn_static.h +++ b/zen/warn_static.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef WARN_STATIC_H_08724567834560832745 #define WARN_STATIC_H_08724567834560832745 diff --git a/zen/xml_io.cpp b/zen/xml_io.cpp index ae69ade4..4b77c851 100644 --- a/zen/xml_io.cpp +++ b/zen/xml_io.cpp @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #include "xml_io.h" #include "file_access.h" diff --git a/zen/xml_io.h b/zen/xml_io.h index 4876ac55..d0492be1 100644 --- a/zen/xml_io.h +++ b/zen/xml_io.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef XML_IO_H_8914759321263879 #define XML_IO_H_8914759321263879 diff --git a/zen/zstring.cpp b/zen/zstring.cpp index 6d249e70..f5732c3f 100644 --- a/zen/zstring.cpp +++ b/zen/zstring.cpp @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #include "zstring.h" #include <stdexcept> diff --git a/zen/zstring.h b/zen/zstring.h index 3a431ea7..792b92db 100644 --- a/zen/zstring.h +++ b/zen/zstring.h @@ -1,8 +1,8 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** #ifndef ZSTRING_H_73425873425789 #define ZSTRING_H_73425873425789 @@ -11,19 +11,19 @@ #ifdef ZEN_WIN //Windows encodes Unicode as UTF-16 wchar_t - typedef wchar_t Zchar; + using Zchar = wchar_t; #define Zstr(x) L ## x const Zchar FILE_NAME_SEPARATOR = L'\\'; #elif defined ZEN_LINUX || defined ZEN_MAC //Linux uses UTF-8 - typedef char Zchar; + using Zchar = char; #define Zstr(x) x const Zchar FILE_NAME_SEPARATOR = '/'; #endif //"The reason for all the fuss above" - Loki/SmartPtr //a high-performance string for interfacing with native OS APIs in multithreaded contexts -typedef zen::Zbase<Zchar, zen::StorageRefCountThreadSafe, zen::AllocatorOptimalSpeed> Zstring; +using Zstring = zen::Zbase<Zchar, zen::StorageRefCountThreadSafe, zen::AllocatorOptimalSpeed>; int cmpStringNoCase(const wchar_t* lhs, size_t lhsLen, const wchar_t* rhs, size_t rhsLen); |