From 866e37aecaf014f0f21a1b34543cd1040426e72f Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Thu, 5 Dec 2024 07:50:10 +0200 Subject: [PATCH] Minor cleanup --- include/spdlog/details/os.h | 58 ++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index c355753c..079b2399 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -31,19 +31,6 @@ constexpr static const char *default_eol = "\n"; // fopen_s on non windows for writing SPDLOG_API bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode); -// Remove filename. return true on success -SPDLOG_API bool remove(const filename_t &filename); - -// Remove file if exists. return 0 on success -// Note: Non atomic (might return failure to delete if concurrently deleted by other process/thread) -SPDLOG_API bool remove_if_exists(const filename_t &filename) ; - -// Rename file. return true on success -SPDLOG_API bool rename(const filename_t &filename1, const filename_t &filename2) noexcept; - -// Return if file exists. -SPDLOG_API bool path_exists(const filename_t &filename) noexcept; - // Return file size according to open FILE* object SPDLOG_API size_t filesize(FILE *f); @@ -62,9 +49,7 @@ SPDLOG_API size_t thread_id() noexcept; // See https://github.com/gabime/spdlog/issues/609 SPDLOG_API void sleep_for_millis(unsigned int milliseconds) noexcept; -// Try tp convert wstring filename to string. Return "??" if failed -SPDLOG_API std::string filename_to_str(const filename_t &filename); - +// Return pid SPDLOG_API int pid() noexcept; // Determine if the terminal supports colors @@ -80,16 +65,6 @@ SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target); SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target); #endif -// Return directory name from given path or empty string -// "abc/file" => "abc" -// "abc/" => "abc" -// "abc" => "" -// "abc///" => "abc//" -SPDLOG_API filename_t dir_name(const filename_t &path); - -// Create a dir from the given path. -// Return true if succeeded or if this dir already exists. -SPDLOG_API bool create_dir(const filename_t &path); // non thread safe, cross platform getenv/getenv_s // return empty string if field not found @@ -104,6 +79,33 @@ SPDLOG_API bool fsync(FILE *fp); SPDLOG_API bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp); // +// std::filesystem wrapper functions +// + +// Return directory name from given path or empty string +// "abc/file" => "abc" +// "abc/" => "abc" +// "abc" => "" +SPDLOG_API filename_t dir_name(const filename_t &path); + +// Create a dir from the given path. +// Return true if succeeded or if this dir already exists. +SPDLOG_API bool create_dir(const filename_t &path); + +// Remove filename. return true on success +SPDLOG_API bool remove(const filename_t &filename); + +// Remove file if exists. return 0 on success +// Note: Non atomic (might return failure to delete if concurrently deleted by other process/thread) +SPDLOG_API bool remove_if_exists(const filename_t &filename); + +// Rename file. return true on success +SPDLOG_API bool rename(const filename_t &filename1, const filename_t &filename2) noexcept; + +// Return if file exists. +SPDLOG_API bool path_exists(const filename_t &filename) noexcept; + + // Return file path and its extension: // // "mylog.txt" => ("mylog", ".txt") @@ -118,6 +120,10 @@ SPDLOG_API bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp); // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") SPDLOG_API std::tuple split_by_extension(const filename_t &fname); +// Try tp convert filename to string. Return "??" if failed +SPDLOG_API std::string filename_to_str(const filename_t &filename); + + } // namespace os } // namespace details } // namespace spdlog