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

Jeff Cohen jeffc at jolt-lang.org
Wed Jan 26 19:49:14 PST 2005



Changes in directory llvm/lib/System/Win32:

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

Fix some Path bugs

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

 Path.inc |   35 ++++++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 11 deletions(-)


Index: llvm/lib/System/Win32/Path.inc
diff -u llvm/lib/System/Win32/Path.inc:1.29 llvm/lib/System/Win32/Path.inc:1.30
--- llvm/lib/System/Win32/Path.inc:1.29	Sat Jan 22 10:28:33 2005
+++ llvm/lib/System/Win32/Path.inc	Wed Jan 26 21:49:03 2005
@@ -347,9 +347,10 @@
 
   result.clear();
   WIN32_FIND_DATA fd;
-  HANDLE h = FindFirstFile(path.c_str(), &fd);
+  std::string searchpath = path + "*";
+  HANDLE h = FindFirstFile(searchpath.c_str(), &fd);
   if (h == INVALID_HANDLE_VALUE) {
-    if (GetLastError() == ERROR_NO_MORE_FILES)
+    if (GetLastError() == ERROR_FILE_NOT_FOUND)
       return true; // not really an error, now is it?
     ThrowError(path + ": Can't read directory: ");
   }
@@ -607,7 +608,7 @@
           aPath.destroyFile();
       }
     } else {
-      if (GetLastError() != ERROR_NO_MORE_FILES)
+      if (GetLastError() != ERROR_FILE_NOT_FOUND)
         ThrowError(path + ": Can't read directory: ");
     }
   }
@@ -742,15 +743,19 @@
   if (reuse_current && !exists())
     return; // File doesn't exist already, just use it!
 
-  Path dir (*this);
-  dir.elideFile();
-  std::string fname = this->getLast();
-
-  char newName[MAX_PATH + 1];
-  if (!GetTempFileName(dir.c_str(), fname.c_str(), 0, newName))
-    ThrowError("Cannot make unique filename for '" + path + "': ");
+  // Reserve space for -XXXXXX at the end.
+  char *FNBuffer = (char*) alloca(path.size()+8);
+  unsigned offset = path.size();
+  path.copy(FNBuffer, offset);
 
-  path = newName;
+  // Find a numeric suffix that isn't used by an existing file.
+  static unsigned FCounter = 0;
+  do {
+    sprintf(FNBuffer+offset, "-%06u", FCounter);
+    if (++FCounter > 999999)
+      FCounter = 0;
+    path = FNBuffer;
+  } while (exists());
 }
 
 bool
@@ -761,6 +766,14 @@
 
   // Make this into a unique file name
   makeUnique( reuse_current );
+
+  // Now go and create it
+  HANDLE h = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW,
+                        FILE_ATTRIBUTE_NORMAL, NULL);
+  if (h == INVALID_HANDLE_VALUE)
+    return false;
+
+  CloseHandle(h);
   return true;
 }
 






More information about the llvm-commits mailing list