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