spdlog/include/spdlog/details/os.h

99 lines
2.7 KiB
C
Raw Normal View History

2019-06-03 17:09:16 -04:00
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2017-11-06 05:39:04 -05:00
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
2019-05-11 13:06:17 -04:00
2017-11-06 05:39:04 -05:00
#pragma once
2019-04-05 09:57:49 -04:00
#include "spdlog/common.h"
2019-05-10 20:05:22 -04:00
#include <ctime> // std::time_t
2017-11-06 05:39:04 -05:00
2018-03-17 06:47:46 -04:00
namespace spdlog {
namespace details {
namespace os {
2017-11-06 05:39:04 -05:00
2019-04-05 09:44:17 -04:00
spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
2019-04-05 09:44:17 -04:00
std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
2019-04-05 09:44:17 -04:00
std::tm localtime() SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
2019-04-05 09:44:17 -04:00
std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
2019-04-05 09:44:17 -04:00
std::tm gmtime() SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
// eol definition
2018-03-09 08:26:33 -05:00
#if !defined(SPDLOG_EOL)
2017-11-06 05:39:04 -05:00
#ifdef _WIN32
#define SPDLOG_EOL "\r\n"
#else
#define SPDLOG_EOL "\n"
#endif
#endif
2018-03-09 08:26:33 -05:00
SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL;
// folder separator
#ifdef _WIN32
2019-04-05 09:44:17 -04:00
const char folder_sep = '\\';
#else
SPDLOG_CONSTEXPR static const char folder_sep = '/';
#endif
2019-04-05 09:44:17 -04:00
void prevent_child_fd(FILE *f);
2017-11-06 05:39:04 -05:00
2018-03-09 08:26:33 -05:00
// fopen_s on non windows for writing
2019-04-05 09:44:17 -04:00
bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode);
2017-11-06 05:39:04 -05:00
2019-09-15 11:34:29 -04:00
// Remove filename. return 0 on success
2019-04-05 09:44:17 -04:00
int remove(const filename_t &filename) SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
2019-09-15 11:34:29 -04:00
// Remove file if exists. return 0 on success
// Note: Non atomic (might return failure to delete if concurrently deleted by other process/thread)
int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT;
2019-04-05 09:44:17 -04:00
int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
2019-09-15 11:34:29 -04:00
// Return if file exists.
2019-04-05 09:44:17 -04:00
bool file_exists(const filename_t &filename) SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
2018-03-09 08:26:33 -05:00
// Return file size according to open FILE* object
2019-04-05 09:44:17 -04:00
size_t filesize(FILE *f);
2017-11-06 05:39:04 -05:00
2018-03-09 08:26:33 -05:00
// Return utc offset in minutes or throw spdlog_ex on failure
2019-04-05 09:44:17 -04:00
int utc_minutes_offset(const std::tm &tm = details::os::localtime());
2017-11-06 05:39:04 -05:00
2018-03-09 08:26:33 -05:00
// Return current thread id as size_t
2018-07-21 16:48:07 -04:00
// It exists because the std::this_thread::get_id() is much slower(especially
// under VS 2013)
2019-04-05 09:44:17 -04:00
size_t _thread_id() SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
2018-03-09 08:26:33 -05:00
// Return current thread id as size_t (from thread local storage)
2019-04-05 09:44:17 -04:00
size_t thread_id() SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
2018-01-12 07:09:07 -05:00
// This is avoid msvc issue in sleep_for that happens if the clock changes.
// See https://github.com/gabime/spdlog/issues/609
2019-04-05 09:44:17 -04:00
void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
std::string filename_to_str(const filename_t &filename);
2017-11-06 05:39:04 -05:00
2019-05-08 10:16:56 -04:00
int pid() SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
// Determine if the terminal supports colors
2017-11-06 05:39:04 -05:00
// Source: https://github.com/agauniyal/rang/
2019-04-05 09:44:17 -04:00
bool is_color_terminal() SPDLOG_NOEXCEPT;
2017-11-06 05:39:04 -05:00
// Detrmine if the terminal attached
// Source: https://github.com/agauniyal/rang/
2019-04-05 09:44:17 -04:00
bool in_terminal(FILE *file) SPDLOG_NOEXCEPT;
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
2019-09-23 01:48:09 -04:00
void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target);
#endif
2018-03-17 06:47:46 -04:00
} // namespace os
} // namespace details
} // namespace spdlog
2019-04-05 09:44:17 -04:00
#ifdef SPDLOG_HEADER_ONLY
2019-05-11 06:19:53 -04:00
#include "os-inl.h"
2019-04-05 09:44:17 -04:00
#endif