Skip to content

Commit ea81492

Browse files
committed
fix warnings on windows
1 parent e030186 commit ea81492

File tree

8 files changed

+82
-34
lines changed

8 files changed

+82
-34
lines changed

cpp-terminal/iostream_initializer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
#include <iostream>
2020
std::size_t Term::IOStreamInitializer::m_counter{0};
2121

22+
#ifdef _WIN32
23+
#pragma warning( push )
24+
#pragma warning( disable : 4297)
25+
#endif
26+
2227
Term::IOStreamInitializer::IOStreamInitializer() noexcept
2328
try
2429
{
@@ -55,3 +60,7 @@ catch(...)
5560
{
5661
ExceptionHandler(Private::ExceptionDestination::StdErr);
5762
}
63+
64+
#ifdef _WIN32
65+
#pragma warning( pop )
66+
#endif

cpp-terminal/private/args.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma warning( push )
1818
#pragma warning( disable : 4668)
1919
#include <windows.h>
20+
#pragma warning( pop )
2021
#include <processenv.h>
2122
#include "cpp-terminal/private/unicode.hpp"
2223
// clang-format on

cpp-terminal/private/exception.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ Term::Private::ErrnoException::ErrnoException(const std::int64_t& error, const s
156156
setContext(context);
157157
#if defined(_WIN32)
158158
std::wstring message(m_maxSize, L'\0');
159-
message = _wcserror_s(&message[0], message.size(), static_cast<int>(error));
160-
setMessage(Term::Private::to_narrow(message.c_str()));
159+
const errno_t result = _wcserror_s(&message[0], message.size(), static_cast<int>(error));
160+
if(result==0) setMessage(Term::Private::to_narrow(message.c_str()));
161+
else setMessage("_wcserror_s failed");
161162
#else
162163
std::string message(m_maxSize, '\0');
163164
message = ::strerror_r(static_cast<std::int32_t>(error), &message[0], message.size()); // NOLINT(readability-container-data-pointer)

cpp-terminal/private/file.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ Term::Private::OutputFileHandler& Term::Private::out = reinterpret_cast<Term::Pr
4545

4646
//
4747

48+
#ifdef _WIN32
49+
#pragma warning( push )
50+
#pragma warning( disable : 4297)
51+
#endif
52+
4853
Term::Private::FileHandler::FileHandler(std::recursive_mutex& mutex, const std::string& file, const std::string& mode) noexcept
4954
try : m_mutex(mutex)
5055
{
@@ -90,6 +95,30 @@ catch(...)
9095
ExceptionHandler(ExceptionDestination::StdErr);
9196
}
9297

98+
Term::Private::OutputFileHandler::OutputFileHandler(std::recursive_mutex& io_mutex) noexcept
99+
try : FileHandler(io_mutex, m_file, "w")
100+
{
101+
//noop
102+
}
103+
catch(...)
104+
{
105+
ExceptionHandler(ExceptionDestination::StdErr);
106+
}
107+
108+
Term::Private::InputFileHandler::InputFileHandler(std::recursive_mutex& io_mutex) noexcept
109+
try : FileHandler(io_mutex, m_file, "r")
110+
{
111+
//noop
112+
}
113+
catch(...)
114+
{
115+
ExceptionHandler(ExceptionDestination::StdErr);
116+
}
117+
118+
#ifdef _WIN32
119+
#pragma warning( pop )
120+
#endif
121+
93122
bool Term::Private::FileHandler::null() const noexcept { return m_null; }
94123

95124
std::FILE* Term::Private::FileHandler::file() const noexcept { return m_file; }
@@ -159,26 +188,6 @@ void Term::Private::FileHandler::flush() { Term::Private::Errno().check_if(0 !=
159188
void Term::Private::FileHandler::lockIO() { m_mutex.lock(); }
160189
void Term::Private::FileHandler::unlockIO() { m_mutex.unlock(); }
161190

162-
Term::Private::OutputFileHandler::OutputFileHandler(std::recursive_mutex& io_mutex) noexcept
163-
try : FileHandler(io_mutex, m_file, "w")
164-
{
165-
//noop
166-
}
167-
catch(...)
168-
{
169-
ExceptionHandler(ExceptionDestination::StdErr);
170-
}
171-
172-
Term::Private::InputFileHandler::InputFileHandler(std::recursive_mutex& io_mutex) noexcept
173-
try : FileHandler(io_mutex, m_file, "r")
174-
{
175-
//noop
176-
}
177-
catch(...)
178-
{
179-
ExceptionHandler(ExceptionDestination::StdErr);
180-
}
181-
182191
std::string Term::Private::ask(const std::string& str)
183192
{
184193
Term::Private::out.write(str);

cpp-terminal/private/file_initializer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ catch(...)
7171
ExceptionHandler(ExceptionDestination::MessageBox);
7272
}
7373

74+
#ifdef _WIN32
75+
#pragma warning( push )
76+
#pragma warning( disable : 4297)
77+
#endif
78+
7479
Term::Private::FileInitializer::FileInitializer() noexcept
7580
try
7681
{
@@ -106,6 +111,10 @@ catch(...)
106111
ExceptionHandler(ExceptionDestination::StdErr);
107112
}
108113

114+
#ifdef _WIN32
115+
#pragma warning( pop )
116+
#endif
117+
109118
void Term::Private::FileInitializer::openStandardStreams() noexcept
110119
try
111120
{

cpp-terminal/private/signals.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
*/
99

1010
#include "cpp-terminal/private/signals.hpp"
11-
1211
#include "cpp-terminal/terminal_impl.hpp"
13-
#include "signals.hpp"
1412

1513
#include <algorithm>
1614
#include <csignal>
@@ -20,7 +18,10 @@
2018
#endif
2119

2220
#ifdef _WIN32
21+
#pragma warning( push )
22+
#pragma warning( disable : 4668)
2323
#include <windows.h>
24+
#pragma warning( pop )
2425
static BOOL WINAPI consoleHandler(DWORD signal)
2526
{
2627
switch(signal)

cpp-terminal/terminal_impl.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ std::string Term::Terminal::clear() const noexcept { return "\u001b[3J"; }
2020

2121
Term::Options Term::Terminal::getOptions() const noexcept { return m_options; }
2222

23+
#ifdef _WIN32
24+
#pragma warning( push )
25+
#pragma warning( disable : 4297)
26+
#endif
27+
2328
Term::Terminal::Terminal() noexcept
2429
try
2530
{
@@ -32,16 +37,6 @@ catch(...)
3237
ExceptionHandler(Private::ExceptionDestination::StdErr);
3338
}
3439

35-
void Term::Terminal::clean()
36-
{
37-
unsetFocusEvents();
38-
unsetMouseEvents();
39-
if(getOptions().has(Option::NoCursor)) { Term::Private::out.write(cursor_on()); }
40-
if(getOptions().has(Option::ClearScreen)) { Term::Private::out.write(clear() + style(Style::Reset) + cursor_move(1, 1) + screen_load()); }
41-
set_unset_utf8();
42-
store_and_restore();
43-
}
44-
4540
Term::Terminal::~Terminal() noexcept
4641
try
4742
{
@@ -52,6 +47,20 @@ catch(...)
5247
ExceptionHandler(Private::ExceptionDestination::StdErr);
5348
}
5449

50+
#ifdef _WIN32
51+
#pragma warning( pop )
52+
#endif
53+
54+
void Term::Terminal::clean()
55+
{
56+
unsetFocusEvents();
57+
unsetMouseEvents();
58+
if(getOptions().has(Option::NoCursor)) { Term::Private::out.write(cursor_on()); }
59+
if(getOptions().has(Option::ClearScreen)) { Term::Private::out.write(clear() + style(Style::Reset) + cursor_move(1, 1) + screen_load()); }
60+
set_unset_utf8();
61+
store_and_restore();
62+
}
63+
5564
void Term::Terminal::applyOptions() const
5665
{
5766
if(getOptions().has(Option::ClearScreen)) { Term::Private::out.write(screen_save() + clear() + style(Style::Reset) + cursor_move(1, 1)); }

cpp-terminal/terminal_initializer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
std::size_t Term::TerminalInitializer::m_counter{0};
2121

22+
#ifdef _WIN32
23+
#pragma warning( push )
24+
#pragma warning( disable : 4297)
25+
#endif
26+
2227
Term::TerminalInitializer::TerminalInitializer() noexcept
2328
try
2429
{
@@ -47,3 +52,7 @@ catch(...)
4752
{
4853
ExceptionHandler(Private::ExceptionDestination::StdErr);
4954
}
55+
56+
#ifdef _WIN32
57+
#pragma warning( pop )
58+
#endif

0 commit comments

Comments
 (0)