Skip to content

Commit

Permalink
update filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Oct 10, 2023
1 parent 098e944 commit 29b0a88
Showing 1 changed file with 17 additions and 28 deletions.
45 changes: 17 additions & 28 deletions 3rd/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,6 @@
// SOFTWARE.
//
//---------------------------------------------------------------------------------------
//
// To dynamically select std::filesystem where available on most platforms,
// you could use:
//
// #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
// #if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
// #define GHC_USE_STD_FS
// #include <filesystem>
// namespace fs = std::filesystem;
// #endif
// #endif
// #ifndef GHC_USE_STD_FS
// #include <ghc/filesystem.hpp>
// namespace fs = ghc::filesystem;
// #endif
//
//---------------------------------------------------------------------------------------
#ifndef GHC_FILESYSTEM_H
#define GHC_FILESYSTEM_H

Expand All @@ -53,7 +36,7 @@

#ifndef GHC_OS_DETECTED
#if defined(__APPLE__) && defined(__MACH__)
#define GHC_OS_MACOS
#define GHC_OS_APPLE
#elif defined(__linux__)
#define GHC_OS_LINUX
#if defined(__ANDROID__)
Expand Down Expand Up @@ -181,7 +164,7 @@
#include <langinfo.h>
#endif
#endif
#ifdef GHC_OS_MACOS
#ifdef GHC_OS_APPLE
#include <Availability.h>
#endif

Expand Down Expand Up @@ -308,7 +291,7 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// ghc::filesystem version in decimal (major * 10000 + minor * 100 + patch)
#define GHC_FILESYSTEM_VERSION 10514L
#define GHC_FILESYSTEM_VERSION 10515L

#if !defined(GHC_WITH_EXCEPTIONS) && (defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND))
#define GHC_WITH_EXCEPTIONS
Expand Down Expand Up @@ -1159,6 +1142,10 @@ GHC_FS_API void create_hard_link(const path& to, const path& new_hard_link, std:
GHC_FS_API uintmax_t hard_link_count(const path& p, std::error_code& ec) noexcept;
#endif

#if defined(GHC_OS_WINDOWS) && (!defined(__GLIBCXX__) || (defined(_GLIBCXX_HAVE__WFOPEN) && defined(_GLIBCXX_USE_WCHAR_T)))
#define GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
#endif

// Non-C++17 add-on std::fstream wrappers with path
template <class charT, class traits = std::char_traits<charT>>
class basic_filebuf : public std::basic_filebuf<charT, traits>
Expand All @@ -1170,7 +1157,7 @@ class basic_filebuf : public std::basic_filebuf<charT, traits>
const basic_filebuf& operator=(const basic_filebuf&) = delete;
basic_filebuf<charT, traits>* open(const path& p, std::ios_base::openmode mode)
{
#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
return std::basic_filebuf<charT, traits>::open(p.wstring().c_str(), mode) ? this : 0;
#else
return std::basic_filebuf<charT, traits>::open(p.string().c_str(), mode) ? this : 0;
Expand All @@ -1183,7 +1170,7 @@ class basic_ifstream : public std::basic_ifstream<charT, traits>
{
public:
basic_ifstream() {}
#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
explicit basic_ifstream(const path& p, std::ios_base::openmode mode = std::ios_base::in)
: std::basic_ifstream<charT, traits>(p.wstring().c_str(), mode)
{
Expand All @@ -1206,7 +1193,7 @@ class basic_ofstream : public std::basic_ofstream<charT, traits>
{
public:
basic_ofstream() {}
#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
explicit basic_ofstream(const path& p, std::ios_base::openmode mode = std::ios_base::out)
: std::basic_ofstream<charT, traits>(p.wstring().c_str(), mode)
{
Expand All @@ -1229,7 +1216,7 @@ class basic_fstream : public std::basic_fstream<charT, traits>
{
public:
basic_fstream() {}
#if defined(GHC_OS_WINDOWS) && !defined(__GLIBCXX__)
#ifdef GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
explicit basic_fstream(const path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
: std::basic_fstream<charT, traits>(p.wstring().c_str(), mode)
{
Expand Down Expand Up @@ -3170,7 +3157,7 @@ GHC_INLINE path path::extension() const
auto iter = end();
const auto& fn = *--iter;
impl_string_type::size_type pos = fn._path.rfind('.');
if (pos != std::string::npos && pos > 0) {
if (pos != std::string::npos && pos > 0 && fn._path != "..") {
return path(fn._path.substr(pos), native_format);
}
}
Expand Down Expand Up @@ -4650,9 +4637,11 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err
if (!::SetFileTime(file.get(), 0, 0, &ft)) {
ec = detail::make_system_error();
}
#elif defined(GHC_OS_MACOS) && \
(__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_13) || (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_11_0) || \
(__TV_OS_VERSION_MIN_REQUIRED < __TVOS_11_0) || (__WATCH_OS_VERSION_MIN_REQUIRED < __WATCHOS_4_0)
#elif defined(GHC_OS_APPLE) && \
(__MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300 \
|| __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000 \
|| __TV_OS_VERSION_MIN_REQUIRED && __TVOS_VERSION_MIN_REQUIRED < 110000 \
|| __WATCH_OS_VERSION_MIN_REQUIRED && __WATCHOS_VERSION_MIN_REQUIRED < 40000)
struct ::stat fs;
if (::stat(p.c_str(), &fs) == 0) {
struct ::timeval tv[2];
Expand Down

0 comments on commit 29b0a88

Please sign in to comment.