Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed Apr 12, 2024
1 parent eb00559 commit 2503232
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cli/tls_http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ using tcp_stream = typename beast::tcp_stream::rebind_executor<

class Logger final {
private:
auto timestamp() const {
std::string timestamp() const {
return Botan::OS::format_time(std::time(nullptr), "%c");
}

Expand Down
19 changes: 13 additions & 6 deletions src/lib/utils/os_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,24 @@ uint64_t OS::get_system_timestamp_ns() {
return std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
}

std::string format_time(time_t time, const std::string& format) {
std::string OS::format_time(time_t time, const std::string& format) {
std::tm tm;

#if defined(BOTAN_BUILD_COMPILER_IS_MSVC) || defined(BOTAN_TARGET_OS_IS_MINGW) || \
defined(BOTAN_TARGET_OS_IS_CYGWIN) || defined(BOTAN_TARGET_OS_IS_WINDOWS)
localtime_s(&tm, time);
#if defined(BOTAN_TARGET_OS_HAS_WIN32)
localtime_s(&tm, &time);
#elif defined(BOTAN_TARGET_OS_HAS_POSIX1)
localtime_r(&time, &tm);
#else
localtime_r(time, &tm);
if(auto tmp = std::localtime(&time)) {
tm = *tmp;
} else {
throw Encoding_Error("Could not convert time_t to localtime");
}
#endif

return std::put_time(tm, format.c_str());
std::ostringstream oss;
oss << std::put_time(&tm, format.c_str());

Check failure on line 344 in src/lib/utils/os_utils.cpp

View workflow job for this annotation

GitHub Actions / Clang Tidy

no member named 'put_time' in namespace 'std'
return oss.str();
}

size_t OS::system_page_size() {
Expand Down

0 comments on commit 2503232

Please sign in to comment.