diff options
author | Josiah Gaskin <josiahgaskin@google.com> | 2011-07-20 17:33:08 -0700 |
---|---|---|
committer | Josiah Gaskin <josiahgaskin@google.com> | 2011-07-20 18:22:26 -0700 |
commit | 9102165fd8be64bdc9110d0839a84fcdfa5b68cb (patch) | |
tree | 3c9f6a6449ee315a165192ff8f8b9d2280809bc9 /tools | |
parent | 0bc12a0b13719976aff95a801d88e48c64510d11 (diff) | |
download | frameworks_base-9102165fd8be64bdc9110d0839a84fcdfa5b68cb.zip frameworks_base-9102165fd8be64bdc9110d0839a84fcdfa5b68cb.tar.gz frameworks_base-9102165fd8be64bdc9110d0839a84fcdfa5b68cb.tar.bz2 |
Fix to compile for windows
This change includes a workaround for dirent.h on windows not
including d_type.
Change-Id: Ieaa3f298d2e6b32f2d8367384a1d02a2f5d06cca
Diffstat (limited to 'tools')
-rw-r--r-- | tools/aapt/FileFinder.cpp | 29 | ||||
-rw-r--r-- | tools/aapt/FileFinder.h | 2 |
2 files changed, 27 insertions, 4 deletions
diff --git a/tools/aapt/FileFinder.cpp b/tools/aapt/FileFinder.cpp index a1f64d0..580528d 100644 --- a/tools/aapt/FileFinder.cpp +++ b/tools/aapt/FileFinder.cpp @@ -9,8 +9,9 @@ #include <utils/String8.h> #include <utils/KeyedVector.h> - #include <iostream> +#include <dirent.h> +#include <sys/stat.h> #include "DirectoryWalker.h" #include "FileFinder.h" @@ -21,6 +22,25 @@ using android::String8; using std::cout; using std::endl; +// Private function to check whether a file is a directory or not +bool isDirectory(const char* filename) { + struct stat fileStat; + if (stat(filename, &fileStat) == -1) { + return false; + } + return(S_ISDIR(fileStat.st_mode)); +} + + +// Private function to check whether a file is a regular file or not +bool isFile(const char* filename) { + struct stat fileStat; + if (stat(filename, &fileStat) == -1) { + return false; + } + return(S_ISREG(fileStat.st_mode)); +} + bool SystemFileFinder::findFiles(String8 basePath, Vector<String8>& extensions, KeyedVector<String8,time_t>& fileStore, DirectoryWalker* dw) @@ -45,14 +65,14 @@ bool SystemFileFinder::findFiles(String8 basePath, Vector<String8>& extensions, String8 fullPath = basePath.appendPathCopy(entryName); // If this entry is a directory we'll recurse into it - if (entry->d_type == DT_DIR) { + if (isDirectory(fullPath.string()) ) { DirectoryWalker* copy = dw->clone(); findFiles(fullPath, extensions, fileStore,copy); delete copy; } // If this entry is a file, we'll pass it over to checkAndAddFile - if (entry->d_type == DT_REG) { + if (isFile(fullPath.string()) ) { checkAndAddFile(fullPath,dw->entryStats(),extensions,fileStore); } } @@ -89,4 +109,5 @@ void SystemFileFinder::checkAndAddFile(String8 path, const struct stat* stats, #ifdef DEBUG cout << endl; #endif //DEBUG -}
\ No newline at end of file +} + diff --git a/tools/aapt/FileFinder.h b/tools/aapt/FileFinder.h index 3f87aba..6974aee 100644 --- a/tools/aapt/FileFinder.h +++ b/tools/aapt/FileFinder.h @@ -25,6 +25,8 @@ public: virtual bool findFiles(String8 basePath, Vector<String8>& extensions, KeyedVector<String8,time_t>& fileStore, DirectoryWalker* dw) = 0; + + virtual ~FileFinder() {}; }; class SystemFileFinder : public FileFinder { |