-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.cpp
44 lines (36 loc) · 1.24 KB
/
simple.cpp
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
#include <fstream>
#include <iostream>
#include <win_handle_getter.h>
// Adapted from https://stackoverflow.com/a/874160
inline bool ends_with(
const std::wstring &full_string, const std::wstring &ending)
{
if (full_string.length() >= ending.length()) {
const auto comp_res = full_string.compare(
full_string.size() - ending.size(), ending.size(), ending);
return comp_res == 0;
} else {
return false;
}
}
int main()
{
// Note that this should also work with SMB shares! Try it via e.g.
// constexpr wchar_t fname[] = L"\\\\localhost\\C$\\Users\\colin\\file.txt";
constexpr wchar_t fname[] = L"file.txt";
const auto initial_paths = get_cur_proc_handle_paths();
// file.txt shouldn't show up as open
std::wcout << L"BEFORE OPENING FILE" << std::endl;
for (const auto &path : initial_paths) {
std::wcout << path << std::endl;
}
// Open a file so we can see its handle in the list
std::ofstream st(fname);
const auto final_paths = get_cur_proc_handle_paths();
// file.txt should now show up as open
std::wcout << L"AFTER OPENING FILE" << std::endl;
for (const auto &path : final_paths) {
std::wcout << path << std::endl;
}
return 0;
}