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

Reid Spencer reid at x10sys.com
Wed Aug 23 00:31:05 PDT 2006



Changes in directory llvm/lib/System/Unix:

Path.inc updated: 1.56 -> 1.57
Unix.h updated: 1.16 -> 1.17
---
Log message:

For PR797: http://llvm.org/PR797 :
Eliminate exception throwing from Path::renamePathOnDisk and adjust its 
users correspondingly.


---
Diffs of the changes:  (+24 -36)

 Path.inc |   55 +++++++++++++++++++++----------------------------------
 Unix.h   |    5 +++--
 2 files changed, 24 insertions(+), 36 deletions(-)


Index: llvm/lib/System/Unix/Path.inc
diff -u llvm/lib/System/Unix/Path.inc:1.56 llvm/lib/System/Unix/Path.inc:1.57
--- llvm/lib/System/Unix/Path.inc:1.56	Wed Aug 23 01:56:27 2006
+++ llvm/lib/System/Unix/Path.inc	Wed Aug 23 02:30:48 2006
@@ -391,36 +391,28 @@
 }
 
 bool Path::makeReadableOnDisk(std::string* ErrMsg) {
-  if (!AddPermissionBits(*this, 0444)) {
-    MakeErrMsg(ErrMsg, path + ": can't make file readable");
-    return true;
-  }
+  if (!AddPermissionBits(*this, 0444)) 
+    return MakeErrMsg(ErrMsg, path + ": can't make file readable");
   return false;
 }
 
 bool Path::makeWriteableOnDisk(std::string* ErrMsg) {
-  if (!AddPermissionBits(*this, 0222)) {
-    MakeErrMsg(ErrMsg, path + ": can't make file writable");
-    return true;
-  }
+  if (!AddPermissionBits(*this, 0222))
+    return MakeErrMsg(ErrMsg, path + ": can't make file writable");
   return false;
 }
 
 bool Path::makeExecutableOnDisk(std::string* ErrMsg) {
-  if (!AddPermissionBits(*this, 0111)) {
-    MakeErrMsg(ErrMsg, path + ": can't make file executable");
-    return true;
-  }
+  if (!AddPermissionBits(*this, 0111))
+    return MakeErrMsg(ErrMsg, path + ": can't make file executable");
   return false;
 }
 
 bool
 Path::getDirectoryContents(std::set<Path>& result, std::string* ErrMsg) const {
   DIR* direntries = ::opendir(path.c_str());
-  if (direntries == 0) {
-    MakeErrMsg(ErrMsg, path + ": can't open directory");
-    return true;
-  }
+  if (direntries == 0)
+    return MakeErrMsg(ErrMsg, path + ": can't open directory");
 
   std::string dirPath = path;
   if (!lastIsSlash(dirPath))
@@ -435,8 +427,8 @@
       if (0 != lstat(aPath.path.c_str(), &st)) {
         if (S_ISLNK(st.st_mode))
           continue; // dangling symlink -- ignore
-        MakeErrMsg(ErrMsg, aPath.path +  ": can't determine file object type");
-        return true;
+        return MakeErrMsg(ErrMsg, 
+                          aPath.path +  ": can't determine file object type");
       }
       result.insert(aPath);
     }
@@ -544,9 +536,8 @@
       *next = 0;
       if (0 != access(pathname, F_OK | R_OK | W_OK))
         if (0 != mkdir(pathname, S_IRWXU | S_IRWXG)) {
-          MakeErrMsg(ErrMsg, 
-            std::string(pathname) + ": can't create directory");
-          return true;
+          return MakeErrMsg(ErrMsg, 
+                            std::string(pathname) + ": can't create directory");
         }
       char* save = next;
       next = strchr(next+1,'/');
@@ -556,8 +547,8 @@
 
   if (0 != access(pathname, F_OK | R_OK))
     if (0 != mkdir(pathname, S_IRWXU | S_IRWXG)) {
-      MakeErrMsg(ErrMsg, std::string(pathname) + ": can't create directory");
-      return true;
+      return MakeErrMsg(ErrMsg, 
+                        std::string(pathname) + ": can't create directory");
     }
   return false;
 }
@@ -566,10 +557,8 @@
 Path::createFileOnDisk(std::string* ErrMsg) {
   // Create the file
   int fd = ::creat(path.c_str(), S_IRUSR | S_IWUSR);
-  if (fd < 0) {
-    MakeErrMsg(ErrMsg, path + ": can't create file");
-    return true;
-  }
+  if (fd < 0)
+    return MakeErrMsg(ErrMsg, path + ": can't create file");
   ::close(fd);
   return false;
 }
@@ -581,10 +570,8 @@
 
   // create the file
   int fd = ::open(path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
-  if (fd < 0) {
-    MakeErrMsg(ErrMsg, path + ": can't create temporary file");
-    return true;
-  }
+  if (fd < 0) 
+    return MakeErrMsg(ErrMsg, path + ": can't create temporary file");
   ::close(fd);
   return false;
 }
@@ -633,11 +620,11 @@
 }
 
 bool
-Path::renamePathOnDisk(const Path& newName) {
+Path::renamePathOnDisk(const Path& newName, std::string* ErrMsg) {
   if (0 != ::rename(path.c_str(), newName.c_str()))
-    ThrowErrno(std::string("can't rename '") + path + "' as '" + 
+    return MakeErrMsg(ErrMsg, std::string("can't rename '") + path + "' as '" + 
                newName.toString() + "' ");
-  return true;
+  return false;
 }
 
 bool


Index: llvm/lib/System/Unix/Unix.h
diff -u llvm/lib/System/Unix/Unix.h:1.16 llvm/lib/System/Unix/Unix.h:1.17
--- llvm/lib/System/Unix/Unix.h:1.16	Mon Aug 21 01:02:44 2006
+++ llvm/lib/System/Unix/Unix.h	Wed Aug 23 02:30:48 2006
@@ -123,10 +123,10 @@
 /// string and the Unix error number given by \p errnum. If errnum is -1, the
 /// default then the value of errno is used.
 /// @brief Make an error message
-inline void MakeErrMsg(
+inline bool MakeErrMsg(
   std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
   if (!ErrMsg)
-    return;
+    return true;
   char buffer[MAXPATHLEN];
   buffer[0] = 0;
   if (errnum == -1)
@@ -148,6 +148,7 @@
   sprintf(buffer, "Error #%d", errnum);
 #endif
   *ErrMsg = buffer;
+  return true;
 }
 
 #endif






More information about the llvm-commits mailing list