You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spdlog/include/spdlog/details/os.h

94 lines
2.5 KiB
C

// Copyright(c) 2015-present Gabi Melman & spdlog contributors.
8 years ago
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
8 years ago
#pragma once
6 years ago
#include "spdlog/common.h"
6 years ago
#include <ctime> // std::time_t
8 years ago
8 years ago
namespace spdlog {
namespace details {
namespace os {
8 years ago
6 years ago
spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT;
8 years ago
6 years ago
std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT;
8 years ago
6 years ago
std::tm localtime() SPDLOG_NOEXCEPT;
8 years ago
6 years ago
std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT;
8 years ago
6 years ago
std::tm gmtime() SPDLOG_NOEXCEPT;
8 years ago
// eol definition
8 years ago
#if !defined(SPDLOG_EOL)
8 years ago
#ifdef _WIN32
#define SPDLOG_EOL "\r\n"
#else
#define SPDLOG_EOL "\n"
#endif
#endif
8 years ago
SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL;
// folder separator
#ifdef _WIN32
6 years ago
const char folder_sep = '\\';
#else
SPDLOG_CONSTEXPR static const char folder_sep = '/';
#endif
6 years ago
void prevent_child_fd(FILE *f);
8 years ago
8 years ago
// fopen_s on non windows for writing
6 years ago
bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode);
8 years ago
6 years ago
int remove(const filename_t &filename) SPDLOG_NOEXCEPT;
8 years ago
6 years ago
int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT;
8 years ago
8 years ago
// Return if file exists
6 years ago
bool file_exists(const filename_t &filename) SPDLOG_NOEXCEPT;
8 years ago
8 years ago
// Return file size according to open FILE* object
6 years ago
size_t filesize(FILE *f);
8 years ago
8 years ago
// Return utc offset in minutes or throw spdlog_ex on failure
6 years ago
int utc_minutes_offset(const std::tm &tm = details::os::localtime());
8 years ago
8 years ago
// Return current thread id as size_t
7 years ago
// It exists because the std::this_thread::get_id() is much slower(especially
// under VS 2013)
6 years ago
size_t _thread_id() SPDLOG_NOEXCEPT;
8 years ago
8 years ago
// Return current thread id as size_t (from thread local storage)
6 years ago
size_t thread_id() SPDLOG_NOEXCEPT;
8 years ago
8 years ago
// This is avoid msvc issue in sleep_for that happens if the clock changes.
// See https://github.com/gabime/spdlog/issues/609
6 years ago
void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT;
8 years ago
6 years ago
std::string filename_to_str(const filename_t &filename) SPDLOG_NOEXCEPT;
8 years ago
6 years ago
int pid() SPDLOG_NOEXCEPT;
8 years ago
// Determine if the terminal supports colors
8 years ago
// Source: https://github.com/agauniyal/rang/
6 years ago
bool is_color_terminal() SPDLOG_NOEXCEPT;
8 years ago
// Detrmine if the terminal attached
// Source: https://github.com/agauniyal/rang/
6 years ago
bool in_terminal(FILE *file) SPDLOG_NOEXCEPT;
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) && defined(_WIN32)
void wbuf_to_utf8buf(const fmt::wmemory_buffer &wbuf, fmt::memory_buffer &target);
#endif
8 years ago
} // namespace os
} // namespace details
} // namespace spdlog
6 years ago
#ifdef SPDLOG_HEADER_ONLY
#include "os-inl.h"
6 years ago
#endif