mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
refactor: replace some C idioms with C++ ones (#5656)
* tidy up legecy practices * remove undefined std::ignore usage * avoid extra function stack level in daemon.cc
This commit is contained in:
@@ -3,15 +3,15 @@
|
||||
// or any future license endorsed by Mnemosyne LLC.
|
||||
// License text can be found in the licenses/ folder.
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <cassert>
|
||||
#include <cerrno>
|
||||
#include <pthread.h>
|
||||
#ifdef HAVE_SYS_SIGNALFD_H
|
||||
#include <sys/signalfd.h>
|
||||
#endif /* signalfd API */
|
||||
#include <event2/event.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h> /* abort(), daemon(), exit() */
|
||||
#include <csignal>
|
||||
#include <cstdlib> /* abort(), daemon(), exit() */
|
||||
#include <fcntl.h> /* open() */
|
||||
#include <unistd.h> /* fork(), setsid(), chdir(), dup2(), close(), pipe() */
|
||||
|
||||
|
||||
@@ -39,15 +39,9 @@
|
||||
|
||||
#else
|
||||
|
||||
static void sd_notify(int /*status*/, char const* /*str*/)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
static void sd_notifyf(int /*status*/, char const* /*fmt*/, ...)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
// no-op
|
||||
#define sd_notify(status, str)
|
||||
#define sd_notifyf(status, fmt, ...)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -695,7 +689,7 @@ int tr_daemon::start([[maybe_unused]] bool foreground)
|
||||
/* setup event state */
|
||||
ev_base_ = event_base_new();
|
||||
|
||||
if (ev_base_ == nullptr || setup_signals() == false)
|
||||
if (ev_base_ == nullptr || !setup_signals())
|
||||
{
|
||||
auto const error_code = errno;
|
||||
auto const errmsg = fmt::format(
|
||||
|
||||
@@ -584,8 +584,8 @@ void Application::Impl::on_startup()
|
||||
css_provider,
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
std::ignore = FilterBar();
|
||||
std::ignore = PathButton();
|
||||
FilterBar();
|
||||
PathButton();
|
||||
|
||||
tr_session* session = nullptr;
|
||||
|
||||
|
||||
@@ -82,8 +82,8 @@ enum tr_encryption_mode
|
||||
TR_ENCRYPTION_REQUIRED
|
||||
};
|
||||
|
||||
#define TR_RATIO_NA -1
|
||||
#define TR_RATIO_INF -2
|
||||
#define TR_RATIO_NA (-1)
|
||||
#define TR_RATIO_INF (-2)
|
||||
|
||||
// --- Startup & Shutdown
|
||||
|
||||
|
||||
@@ -66,10 +66,10 @@ void tr_locale_set_global(char const* locale_name) noexcept
|
||||
{
|
||||
try
|
||||
{
|
||||
std::ignore = std::locale::global(std::locale{ locale_name });
|
||||
std::locale::global(std::locale{ locale_name });
|
||||
|
||||
std::ignore = std::cout.imbue(std::locale{});
|
||||
std::ignore = std::cerr.imbue(std::locale{});
|
||||
std::cout.imbue(std::locale{});
|
||||
std::cerr.imbue(std::locale{});
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
@@ -274,7 +274,7 @@ double tr_getRatio(uint64_t numerator, uint64_t denominator)
|
||||
{
|
||||
if (denominator > 0)
|
||||
{
|
||||
return numerator / (double)denominator;
|
||||
return numerator / static_cast<double>(denominator);
|
||||
}
|
||||
|
||||
if (numerator > 0)
|
||||
@@ -717,7 +717,7 @@ char* formatter_get_size_str(formatter_units const& u, char* buf, uint64_t bytes
|
||||
unit = &u[3];
|
||||
}
|
||||
|
||||
double const value = double(bytes) / unit->value;
|
||||
double const value = static_cast<double>(bytes) / unit->value;
|
||||
auto const* const units = std::data(unit->name);
|
||||
|
||||
auto precision = int{};
|
||||
|
||||
@@ -39,7 +39,7 @@ protected:
|
||||
{
|
||||
if (old_locale_)
|
||||
{
|
||||
std::ignore = std::locale::global(*old_locale_);
|
||||
std::locale::global(*old_locale_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user