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

Reid Spencer reid at x10sys.com
Fri Jul 8 10:46:21 PDT 2005



Changes in directory llvm/lib/System/Unix:

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

Ensure that functions like isDirectory don't fail if the file doesn't
exist but just return false instead.


---
Diffs of the changes:  (+13 -1)

 Path.inc |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletion(-)


Index: llvm/lib/System/Unix/Path.inc
diff -u llvm/lib/System/Unix/Path.inc:1.41 llvm/lib/System/Unix/Path.inc:1.42
--- llvm/lib/System/Unix/Path.inc:1.41	Fri Jul  8 01:53:26 2005
+++ llvm/lib/System/Unix/Path.inc	Fri Jul  8 12:46:10 2005
@@ -231,6 +231,8 @@
 
 bool
 Path::isFile() const {
+  if (!exists())
+    return false;
   struct stat buf;
   if (0 != stat(path.c_str(), &buf)) {
     ThrowErrno(path + ": can't determine type of path object: ");
@@ -240,6 +242,8 @@
 
 bool
 Path::isDirectory() const {
+  if (!exists())
+    return false;
   struct stat buf;
   if (0 != stat(path.c_str(), &buf)) {
     ThrowErrno(path + ": can't determine type of path object: ");
@@ -249,6 +253,8 @@
 
 bool
 Path::isHidden() const {
+  if (!exists())
+    return false;
   size_t slash = path.rfind('/');
   return (slash != std::string::npos && 
           slash < path.length()-1 && 
@@ -269,6 +275,8 @@
 }
 
 bool Path::hasMagicNumber(const std::string &Magic) const {
+  if (!isFile())
+    return false;
   size_t len = Magic.size();
   assert(len < 1024 && "Request for magic string too long");
   char* buf = (char*) alloca(1 + len);
@@ -303,6 +311,8 @@
 
 bool 
 Path::isBytecodeFile() const {
+  if (!isFile())
+    return false;
   char buffer[ 4];
   buffer[0] = 0;
   int fd = ::open(path.c_str(),O_RDONLY);
@@ -334,11 +344,13 @@
 
 bool
 Path::canExecute() const {
+  if (0 != access(path.c_str(), R_OK | X_OK ))
+    return false;
   struct stat st;
   int r = stat(path.c_str(), &st);
   if (r != 0 || !S_ISREG(st.st_mode))
     return false;
-  return 0 == access(path.c_str(), R_OK | X_OK );
+  return true;
 }
 
 std::string 






More information about the llvm-commits mailing list