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