FileSystem.h revision f7ac0f19a1c8d0ad14bcf6456ce368b830fea886
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 26namespace mcld { 27namespace sys { 28 29namespace fs { 30 31enum 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 */ 52class FileStatus 53{ 54public: 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 64private: 65 FileType m_Value; 66}; 67 68inline bool operator==(const FileStatus& rhs, const FileStatus& lhs) { 69 return rhs.type() == lhs.type(); 70} 71 72inline bool operator!=(const FileStatus& rhs, const FileStatus& lhs ) { 73 return !(rhs == lhs); 74} 75 76class Path; 77class DirIterator; 78class Directory; 79 80bool exists(const Path &pPath); 81bool is_directory(const Path &pPath); 82 83namespace detail { 84 85extern Path::StringType static_library_extension; 86extern Path::StringType shared_library_extension; 87extern Path::StringType executable_extension; 88extern Path::StringType relocatable_extension; 89extern Path::StringType assembly_extension; 90extern Path::StringType bitcode_extension; 91 92size_t canonicalize(Path::StringType& pPathName); 93bool not_found_error(int perrno); 94void status(const Path& p, FileStatus& pFileStatus); 95void symlink_status(const Path& p, FileStatus& pFileStatus); 96mcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter); 97void open_dir(Directory& pDir); 98void close_dir(Directory& pDir); 99void get_pwd(Path& pPWD); 100 101int open(const Path& pPath, int pOFlag); 102int open(const Path& pPath, int pOFlag, int pPermission); 103ssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset); 104ssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset); 105int ftruncate(int pFD, size_t pLength); 106void* mmap(void *pAddr, size_t pLen, 107 int pProt, int pFlags, int pFD, off_t pOffset); 108int 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