1 //===- FileSystem.h -------------------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // This file declares the mcld::sys::fs:: namespace. It follows TR2/boost 10 // filesystem (v3), but modified to remove exception handling and the 11 // path class. 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MCLD_FILE_SYSTEM_H 15 #define MCLD_FILE_SYSTEM_H 16 #ifdef ENABLE_UNITTEST 17 #include <gtest.h> 18 #endif 19 20 #include "mcld/Support/PathCache.h" 21 #include <mcld/Config/Config.h> 22 #include <string> 23 #include <iosfwd> 24 #include <locale> 25 26 namespace mcld { 27 namespace sys { 28 29 namespace fs { 30 31 enum FileType 32 { 33 StatusError, 34 StatusUnknown = StatusError, 35 FileNotFound, 36 RegularFile, 37 DirectoryFile, 38 SymlinkFile, 39 BlockFile, 40 CharacterFile, 41 FifoFile, 42 SocketFile, 43 ReparseFile, 44 TypeUnknown, 45 StatusKnown, 46 IsSymLink 47 }; 48 49 /** \class FileStatus 50 * \brief FileStatus 51 */ 52 class FileStatus 53 { 54 public: 55 FileStatus() 56 : m_Value(StatusError) {} 57 58 explicit FileStatus(FileType v) 59 : m_Value(v) {} 60 61 void setType(FileType v) { m_Value = v; } 62 FileType type() const { return m_Value; } 63 64 private: 65 FileType m_Value; 66 }; 67 68 inline bool operator==(const FileStatus& rhs, const FileStatus& lhs) { 69 return rhs.type() == lhs.type(); 70 } 71 72 inline bool operator!=(const FileStatus& rhs, const FileStatus& lhs ) { 73 return !(rhs == lhs); 74 } 75 76 class Path; 77 class DirIterator; 78 class Directory; 79 80 bool exists(const Path &pPath); 81 bool is_directory(const Path &pPath); 82 83 inline static bool exists(FileStatus f) { 84 return (f.type() != StatusError)&&(f.type() != FileNotFound); 85 } 86 87 inline static bool is_directory(FileStatus f) { 88 return f.type() == mcld::sys::fs::DirectoryFile; 89 } 90 91 namespace detail 92 { 93 94 extern std::string static_library_extension; 95 extern std::string shared_library_extension; 96 extern std::string executable_extension; 97 extern std::string relocatable_extension; 98 extern std::string assembly_extension; 99 extern std::string bitcode_extension; 100 101 size_t canonicalize(std::string& pPathName); 102 bool not_found_error(int perrno); 103 void status(const Path& p, FileStatus& pFileStatus); 104 void symlink_status(const Path& p, FileStatus& pFileStatus); 105 mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter); 106 void open_dir(Directory& pDir); 107 void close_dir(Directory& pDir); 108 void get_pwd(std::string& pPWD); 109 110 int open(const Path& pPath, int pOFlag); 111 int open(const Path& pPath, int pOFlag, int pPermission); 112 ssize_t pread(int pFD, void* pBuf, size_t pCount, size_t pOffset); 113 ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, size_t pOffset); 114 int ftruncate(int pFD, size_t pLength); 115 116 } // namespace of detail 117 } // namespace of fs 118 } // namespace of sys 119 } // namespace of mcld 120 121 #endif 122 123