summaryrefslogtreecommitdiff
path: root/zen/file_id_internal.h
blob: 492d84326d0d3901e7a355810dd3471c6be99aad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 <string>

#ifdef FFS_WIN
#include "win.h" //includes "windows.h"

#elif defined FFS_LINUX
#include <sys/stat.h>
#endif

namespace
{
template <class T> inline
std::string numberToBytes(T number)
{
    const char* rawBegin = reinterpret_cast<const char*>(&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
bgstack15