Add method for checking if a path is a symbolic link.
authorRafael Espindola <rafael.espindola@gmail.com>
Sun, 7 Nov 2010 04:36:50 +0000 (04:36 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sun, 7 Nov 2010 04:36:50 +0000 (04:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118367 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/System/Path.h
lib/System/Unix/Path.inc
lib/System/Win32/Path.inc

index 20495287b140519bfdba7ea42e4ae3d81c7a61fe..cfeacd236e22100dcb64fa072fb178c2bc6d06b8 100644 (file)
@@ -373,6 +373,12 @@ namespace sys {
       /// @brief Determins if the path is a directory in the file system.
       bool isDirectory() const;
 
+      /// This function determines if the path name refences an
+      /// existing symbolic link.
+      /// @returns true if the pathname references an existing symlink.
+      /// @brief Determins if the path is a symlink in the file system.
+      bool isSymLink() const;
+
       /// This function determines if the path name references a readable file
       /// or directory in the file system. This function checks for
       /// the existence and readability (by the current program) of the file
index d5b7542757da7b2524166b00d30b9cbc6cc357ce..5ee3adc4d2d4441ff58a26396cb847a520dc286d 100644 (file)
@@ -433,6 +433,15 @@ Path::isDirectory() const {
   return ((buf.st_mode & S_IFMT) == S_IFDIR) ? true : false;
 }
 
+bool
+Path::isSymLink() const {
+  struct stat buf;
+  if (0 != lstat(path.c_str(), &buf))
+    return false;
+  return S_ISLNK(buf.st_mode);
+}
+
+
 bool
 Path::canRead() const {
   return 0 == access(path.c_str(), R_OK);
index 2ead80127b3a14159be691cccb7a6c19e9fd28f6..4db7696b49ed92d28b6df43afd29c58814a6046c 100644 (file)
@@ -350,6 +350,11 @@ Path::isDirectory() const {
          (attr & FILE_ATTRIBUTE_DIRECTORY);
 }
 
+bool
+Path::isSymLink() const {
+  return false;
+}
+
 bool
 Path::canRead() const {
   // FIXME: take security attributes into account.