1 // TODO(b/147469372): filesystem library in Android's libcxx is not available 2 // for vendors. It had an unstable ABI and libcxx isn't updated ever since. 3 4 // This simply implements some of the required functions in not-so-safe fashion. 5 6 #pragma once 7 8 #include <dirent.h> 9 #include <log/log.h> 10 #include <stdlib.h> 11 #include <sys/stat.h> 12 #include <sys/types.h> 13 14 #include <string> 15 #include <vector> 16 17 namespace filesystem { 18 class path { 19 public: path(const std::string _path)20 path(const std::string _path) : strPath(_path) {} 21 filename()22 path filename() const { 23 auto pos = strPath.rfind('/'); 24 if (pos == std::string::npos) 25 return path(strPath); 26 27 pos++; 28 auto l = strPath.size(); 29 return path(strPath.substr(pos, l - pos)); 30 } 31 string()32 std::string string() const { return strPath; } 33 34 private: 35 std::string strPath; 36 }; 37 38 class directory_entry { 39 public: directory_entry(const std::string _path)40 directory_entry(const std::string _path) : p(_path) {} 41 path()42 class path path() { 43 return p; 44 } 45 46 private: 47 class path p; 48 }; 49 50 bool exists(const path& p); 51 52 bool is_directory(const path& p); 53 54 bool is_symlink(const path& p); 55 56 path read_symlink(const path& p); 57 58 // Vector is easier to create than an iterator and serves our purposes well 59 std::vector<directory_entry> directory_iterator(const path& p); 60 } // namespace filesystem 61