From 8bf668665b107469086f16cb8ad23e47d479d2b4 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:14:37 +0200 Subject: 4.0 --- shared/file_id_internal.h | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 shared/file_id_internal.h (limited to 'shared/file_id_internal.h') diff --git a/shared/file_id_internal.h b/shared/file_id_internal.h new file mode 100644 index 00000000..a8a7042d --- /dev/null +++ b/shared/file_id_internal.h @@ -0,0 +1,48 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// ************************************************************************** + +#ifndef FILE_ID_INTERNAL_HEADER_013287632486321493 +#define FILE_ID_INTERNAL_HEADER_013287632486321493 + +#include + +#ifdef FFS_WIN +#include //includes "windows.h" + +#elif defined FFS_LINUX +#include +#endif + +namespace +{ +template inline +std::string numberToBytes(T number) +{ + const char* rawBegin = reinterpret_cast(&number); + return std::string(rawBegin, rawBegin + sizeof(number)); +} + +#ifdef FFS_WIN +inline +std::string extractFileID(const BY_HANDLE_FILE_INFORMATION& fileInfo) +{ + return numberToBytes(fileInfo.dwVolumeSerialNumber) + + numberToBytes(fileInfo.nFileIndexHigh) + + numberToBytes(fileInfo.nFileIndexLow); +} +#elif defined FFS_LINUX +inline +std::string extractFileID(const struct stat& fileInfo) +{ + return numberToBytes(fileInfo.st_dev) + + numberToBytes(fileInfo.st_ino); +} +#endif + +} + + +#endif //FILE_ID_INTERNAL_HEADER_013287632486321493 -- cgit