From a0f28a93bc27196ce1a8b1ac9e1ac130c1f7dc64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?okhowang=28=E7=8E=8B=E6=B2=9B=E6=96=87=29?= Date: Tue, 7 Apr 2020 21:15:52 +0800 Subject: [PATCH] Fix android compatibility --- include/ghc/filesystem.hpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 1f0fe39..c28815e 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -109,16 +109,24 @@ #else #include #include -#include #include #include -#include #include #include #include #include #ifdef GHC_OS_ANDROID #include +#if __ANDROID_API__ < 12 +#include +#endif +#include +#define statvfs statfs +#else +#include +#endif +#if !defined(__ANDROID__) || __ANDROID_API__ >= 26 +#include #endif #endif #ifdef GHC_OS_MACOS @@ -3961,12 +3969,19 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err #endif #endif #else +#ifndef UTIME_OMIT +#define UTIME_OMIT ((1l << 30) - 2l) +#endif struct ::timespec times[2]; times[0].tv_sec = 0; times[0].tv_nsec = UTIME_OMIT; times[1].tv_sec = static_cast(std::chrono::duration_cast(d).count()); times[1].tv_nsec = static_cast(std::chrono::duration_cast(d).count() % 1000000000); +#if defined(__ANDROID_API__) && __ANDROID_API__ < 12 + if (syscall(__NR_utimensat, AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) { +#else if (::utimensat(AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) { +#endif ec = detail::make_system_error(); } return; @@ -4268,17 +4283,13 @@ GHC_INLINE space_info space(const path& p, std::error_code& ec) noexcept return {static_cast(-1), static_cast(-1), static_cast(-1)}; } return {static_cast(totalNumberOfBytes.QuadPart), static_cast(totalNumberOfFreeBytes.QuadPart), static_cast(freeBytesAvailableToCaller.QuadPart)}; -#elif !defined(__ANDROID__) || __ANDROID_API__ >= 19 +#else struct ::statvfs sfs; if (::statvfs(p.c_str(), &sfs) != 0) { ec = detail::make_system_error(); return {static_cast(-1), static_cast(-1), static_cast(-1)}; } return {static_cast(sfs.f_blocks * sfs.f_frsize), static_cast(sfs.f_bfree * sfs.f_frsize), static_cast(sfs.f_bavail * sfs.f_frsize)}; -#else - (void)p; - ec = detail::make_error_code(detail::portable_error::not_supported); - return {static_cast(-1), static_cast(-1), static_cast(-1)}; #endif }