diff options
| author | 2022-12-01 05:32:01 +0000 | |
|---|---|---|
| committer | 2022-12-01 05:32:01 +0000 | |
| commit | 46b0752616f899f0dc0188f8a234449d2e6533d0 (patch) | |
| tree | 7cccc1ed8d069e66266b3c2b04f4c19b93a04136 /libs/androidfw/misc.cpp | |
| parent | 7b7f8aba2f2c6fca1b065bfe055a4c62d0dd472a (diff) | |
| parent | 2ab4447ad20bdbf664c00de5f47c2c638ee83241 (diff) | |
Merge changes Ie5999dda,I2853cd3c,I7d9f1fe3,I19576654,I158af793, ...
* changes:
[res] Don't stat asset providers on RO filesystems
[res] Change OverlayableInfo to hold string views
[res] Change staged alias container to vector
[res] Change callback from function to function_ref
[res] Reuse memory in RebuildFilterList()
[res] Split keys and values in Theme::Entry vector
[res] Properly create ZipAssetsProvider with fd
Diffstat (limited to 'libs/androidfw/misc.cpp')
| -rw-r--r-- | libs/androidfw/misc.cpp | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/libs/androidfw/misc.cpp b/libs/androidfw/misc.cpp index 52854205207c..7af506638ebc 100644 --- a/libs/androidfw/misc.cpp +++ b/libs/androidfw/misc.cpp @@ -21,12 +21,17 @@ // #include <androidfw/misc.h> -#include <sys/stat.h> +#include "android-base/logging.h" + +#ifndef _WIN32 +#include <sys/statvfs.h> +#include <sys/vfs.h> +#endif // _WIN32 + #include <cstring> -#include <errno.h> #include <cstdio> - -using namespace android; +#include <errno.h> +#include <sys/stat.h> namespace android { @@ -41,8 +46,7 @@ FileType getFileType(const char* fileName) if (errno == ENOENT || errno == ENOTDIR) return kFileTypeNonexistent; else { - fprintf(stderr, "getFileType got errno=%d on '%s'\n", - errno, fileName); + PLOG(ERROR) << "getFileType(): stat(" << fileName << ") failed"; return kFileTypeUnknown; } } else { @@ -82,4 +86,32 @@ time_t getFileModDate(const char* fileName) return sb.st_mtime; } +#ifdef _WIN32 +// No need to implement these for Windows, the functions only matter on a device. +bool isReadonlyFilesystem(const char*) { + return false; +} +bool isReadonlyFilesystem(int) { + return false; +} +#else // _WIN32 +bool isReadonlyFilesystem(const char* path) { + struct statfs sfs; + if (::statfs(path, &sfs)) { + PLOG(ERROR) << "isReadonlyFilesystem(): statfs(" << path << ") failed"; + return false; + } + return (sfs.f_flags & ST_RDONLY) != 0; +} + +bool isReadonlyFilesystem(int fd) { + struct statfs sfs; + if (::fstatfs(fd, &sfs)) { + PLOG(ERROR) << "isReadonlyFilesystem(): fstatfs(" << fd << ") failed"; + return false; + } + return (sfs.f_flags & ST_RDONLY) != 0; +} +#endif // _WIN32 + }; // namespace android |