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#ifndef MCLD_SUPPORT_FILESYSTEM_H_ 14#define MCLD_SUPPORT_FILESYSTEM_H_ 15 16#include "mcld/Config/Config.h" 17#include "mcld/Support/PathCache.h" 18 19#include <iosfwd> 20#include <locale> 21#include <string> 22 23namespace mcld { 24namespace sys { 25 26namespace fs { 27 28enum FileType { 29 StatusError, 30 StatusUnknown = StatusError, 31 FileNotFound, 32 RegularFile, 33 DirectoryFile, 34 SymlinkFile, 35 BlockFile, 36 CharacterFile, 37 FifoFile, 38 SocketFile, 39 ReparseFile, 40 TypeUnknown, 41 StatusKnown, 42 IsSymLink 43}; 44 45/** \class FileStatus 46 * \brief FileStatus 47 */ 48class FileStatus { 49 public: 50 FileStatus() : m_Value(StatusError) {} 51 52 explicit FileStatus(FileType v) : m_Value(v) {} 53 54 void setType(FileType v) { m_Value = v; } 55 FileType type() const { return m_Value; } 56 57 private: 58 FileType m_Value; 59}; 60 61inline bool operator==(const FileStatus& rhs, const FileStatus& lhs) { 62 return rhs.type() == lhs.type(); 63} 64 65inline bool operator!=(const FileStatus& rhs, const FileStatus& lhs) { 66 return !(rhs == lhs); 67} 68 69class Path; 70class DirIterator; 71class Directory; 72 73bool exists(const Path& pPath); 74bool is_directory(const Path& pPath); 75 76namespace detail { 77 78extern Path::StringType static_library_extension; 79extern Path::StringType shared_library_extension; 80extern Path::StringType executable_extension; 81extern Path::StringType relocatable_extension; 82extern Path::StringType assembly_extension; 83extern Path::StringType bitcode_extension; 84 85size_t canonicalize(Path::StringType& pPathName); 86bool not_found_error(int perrno); 87void status(const Path& p, FileStatus& pFileStatus); 88void symlink_status(const Path& p, FileStatus& pFileStatus); 89mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter); 90void open_dir(Directory& pDir); 91void close_dir(Directory& pDir); 92void get_pwd(Path& pPWD); 93 94int open(const Path& pPath, int pOFlag); 95int open(const Path& pPath, int pOFlag, int pPermission); 96ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset); 97ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset); 98int ftruncate(int pFD, size_t pLength); 99void* mmap(void* pAddr, 100 size_t pLen, 101 int pProt, 102 int pFlags, 103 int pFD, 104 off_t pOffset); 105int munmap(void* pAddr, size_t pLen); 106 107} // namespace detail 108} // namespace fs 109} // namespace sys 110} // namespace mcld 111 112#endif // MCLD_SUPPORT_FILESYSTEM_H_ 113