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

Reid Spencer reid at x10sys.com
Thu Jul 7 23:53:37 PDT 2005



Changes in directory llvm/lib/System/Unix:

Path.inc updated: 1.40 -> 1.41
---
Log message:

Two changes:
1. Use isValid() to check validity of the resulting path name in the 
   eraseSuffix even though we can't think of a case where eraseSuffix could
   possibly cause an invalid path name.
2. Rewrite isValid() to not use the deprecated realpath function any more.
   It now just uses isascii to make sure all the characters are legit.


---
Diffs of the changes:  (+11 -7)

 Path.inc |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)


Index: llvm/lib/System/Unix/Path.inc
diff -u llvm/lib/System/Unix/Path.inc:1.40 llvm/lib/System/Unix/Path.inc:1.41
--- llvm/lib/System/Unix/Path.inc:1.40	Fri Jul  8 00:02:13 2005
+++ llvm/lib/System/Unix/Path.inc	Fri Jul  8 01:53:26 2005
@@ -68,17 +68,18 @@
 
 bool 
 Path::isValid() const {
+  // Check some obvious things
   if (path.empty()) 
     return false;
   else if (path.length() >= MAXPATHLEN)
     return false;
-#if defined(HAVE_REALPATH)
-  char pathname[MAXPATHLEN];
-  if (0 == realpath(path.c_str(), pathname))
-    if (errno != EACCES && errno != EIO && errno != ENOENT && errno != ENOTDIR)
-      return false;
-#endif
-  return true;
+
+  // Check that the characters are ascii chars
+  size_t len = path.length();
+  unsigned i = 0;
+  while (i < len && isascii(path[i])) 
+    ++i;
+  return i >= len; 
 }
 
 Path
@@ -504,6 +505,7 @@
 
 bool
 Path::eraseSuffix() {
+  std::string save = path;
   size_t dotpos = path.rfind('.',path.size());
   size_t slashpos = path.rfind('/',path.size());
   if (dotpos != std::string::npos) {
@@ -512,6 +514,8 @@
       return true;
     }
   }
+  if (!isValid())
+    path = save;
   return false;
 }
 






More information about the llvm-commits mailing list