forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissamefilesystemitem.cpp
More file actions
48 lines (42 loc) · 1.24 KB
/
issamefilesystemitem.cpp
File metadata and controls
48 lines (42 loc) · 1.24 KB
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
//! @file issamefilesystemitem.cpp
//! @author Jeff Bienstadt <v-jebien@microsoft.com>
//! @brief Determines whether two paths ultimately point to the same filesystem object
#include "getstat.h"
#include "issamefilesystemitem.h"
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
//! @brief Returns a boolean value indicating whether two paths ultimately refer to the same file or directory.
//!
//! IsSameFileSystemItem
//!
//! @param[in] path_one
//! @parblock
//! A pointer to the buffer that contains the first path.
//!
//! char* is marshaled as an LPStr, which on Linux is UTF-8.
//! @endparblock
//!
//! @param[in] path_two
//! @parblock
//! A pointer to the buffer that contains the second path.
//!
//! char* is marshaled as an LPStr, which on Linux is UTF-8.
//! @endparblock
//!
//! @retval true if both paths point to the same filesystem object,
//! false otherwise
//!
bool IsSameFileSystemItem(const char* path_one, const char* path_two)
{
assert(path_one);
assert(path_two);
struct stat buf_1;
struct stat buf_2;
if (GetStat(path_one, &buf_1) == 0 && GetStat(path_two, &buf_2) == 0)
{
return buf_1.st_dev == buf_2.st_dev && buf_1.st_ino == buf_2.st_ino;
}
return false;
}