[llvm-commits] CVS: llvm/include/llvm/System/Path.h

Reid Spencer reid at x10sys.com
Sun Nov 14 13:53:00 PST 2004



Changes in directory llvm/include/llvm/System:

Path.h updated: 1.8 -> 1.9
---
Log message:

*Put the StatusInfo type in the right section. *Provide the ability to rename a file.*Provide the ability to get/set stat(2) information.*Provide the ability to identify LLVM file types.

---
Diffs of the changes:  (+72 -19)

Index: llvm/include/llvm/System/Path.h
diff -u llvm/include/llvm/System/Path.h:1.8 llvm/include/llvm/System/Path.h:1.9
--- llvm/include/llvm/System/Path.h:1.8	Tue Nov  9 14:26:31 2004
+++ llvm/include/llvm/System/Path.h	Sun Nov 14 15:52:22 2004
@@ -43,6 +43,26 @@
   /// @since 1.4
   /// @brief An abstraction for operating system paths.
   class Path {
+    /// @name Types
+    /// @{
+    public:
+      typedef std::vector<Path> Vector;
+
+      /// This structure provides basic file system information about a file.
+      /// The structure is filled in by the getStatusInfo method.
+      /// @brief File status structure
+      struct StatusInfo {
+        StatusInfo() : modTime(0,0) { fileSize=0; mode=0; user=0; group=0; }
+        size_t      fileSize;   ///< Size of the file in bytes
+        TimeValue   modTime;    ///< Time of file's modification
+        uint32_t    mode;       ///< Mode of the file, if applicable
+        uint32_t    user;       ///< User ID of owner, if applicable
+        uint32_t    group;      ///< Group ID of owner, if applicable
+        bool        isDir;      ///< True if this is a directory.
+      };
+
+
+    /// @}
     /// @name Constructors
     /// @{
     public:
@@ -125,7 +145,7 @@
       static std::string GetDLLSuffix();
 
       /// This is one of the very few ways in which a path can be constructed
-      /// with a syntactically invalid name. The only *legal* invalid name is an 
+      /// with a syntactically invalid name. The only *legal* invalid name is an
       /// empty one. Other invalid names are not permitted. Empty paths are
       /// provided so that they can be used to indicate null or error results in
       /// other lib/System functionality.
@@ -235,6 +255,14 @@
       /// @brief Determine if file has a specific magic number
       bool hasMagicNumber(const std::string& magic) const;
 
+      /// This function retrieves the first \p len bytes of the file associated
+      /// with \p this. These bytes are returned as the "magic number" in the
+      /// \p Magic parameter.
+      /// @returns true if the Path is a file and the magic number is retrieved,
+      /// false otherwise.
+      /// @brief Get the file's magic number.
+      bool getMagicNumber(std::string& Magic, unsigned len) const;
+
       /// This function determines if the path name in the object references an
       /// archive file by looking at its magic number.
       /// @returns true if the file starts with the magic number for an archive
@@ -307,25 +335,15 @@
       /// @brief Get the base name of the path
       std::string getBasename() const;
 
-      /// This structure provides basic file system information about a file.
-      /// The structure is filled in by the getStatusInfo method.
-      /// @brief File status structure
-      struct StatusInfo {
-        StatusInfo() : modTime(0,0) { fileSize=0; mode=0; user=0; group=0; }
-        size_t      fileSize;   ///< Size of the file in bytes
-        TimeValue   modTime;    ///< Time of file's modification
-        uint64_t    mode;       ///< Mode of the file, if applicable
-        uint64_t    user;       ///< User ID of owner, if applicable
-        uint64_t    group;      ///< Group ID of owner, if applicable
-      };
-
-      /// This function returns status information about the file. 
-      /// @returns nothing
-      /// @throws std::string if an error occurs.
-      /// @brief Get file status.
-      void getStatusInfo(StatusInfo& stat) const;
+      /// This function builds a list of paths that are the names of the
+      /// files and directories in a directory.
+      /// @returns false if \p this is not a directory, true otherwise
+      /// @throws std::string if the directory cannot be searched
+      /// @brief Build a list of directory's contents.
+      bool getDirectoryContents(Vector& paths) const;
 
-      /// @returns a c string containing the path name.
+      /// Obtain a 'C' string for the path name.
+      /// @returns a 'C' string containing the path name.
       /// @brief Returns the path as a C string.
       const char* const c_str() const { return path.c_str(); }
 
@@ -339,6 +357,14 @@
       /// valid path being found.
       void clear() { path.clear(); }
 
+      /// This function returns status information about the file. The type of
+      /// path (file or directory) is updated to reflect the actual contents 
+      /// of the file system.
+      /// @returns nothing
+      /// @throws std::string if an error occurs.
+      /// @brief Get file status.
+      void getStatusInfo(StatusInfo& stat);
+
       /// This method attempts to set the Path object to \p unverified_path
       /// and interpret the name as a directory name.  The \p unverified_path 
       /// is verified. If verification succeeds then \p unverified_path 
@@ -476,6 +502,20 @@
       /// @brief Destroy the file this Path refers to.
       bool destroyFile(); 
 
+      /// This method renames the file referenced by \p this as \p newName. Both
+      /// files must exist before making this call.
+      /// @returns false if the Path does not refer to a file, true otherwise.
+      /// @throws std::string if there is an file system error.
+      /// @brief Rename one file as another.
+      bool renameFile(const Path& newName);
+
+      /// This method sets the access time, modification time, and permission
+      /// mode of the file associated with \p this as given by \p si.  
+      /// @returns false if the Path does not refer to a file, true otherwise.
+      /// @throws std::string if the file could not be modified
+      /// @brief Set file times and mode.
+      bool setStatusInfo(const StatusInfo& si ) const ;
+
     /// @}
     /// @name Data
     /// @{
@@ -484,7 +524,20 @@
 
     /// @}
   };
+
+  /// This enumeration delineates the kinds of files that LLVM knows about.
+  enum LLVMFileType {
+    UnknownFileType = 0,            ///< Unrecognized file
+    BytecodeFileType = 1,           ///< Uncompressed bytecode file
+    CompressedBytecodeFileType = 2, ///< Compressed bytecode file
+    ArchiveFileType = 3,            ///< ar style archive file
+  };
+
+  /// This utility function allows any memory block to be examined in order
+  /// to determine its file type.
+  LLVMFileType IdentifyFileType(const char*magic, unsigned length);
 }
+
 }
 
 // vim: sw=2






More information about the llvm-commits mailing list