Agora  1.2.0
Agora project
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 
9 namespace spdlog {
10 namespace details {
11 namespace os {
12 
13 SPDLOG_API spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT;
14 
15 SPDLOG_API std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT;
16 
18 
19 SPDLOG_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
47 SPDLOG_API bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode);
48 
49 // Remove filename. return 0 on success
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 
56 SPDLOG_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
62 SPDLOG_API size_t filesize(FILE *f);
63 
64 // Return utc offset in minutes or throw spdlog_ex on failure
65 SPDLOG_API int utc_minutes_offset(const std::tm &tm = details::os::localtime());
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
77 SPDLOG_API void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT;
78 
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/
89 SPDLOG_API bool in_terminal(FILE *file) SPDLOG_NOEXCEPT;
90 
91 #if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
92 SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target);
93 
94 SPDLOG_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.
106 SPDLOG_API bool create_dir(const filename_t &path);
107 
108 // non thread safe, cross platform getenv/getenv_s
109 // return empty string if field not found
110 SPDLOG_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
SPDLOG_EOL
#define SPDLOG_EOL
Definition: os.h:28
fmt::v8::detail::value_type
remove_cvref_t< decltype(*detail::range_begin(std::declval< Range >()))> value_type
Definition: ranges.h:226
spdlog::details::os::in_terminal
SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT
Definition: os-inl.h:447
SPDLOG_NOEXCEPT
#define SPDLOG_NOEXCEPT
Definition: common.h:64
mm_gui.target
target
Definition: mm_gui.py:125
spdlog::details::os::rename
SPDLOG_INLINE int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT
Definition: os-inl.h:177
spdlog::details::os::sleep_for_millis
SPDLOG_INLINE void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT
Definition: os-inl.h:376
spdlog::details::os::folder_seps
static const SPDLOG_CONSTEXPR char folder_seps[]
Definition: os.h:43
spdlog::details::os::path_exists
SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT
Definition: os-inl.h:187
mm_gui.mode
string mode
Definition: mm_gui.py:105
fmt::v8::basic_string_view
Definition: core.h:448
spdlog::details::os::now
SPDLOG_INLINE spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT
Definition: os-inl.h:71
spdlog::details::os::remove_if_exists
SPDLOG_INLINE int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT
Definition: os-inl.h:172
spdlog::details::os::utc_minutes_offset
SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
Definition: os-inl.h:263
spdlog::details::os::is_color_terminal
SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT
Definition: os-inl.h:416
spdlog::details::os::fopen_s
SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode)
Definition: os-inl.h:123
filename
filename
Definition: parse_all_dl.m:14
fmt::v8::basic_memory_buffer
Definition: format.h:677
spdlog::details::os::create_dir
SPDLOG_INLINE bool create_dir(const filename_t &path)
Definition: os-inl.h:545
spdlog
Definition: async.h:25
spdlog::details::os::gmtime
SPDLOG_INLINE std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT
Definition: os-inl.h:103
spdlog::details::os::filename_to_str
SPDLOG_INLINE std::string filename_to_str(const filename_t &filename)
Definition: os-inl.h:398
spdlog::details::os::localtime
SPDLOG_INLINE std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT
Definition: os-inl.h:84
spdlog::details::os::getenv
std::string SPDLOG_INLINE getenv(const char *field)
Definition: os-inl.h:590
spdlog::details::os::filesize
SPDLOG_INLINE size_t filesize(FILE *f)
Definition: os-inl.h:209
spdlog::details::os::pid
SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT
Definition: os-inl.h:404
spdlog::details::os::folder_seps_filename
static const SPDLOG_CONSTEXPR filename_t::value_type folder_seps_filename[]
Definition: os.h:44
SPDLOG_FOLDER_SEPS
#define SPDLOG_FOLDER_SEPS
Definition: os.h:39
spdlog::details::os::_thread_id
SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT
Definition: os-inl.h:330
SPDLOG_FILENAME_T
#define SPDLOG_FILENAME_T(s)
Definition: common.h:123
common.h
spdlog::details::os::default_eol
static const SPDLOG_CONSTEXPR char * default_eol
Definition: os.h:32
std
Definition: json.hpp:5213
spdlog::details::os::remove
SPDLOG_INLINE int remove(const filename_t &filename) SPDLOG_NOEXCEPT
Definition: os-inl.h:163
spdlog::filename_t
std::string filename_t
Definition: common.h:122
SPDLOG_API
#define SPDLOG_API
Definition: common.h:40
os-inl.h
spdlog::details::os::thread_id
SPDLOG_INLINE size_t thread_id() SPDLOG_NOEXCEPT
Definition: os-inl.h:364
SPDLOG_CONSTEXPR
#define SPDLOG_CONSTEXPR
Definition: common.h:65
spdlog::details::os::dir_name
SPDLOG_INLINE filename_t dir_name(const filename_t &path)
Definition: os-inl.h:584