Skip to content

Commit 243f941

Browse files
authored
Don't fail file open/writes silently (#880)
1 parent 7ec62b7 commit 243f941

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

cppwinrt/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "component_writers.h"
99
#include "file_writers.h"
1010
#include "type_writers.h"
11+
#include <winternl.h>
1112

1213
namespace cppwinrt
1314
{
@@ -374,5 +375,7 @@ Where <spec> is one or more of:
374375

375376
int main(int const argc, char** argv)
376377
{
378+
// Dynamically enable long path support
379+
((unsigned char*)(NtCurrentTeb()->ProcessEnvironmentBlock))[3] |= 0x80;
377380
return cppwinrt::run(argc, argv);
378381
}

cppwinrt/text_writer.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,18 @@ namespace cppwinrt
157157
{
158158
if (!file_equal(filename))
159159
{
160-
std::ofstream file{ filename, std::ios::out | std::ios::binary };
161-
file.write(m_first.data(), m_first.size());
162-
file.write(m_second.data(), m_second.size());
160+
std::ofstream file;
161+
file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
162+
try
163+
{
164+
file.open(filename, std::ios::out | std::ios::binary);
165+
file.write(m_first.data(), m_first.size());
166+
file.write(m_second.data(), m_second.size());
167+
}
168+
catch (std::ofstream::failure const& e)
169+
{
170+
throw std::filesystem::filesystem_error(e.what(), filename, std::io_errc::stream);
171+
}
163172
}
164173
m_first.clear();
165174
m_second.clear();

0 commit comments

Comments
 (0)