build: re-enable cert-err33-c clang-tidy warning (#2968)
* refactor: re-enable cert-err33-c clang-tidy warning * refactor: use fmt::chrono in transmission-remote * refactor: use fmt::chrono in transmission-show * refactor: use fmt::chrono in GTK details dialog * refactor: use fmt::chrono in tr_session * refactor: remove tr_localtime_r * refactor: remove tr_gmtime_r
This commit is contained in:
parent
ed897f93f2
commit
1ebac744a5
|
@ -576,11 +576,7 @@ set(NEEDED_FUNCTIONS
|
|||
flock
|
||||
getmntent
|
||||
gettext
|
||||
gmtime_r
|
||||
gmtime_s
|
||||
htonll
|
||||
localtime_r
|
||||
localtime_s
|
||||
mkdtemp
|
||||
ngettext
|
||||
ntohll
|
||||
|
|
|
@ -599,16 +599,9 @@ void gtr_text_buffer_set_text(Glib::RefPtr<Gtk::TextBuffer> const& b, Glib::ustr
|
|||
}
|
||||
}
|
||||
|
||||
std::string get_date_string(time_t t)
|
||||
[[nodiscard]] std::string get_date_string(time_t t)
|
||||
{
|
||||
if (t == 0)
|
||||
{
|
||||
return _("N/A");
|
||||
}
|
||||
|
||||
struct tm tm;
|
||||
tr_localtime_r(&t, &tm);
|
||||
return fmt::format(FMT_STRING("{:%x}"), tm);
|
||||
return t == 0 ? _("N/A") : fmt::format(FMT_STRING("{:%x}"), fmt::localtime(t));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -7,7 +7,6 @@ Checks: >
|
|||
-bugprone-implicit-widening-of-multiplication-result,
|
||||
-bugprone-narrowing-conversions,
|
||||
cert-*,
|
||||
-cert-err33-c,
|
||||
-cert-err34-c,
|
||||
-cert-err58-cpp,
|
||||
clang-analyzer-core.*,
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <event2/listener.h>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/chrono.h>
|
||||
|
||||
#include <libdeflate.h>
|
||||
|
||||
|
@ -203,15 +204,10 @@ static void add_response(struct evhttp_request* req, tr_rpc_server* server, stru
|
|||
}
|
||||
}
|
||||
|
||||
static void add_time_header(struct evkeyvalq* headers, char const* key, time_t value)
|
||||
static void add_time_header(struct evkeyvalq* headers, char const* key, time_t now)
|
||||
{
|
||||
char buf[128];
|
||||
struct tm tm;
|
||||
/* According to RFC 2616 this must follow RFC 1123's date format,
|
||||
so use gmtime instead of localtime... */
|
||||
tr_gmtime_r(&value, &tm);
|
||||
strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", &tm);
|
||||
evhttp_add_header(headers, key, buf);
|
||||
// RFC 2616 says this must follow RFC 1123's date format, so use gmtime instead of localtime
|
||||
evhttp_add_header(headers, key, fmt::format("{:%a %b %d %T %Y%n}", fmt::gmtime(now)).c_str());
|
||||
}
|
||||
|
||||
static void evbuffer_ref_cleanup_tr_free(void const* /*data*/, size_t /*datalen*/, void* extra)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/format.h> // fmt::ptr
|
||||
|
||||
|
@ -724,7 +725,7 @@ static void tr_sessionInitImpl(init_data* data)
|
|||
|
||||
#ifndef _WIN32
|
||||
/* Don't exit when writing on a broken socket */
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
(void)signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
|
||||
tr_logSetQueueEnabled(data->messageQueuingEnabled);
|
||||
|
@ -1466,9 +1467,8 @@ static void useAltSpeed(tr_session* s, struct tr_turtle_info* t, bool enabled, b
|
|||
*/
|
||||
static bool getInTurtleTime(struct tr_turtle_info const* t)
|
||||
{
|
||||
time_t const now = tr_time();
|
||||
struct tm tm;
|
||||
tr_localtime_r(&now, &tm);
|
||||
auto const now = tr_time();
|
||||
struct tm const tm = fmt::localtime(now);
|
||||
|
||||
size_t minute_of_the_week = tm.tm_wday * MinutesPerDay + tm.tm_hour * MinutesPerHour + tm.tm_min;
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <event2/util.h> /* evutil_vsnprintf() */
|
||||
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include "transmission.h"
|
||||
|
@ -1779,12 +1780,6 @@ static void torrentCallScript(tr_torrent const* tor, char const* script)
|
|||
return;
|
||||
}
|
||||
|
||||
time_t const now = tr_time();
|
||||
struct tm tm;
|
||||
char ctime_str[32];
|
||||
tr_localtime_r(&now, &tm);
|
||||
strftime(ctime_str, sizeof(ctime_str), "%a %b %d %T %Y%n", &tm); /* ctime equiv */
|
||||
|
||||
auto torrent_dir = std::string{ tor->currentDir() };
|
||||
tr_sys_path_native_separators(std::data(torrent_dir));
|
||||
|
||||
|
@ -1797,7 +1792,7 @@ static void torrentCallScript(tr_torrent const* tor, char const* script)
|
|||
|
||||
auto const env = std::map<std::string_view, std::string_view>{
|
||||
{ "TR_APP_VERSION"sv, SHORT_VERSION_STRING },
|
||||
{ "TR_TIME_LOCALTIME"sv, ctime_str },
|
||||
{ "TR_TIME_LOCALTIME"sv, fmt::format("{:%a %b %d %T %Y%n}", fmt::localtime(tr_time())) },
|
||||
{ "TR_TORRENT_BYTES_DOWNLOADED"sv, bytes_downloaded_str },
|
||||
{ "TR_TORRENT_DIR"sv, torrent_dir.c_str() },
|
||||
{ "TR_TORRENT_HASH"sv, tor->infoHashString() },
|
||||
|
|
|
@ -175,7 +175,7 @@ static void libeventThreadFunc(tr_event_handle* events)
|
|||
{
|
||||
#ifndef _WIN32
|
||||
/* Don't exit when writing on a broken socket */
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
(void)signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
|
||||
tr_evthread_init();
|
||||
|
|
|
@ -59,54 +59,6 @@ time_t __tr_current_time = 0;
|
|||
****
|
||||
***/
|
||||
|
||||
struct tm* tr_gmtime_r(time_t const* timep, struct tm* result)
|
||||
{
|
||||
#if defined(HAVE_GMTIME_R)
|
||||
|
||||
return gmtime_r(timep, result);
|
||||
|
||||
#elif defined(HAVE_GMTIME_S)
|
||||
|
||||
return gmtime_s(result, timep) == 0 ? result : nullptr;
|
||||
|
||||
#else
|
||||
|
||||
struct tm* p = gmtime(timep);
|
||||
if (p != nullptr)
|
||||
{
|
||||
*result = *p;
|
||||
return result;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
struct tm* tr_localtime_r(time_t const* timep, struct tm* result)
|
||||
{
|
||||
#if defined(HAVE_LOCALTIME_R)
|
||||
|
||||
return localtime_r(timep, result);
|
||||
|
||||
#elif defined(HAVE_LOCALTIME_S)
|
||||
|
||||
return localtime_s(result, timep) == 0 ? result : nullptr;
|
||||
|
||||
#else
|
||||
|
||||
struct tm* p = localtime(timep);
|
||||
if (p != nullptr)
|
||||
{
|
||||
*result = *p;
|
||||
return result;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
struct timeval tr_gettimeofday()
|
||||
{
|
||||
auto const d = std::chrono::system_clock::now().time_since_epoch();
|
||||
|
|
|
@ -384,12 +384,6 @@ std::string& tr_strvUtf8Clean(std::string_view cleanme, std::string& setme);
|
|||
*/
|
||||
[[nodiscard]] std::string tr_strratio(double ratio, char const* infinity);
|
||||
|
||||
/** @brief Portability wrapper for localtime_r() that uses the system implementation if available */
|
||||
struct tm* tr_localtime_r(time_t const* _clock, struct tm* _result);
|
||||
|
||||
/** @brief Portability wrapper for gmtime_r() that uses the system implementation if available */
|
||||
struct tm* tr_gmtime_r(time_t const* _clock, struct tm* _result);
|
||||
|
||||
/** @brief Portability wrapper for gettimeofday(), with tz argument dropped */
|
||||
struct timeval tr_gettimeofday();
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <event2/buffer.h>
|
||||
#include <event2/util.h>
|
||||
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <libtransmission/transmission.h>
|
||||
|
@ -886,9 +887,7 @@ static char const* bandwidthPriorityNames[] = {
|
|||
|
||||
static char* format_date(char* buf, size_t buflen, time_t now)
|
||||
{
|
||||
struct tm tm;
|
||||
tr_localtime_r(&now, &tm);
|
||||
strftime(buf, buflen, "%a %b %d %T %Y%n", &tm); /* ctime equiv */
|
||||
*fmt::format_to_n(buf, buflen - 1, "{:%a %b %d %T %Y}", fmt::localtime(now)).out = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -1079,22 +1078,22 @@ static void printDetails(tr_variant* top)
|
|||
|
||||
if (tr_variantDictFindInt(t, TR_KEY_addedDate, &i) && i != 0)
|
||||
{
|
||||
printf(" Date added: %s", format_date(buf, sizeof(buf), i));
|
||||
printf(" Date added: %s\n", format_date(buf, sizeof(buf), i));
|
||||
}
|
||||
|
||||
if (tr_variantDictFindInt(t, TR_KEY_doneDate, &i) && i != 0)
|
||||
{
|
||||
printf(" Date finished: %s", format_date(buf, sizeof(buf), i));
|
||||
printf(" Date finished: %s\n", format_date(buf, sizeof(buf), i));
|
||||
}
|
||||
|
||||
if (tr_variantDictFindInt(t, TR_KEY_startDate, &i) && i != 0)
|
||||
{
|
||||
printf(" Date started: %s", format_date(buf, sizeof(buf), i));
|
||||
printf(" Date started: %s\n", format_date(buf, sizeof(buf), i));
|
||||
}
|
||||
|
||||
if (tr_variantDictFindInt(t, TR_KEY_activityDate, &i) && i != 0)
|
||||
{
|
||||
printf(" Latest activity: %s", format_date(buf, sizeof(buf), i));
|
||||
printf(" Latest activity: %s\n", format_date(buf, sizeof(buf), i));
|
||||
}
|
||||
|
||||
if (tr_variantDictFindInt(t, TR_KEY_secondsDownloading, &i) && i > 0)
|
||||
|
@ -1113,7 +1112,7 @@ static void printDetails(tr_variant* top)
|
|||
|
||||
if (tr_variantDictFindInt(t, TR_KEY_dateCreated, &i) && i != 0)
|
||||
{
|
||||
printf(" Date created: %s", format_date(buf, sizeof(buf), i));
|
||||
printf(" Date created: %s\n", format_date(buf, sizeof(buf), i));
|
||||
}
|
||||
|
||||
if (tr_variantDictFindBool(t, TR_KEY_isPrivate, &boolVal))
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
#include <event2/buffer.h>
|
||||
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <libtransmission/transmission.h>
|
||||
|
||||
#include <libtransmission/error.h>
|
||||
|
@ -158,18 +161,9 @@ int parseCommandLine(app_opts& opts, int argc, char const* const* argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
auto toString(time_t timestamp)
|
||||
[[nodiscard]] auto toString(time_t now)
|
||||
{
|
||||
if (timestamp == 0)
|
||||
{
|
||||
return std::string{ "Unknown" };
|
||||
}
|
||||
|
||||
struct tm tm;
|
||||
tr_localtime_r(×tamp, &tm);
|
||||
auto buf = std::array<char, 64>{};
|
||||
strftime(std::data(buf), std::size(buf), "%a %b %d %T %Y%n", &tm); /* ctime equiv */
|
||||
return std::string{ std::data(buf) };
|
||||
return now == 0 ? "Unknown" : fmt::format("{:%a %b %d %T %Y}", fmt::localtime(now));
|
||||
}
|
||||
|
||||
bool compare_2nd_field(std::string_view const& l, std::string_view const& r)
|
||||
|
@ -199,7 +193,7 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo)
|
|||
printf(" Name: %s\n", metainfo.name().c_str());
|
||||
printf(" Hash: %" TR_PRIsv "\n", TR_PRIsv_ARG(metainfo.infoHashString()));
|
||||
printf(" Created by: %s\n", std::empty(metainfo.creator()) ? "Unknown" : metainfo.creator().c_str());
|
||||
printf(" Created on: %s\n", toString(metainfo.dateCreated()).c_str());
|
||||
printf(" Created on: %s\n\n", toString(metainfo.dateCreated()).c_str());
|
||||
|
||||
if (!std::empty(metainfo.comment()))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue