[llvm-commits] CVS: llvm/lib/System/Unix/Path.inc

Misha Brukman brukman at cs.uiuc.edu
Tue Apr 19 21:04:18 PDT 2005



Changes in directory llvm/lib/System/Unix:

Path.inc updated: 1.30 -> 1.31
---
Log message:

Ignore dangling symlinks in getDirectoryContents()
Thanks to Markus Oberhumer for the patch!


---
Diffs of the changes:  (+8 -3)

 Path.inc |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)


Index: llvm/lib/System/Unix/Path.inc
diff -u llvm/lib/System/Unix/Path.inc:1.30 llvm/lib/System/Unix/Path.inc:1.31
--- llvm/lib/System/Unix/Path.inc:1.30	Tue Mar  1 23:45:56 2005
+++ llvm/lib/System/Unix/Path.inc	Tue Apr 19 23:04:07 2005
@@ -398,17 +398,22 @@
 
   result.clear();
   struct dirent* de = ::readdir(direntries);
-  while (de != 0) {
+  for ( ; de != 0; de = ::readdir(direntries)) {
     if (de->d_name[0] != '.') {
       Path aPath(path + (const char*)de->d_name);
       struct stat buf;
-      if (0 != stat(aPath.path.c_str(), &buf))
+      if (0 != stat(aPath.path.c_str(), &buf)) {
+        int saved_errno = errno;
+        struct stat st;
+        if (0 == lstat(aPath.path.c_str(), &st) && S_ISLNK(st.st_mode))
+          continue; // dangling symlink -- ignore
+        errno = saved_errno;
         ThrowErrno(aPath.path + ": can't get status");
+      }
       if (S_ISDIR(buf.st_mode))
         aPath.path += "/";
       result.insert(aPath);
     }
-    de = ::readdir(direntries);
   }
   
   closedir(direntries);






More information about the llvm-commits mailing list