v30.3-roots.1 · Commit 2: [PATCH 02/68] feat(runtime): preserve Roots operator controls on Core 30.3
src/util/fs.cpp
Before: src/util/fs.cpp · After: src/util/fs.cpp
File metadata
index ec4d551e7881f36a5fe341798496d6cfc05c3551..a90b4f2cb920f4f2cfa74966f8d44570af831c62 100644
Download original patch · Release notes
Diff rows 1–51 of 51. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/util/fs.cpp
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Distributed under the MIT software license, see the accompanying
|
|
3
3
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
4
4
|
|
|
5
|
+
#include <util/check.h>
|
|
5
6
|
#include <util/fs.h>
|
|
6
7
|
#include <util/syserror.h>
|
|
7
8
|
|
|
@@ -13,7 +14,13 @@
|
|
|
13
14
|
#include <unistd.h>
|
|
14
15
|
#else
|
|
15
16
|
#include <codecvt>
|
|
17
|
+
#include <cstring>
|
|
18
|
+
#include <fcntl.h>
|
|
19
|
+
#include <io.h>
|
|
16
20
|
#include <limits>
|
|
21
|
+
#include <locale>
|
|
22
|
+
#include <share.h>
|
|
23
|
+
#include <sys/stat.h>
|
|
17
24
|
#include <windows.h>
|
|
18
25
|
#endif
|
|
19
26
|
|
|
@@ -25,9 +32,22 @@ namespace fsbridge {
|
|
|
25
32
|
|
|
26
33
|
FILE *fopen(const fs::path& p, const char *mode)
|
|
27
34
|
{
|
|
35
|
+
const bool exclusive{strchr(mode, 'x') != nullptr};
|
|
28
36
|
#ifndef WIN32
|
|
37
|
+
Assume((!exclusive) || !strcmp(mode, "wbx"));
|
|
29
38
|
return ::fopen(p.c_str(), mode);
|
|
30
39
|
#else
|
|
40
|
+
if (exclusive) {
|
|
41
|
+
Assert(!strcmp(mode, "wbx"));
|
|
42
|
+
int fd;
|
|
43
|
+
if (::_wsopen_s(&fd, p.wstring().c_str(), _O_WRONLY | _O_CREAT | _O_EXCL | _O_BINARY, _SH_DENYNO, _S_IREAD | _S_IWRITE)) {
|
|
44
|
+
return nullptr;
|
|
45
|
+
}
|
|
46
|
+
FILE* fp = ::_fdopen(fd, "wb");
|
|
47
|
+
if (!fp) ::_close(fd);
|
|
48
|
+
return fp;
|
|
49
|
+
}
|
|
50
|
+
|
|
31
51
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t> utf8_cvt;
|
|
32
52
|
return ::_wfopen(p.wstring().c_str(), utf8_cvt.from_bytes(mode).c_str());
|
|
33
53
|
#endif
|
|
@@ -115,4 +135,9 @@ bool FileLock::TryLock()
|
|
|
115
135
|
}
|
|
116
136
|
#endif
|
|
117
137
|
|
|
138
|
+
std::string get_filesystem_error_message(const fs::filesystem_error& e)
|
|
139
|
+
{
|
|
140
|
+
return e.code().message();
|
|
141
|
+
}
|
|
142
|
+
|
|
118
143
|
} // namespace fsbridge
|