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