From: Otto Moerbeek Date: Wed, 10 Sep 2025 12:44:13 +0000 (+0200) Subject: Move timestamp() function to misc.cc X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fdc9a4fa2d80d7ec6b76f245a7a6efb68dae5f84;p=thirdparty%2Fpdns.git Move timestamp() function to misc.cc Signed-off-by: Otto Moerbeek --- diff --git a/pdns/misc.cc b/pdns/misc.cc index 8b662c5af..4f1e5c482 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -1796,3 +1796,17 @@ UniqueFilePtr openFileForWriting(const std::string& filePath, mode_t permissions } } + +const char* timestamp(time_t arg, timebuf_t& buf) +{ + const std::string s_timestampFormat = "%Y-%m-%dT%T"; + struct tm tmval{}; + size_t len = strftime(buf.data(), buf.size(), s_timestampFormat.c_str(), localtime_r(&arg, &tmval)); + if (len == 0) { + int ret = snprintf(buf.data(), buf.size(), "%lld", static_cast(arg)); + if (ret < 0 || static_cast(ret) >= buf.size()) { + buf[0] = '\0'; + } + } + return buf.data(); +} diff --git a/pdns/misc.hh b/pdns/misc.hh index 482df37b2..34377a8d6 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -895,3 +895,6 @@ using UniqueFilePtr = std::unique_ptr; UniqueFilePtr openFileForWriting(const std::string& filePath, mode_t permissions, bool mustNotExist = true, bool appendIfExists = false); } + +using timebuf_t = std::array; +const char* timestamp(time_t arg, timebuf_t& buf); diff --git a/pdns/recursordist/rec-cookiestore.cc b/pdns/recursordist/rec-cookiestore.cc index 885315cb0..98ece8214 100644 --- a/pdns/recursordist/rec-cookiestore.cc +++ b/pdns/recursordist/rec-cookiestore.cc @@ -23,10 +23,6 @@ #include "misc.hh" #include "rec-cookiestore.hh" -using timebuf_t = std::array; - -extern const char* timestamp(time_t arg, timebuf_t& buf); // XXX - void CookieStore::prune(time_t cutoff) { auto& ind = get(); diff --git a/pdns/recursordist/syncres.cc b/pdns/recursordist/syncres.cc index 38bfb0646..e7c8ae1ff 100644 --- a/pdns/recursordist/syncres.cc +++ b/pdns/recursordist/syncres.cc @@ -1014,20 +1014,6 @@ const char* isoDateTimeMillis(const struct timeval& tval, timebuf_t& buf) return buf.data(); } -const char* timestamp(time_t arg, timebuf_t& buf) -{ - const std::string s_timestampFormat = "%Y-%m-%dT%T"; - struct tm tmval{}; - size_t len = strftime(buf.data(), buf.size(), s_timestampFormat.c_str(), localtime_r(&arg, &tmval)); - if (len == 0) { - int ret = snprintf(buf.data(), buf.size(), "%lld", static_cast(arg)); - if (ret < 0 || static_cast(ret) >= buf.size()) { - buf[0] = '\0'; - } - } - return buf.data(); -} - struct ednsstatus_t : public multi_index_container, member>,