Photon 1.0.0
Loading...
Searching...
No Matches
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
10{
11 namespace details
12 {
13 namespace os
14 {
15
16 SPDLOG_API spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT;
17
18 SPDLOG_API std::tm localtime(const std::time_t& time_tt) SPDLOG_NOEXCEPT;
19
21
22 SPDLOG_API std::tm gmtime(const std::time_t& time_tt) SPDLOG_NOEXCEPT;
23
25
26// eol definition
27#if !defined(SPDLOG_EOL)
28#ifdef _WIN32
29#define SPDLOG_EOL "\r\n"
30#else
31#define SPDLOG_EOL "\n"
32#endif
33#endif
34
35 SPDLOG_CONSTEXPR static const char* default_eol = SPDLOG_EOL;
36
37// folder separator
38#if !defined(SPDLOG_FOLDER_SEPS)
39#ifdef _WIN32
40#define SPDLOG_FOLDER_SEPS "\\/"
41#else
42#define SPDLOG_FOLDER_SEPS "/"
43#endif
44#endif
45
46 SPDLOG_CONSTEXPR static const char folder_seps[] = SPDLOG_FOLDER_SEPS;
47 SPDLOG_CONSTEXPR static const filename_t::value_type folder_seps_filename[] = SPDLOG_FILENAME_T(SPDLOG_FOLDER_SEPS);
48
49 // fopen_s on non windows for writing
50 SPDLOG_API bool fopen_s(FILE** fp, const filename_t& filename, const filename_t& mode);
51
52 // Remove filename. return 0 on success
53 SPDLOG_API int remove(const filename_t& filename) SPDLOG_NOEXCEPT;
54
55 // Remove file if exists. return 0 on success
56 // Note: Non atomic (might return failure to delete if concurrently deleted by other process/thread)
58
59 SPDLOG_API int rename(const filename_t& filename1, const filename_t& filename2) SPDLOG_NOEXCEPT;
60
61 // Return if file exists.
63
64 // Return file size according to open FILE* object
65 SPDLOG_API size_t filesize(FILE* f);
66
67 // Return utc offset in minutes or throw spdlog_ex on failure
68 SPDLOG_API int utc_minutes_offset(const std::tm& tm = details::os::localtime());
69
70 // Return current thread id as size_t
71 // It exists because the std::this_thread::get_id() is much slower(especially
72 // under VS 2013)
74
75 // Return current thread id as size_t (from thread local storage)
77
78 // This is avoid msvc issue in sleep_for that happens if the clock changes.
79 // See https://github.com/gabime/spdlog/issues/609
80 SPDLOG_API void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT;
81
82 SPDLOG_API std::string filename_to_str(const filename_t& filename);
83
85
86 // Determine if the terminal supports colors
87 // Source: https://github.com/agauniyal/rang/
89
90 // Determine if the terminal attached
91 // Source: https://github.com/agauniyal/rang/
92 SPDLOG_API bool in_terminal(FILE* file) SPDLOG_NOEXCEPT;
93
94#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
95 SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t& target);
96
97 SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t& target);
98#endif
99
100 // Return directory name from given path or empty string
101 // "abc/file" => "abc"
102 // "abc/" => "abc"
103 // "abc" => ""
104 // "abc///" => "abc//"
106
107 // Create a dir from the given path.
108 // Return true if succeeded or if this dir already exists.
109 SPDLOG_API bool create_dir(const filename_t& path);
110
111 // non thread safe, cross platform getenv/getenv_s
112 // return empty string if field not found
113 SPDLOG_API std::string getenv(const char* field);
114
115 // Do fsync by FILE objectpointer.
116 // Return true on success.
117 SPDLOG_API bool fsync(FILE* fp);
118
119 } // namespace os
120 } // namespace details
121} // namespace spdlog
122
123#ifdef SPDLOG_HEADER_ONLY
124#include "os-inl.h"
125#endif
#define SPDLOG_NOEXCEPT
Definition common.h:69
#define SPDLOG_API
Definition common.h:45
#define SPDLOG_FILENAME_T(s)
Definition common.h:132
#define SPDLOG_CONSTEXPR
Definition common.h:70
#define SPDLOG_EOL
Definition os.h:31
#define SPDLOG_FOLDER_SEPS
Definition os.h:42
basic_fp< unsigned long long > fp
Definition format.h:1725
SPDLOG_INLINE filename_t dir_name(const filename_t &path)
Definition os-inl.h:581
SPDLOG_INLINE std::string filename_to_str(const filename_t &filename)
Definition os-inl.h:399
SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode)
Definition os-inl.h:128
SPDLOG_INLINE int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT
Definition os-inl.h:177
SPDLOG_INLINE size_t filesize(FILE *f)
Definition os-inl.h:214
SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT
Definition os-inl.h:417
SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
Definition os-inl.h:268
SPDLOG_INLINE int remove(const filename_t &filename) SPDLOG_NOEXCEPT
Definition os-inl.h:168
SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT
Definition os-inl.h:448
SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT
Definition os-inl.h:335
std::string SPDLOG_INLINE getenv(const char *field)
Definition os-inl.h:587
SPDLOG_INLINE int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT
Definition os-inl.h:182
SPDLOG_INLINE spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT
Definition os-inl.h:76
SPDLOG_INLINE std::tm localtime() SPDLOG_NOEXCEPT
Definition os-inl.h:102
SPDLOG_INLINE bool create_dir(const filename_t &path)
Definition os-inl.h:542
SPDLOG_INLINE size_t thread_id() SPDLOG_NOEXCEPT
Definition os-inl.h:369
SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT
Definition os-inl.h:405
SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT
Definition os-inl.h:192
SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT
Definition os-inl.h:121
SPDLOG_INLINE bool fsync(FILE *fp)
Definition os-inl.h:607
SPDLOG_INLINE void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT
Definition os-inl.h:381
Definition async.h:26
fmt::basic_string_view< char > string_view_t
Definition common.h:172
std::string filename_t
Definition common.h:131
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:173
Definition uuid.h:926
annotation details
Definition tag_strings.h:125