spdlog
Loading...
Searching...
No Matches
details/os.h
Go to the documentation of this file.
1// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3
4#pragma once
5
6#include <spdlog/common.h>
7#include <ctime> // std::time_t
8
9namespace spdlog {
10namespace details {
11namespace os {
12
13SPDLOG_API spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT;
14
15SPDLOG_API std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT;
16
18
19SPDLOG_API std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT;
20
22
23// eol definition
24#if !defined(SPDLOG_EOL)
25# ifdef _WIN32
26# define SPDLOG_EOL "\r\n"
27# else
28# define SPDLOG_EOL "\n"
29# endif
30#endif
31
33
34// folder separator
35#if !defined(SPDLOG_FOLDER_SEPS)
36# ifdef _WIN32
37# define SPDLOG_FOLDER_SEPS "\\/"
38# else
39# define SPDLOG_FOLDER_SEPS "/"
40# endif
41#endif
42
45
46// fopen_s on non windows for writing
47SPDLOG_API bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode);
48
49// Remove filename. return 0 on success
50SPDLOG_API int remove(const filename_t &filename) SPDLOG_NOEXCEPT;
51
52// Remove file if exists. return 0 on success
53// Note: Non atomic (might return failure to delete if concurrently deleted by other process/thread)
55
56SPDLOG_API int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT;
57
58// Return if file exists.
60
61// Return file size according to open FILE* object
62SPDLOG_API size_t filesize(FILE *f);
63
64// Return utc offset in minutes or throw spdlog_ex on failure
66
67// Return current thread id as size_t
68// It exists because the std::this_thread::get_id() is much slower(especially
69// under VS 2013)
71
72// Return current thread id as size_t (from thread local storage)
74
75// This is avoid msvc issue in sleep_for that happens if the clock changes.
76// See https://github.com/gabime/spdlog/issues/609
77SPDLOG_API void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT;
78
79SPDLOG_API std::string filename_to_str(const filename_t &filename);
80
82
83// Determine if the terminal supports colors
84// Source: https://github.com/agauniyal/rang/
86
87// Determine if the terminal attached
88// Source: https://github.com/agauniyal/rang/
90
91#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
92SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target);
93
94SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target);
95#endif
96
97// Return directory name from given path or empty string
98// "abc/file" => "abc"
99// "abc/" => "abc"
100// "abc" => ""
101// "abc///" => "abc//"
103
104// Create a dir from the given path.
105// Return true if succeeded or if this dir already exists.
107
108// non thread safe, cross platform getenv/getenv_s
109// return empty string if field not found
110SPDLOG_API std::string getenv(const char *field);
111
112} // namespace os
113} // namespace details
114} // namespace spdlog
115
116#ifdef SPDLOG_HEADER_ONLY
117# include "os-inl.h"
118#endif
#define SPDLOG_NOEXCEPT
Definition common.h:53
#define SPDLOG_API
Definition common.h:31
#define SPDLOG_FILENAME_T(s)
Definition common.h:107
#define SPDLOG_CONSTEXPR
Definition common.h:54
#define SPDLOG_EOL
Definition details/os.h:28
#define SPDLOG_FOLDER_SEPS
Definition details/os.h:39
SPDLOG_INLINE std::string filename_to_str(const filename_t &filename)
Definition os-inl.h:387
static SPDLOG_CONSTEXPR const char folder_seps[]
Definition details/os.h:43
SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode)
Definition os-inl.h:123
SPDLOG_INLINE int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT
Definition os-inl.h:172
SPDLOG_INLINE size_t filesize(FILE *f)
Definition os-inl.h:209
SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT
Definition os-inl.h:405
SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
Definition os-inl.h:263
SPDLOG_INLINE int remove(const filename_t &filename) SPDLOG_NOEXCEPT
Definition os-inl.h:163
SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT
Definition os-inl.h:436
SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT
Definition os-inl.h:330
std::string SPDLOG_INLINE getenv(const char *field)
Definition os-inl.h:579
SPDLOG_INLINE int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT
Definition os-inl.h:177
static SPDLOG_CONSTEXPR const char * default_eol
Definition details/os.h:32
SPDLOG_INLINE spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT
Definition os-inl.h:71
SPDLOG_INLINE std::tm localtime() SPDLOG_NOEXCEPT
Definition os-inl.h:97
SPDLOG_INLINE size_t thread_id() SPDLOG_NOEXCEPT
Definition os-inl.h:357
SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT
Definition os-inl.h:393
SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT
Definition os-inl.h:187
SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT
Definition os-inl.h:116
SPDLOG_INLINE filename_t dir_name(filename_t path)
Definition os-inl.h:573
SPDLOG_INLINE bool create_dir(filename_t path)
Definition os-inl.h:534
SPDLOG_INLINE void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT
Definition os-inl.h:369
static SPDLOG_CONSTEXPR const filename_t::value_type folder_seps_filename[]
Definition details/os.h:44
Definition async.h:25
fmt::basic_memory_buffer< wchar_t, 250 > wmemory_buf_t
Definition common.h:117
fmt::basic_string_view< wchar_t > wstring_view_t
Definition common.h:115
fmt::basic_string_view< char > string_view_t
Definition common.h:114
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:116