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 namespace detail { 84 85 extern Path::StringType static_library_extension; 86 extern Path::StringType shared_library_extension; 87 extern Path::StringType executable_extension; 88 extern Path::StringType relocatable_extension; 89 extern Path::StringType assembly_extension; 90 extern Path::StringType bitcode_extension; 91 92 size_t canonicalize(Path::StringType& pPathName); 93 bool not_found_error(int perrno); 94 void status(const Path& p, FileStatus& pFileStatus); 95 void symlink_status(const Path& p, FileStatus& pFileStatus); 96 mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter); 97 void open_dir(Directory& pDir); 98 void close_dir(Directory& pDir); 99 void get_pwd(Path& pPWD); 100 101 int open(const Path& pPath, int pOFlag); 102 int open(const Path& pPath, int pOFlag, int pPermission); 103 ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset); 104 ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset); 105 int ftruncate(int pFD, size_t pLength); 106 void* mmap(void *pAddr, size_t pLen, 107 int pProt, int pFlags, int pFD, off_t pOffset); 108 int munmap(void *pAddr, size_t pLen); 109 110 } // namespace of detail 111 } // namespace of fs 112 } // namespace of sys 113 } // namespace of mcld 114 115 #endif 116 117