[llvm-commits] CVS: llvm/include/Support/FileUtilities.h

Chris Lattner lattner at cs.uiuc.edu
Mon Dec 29 15:36:06 PST 2003


Changes in directory llvm/include/Support:

FileUtilities.h updated: 1.9 -> 1.10

---
Log message:

Factor FDHandle out of the bytecode reader into the FileUtilities.h support 
routines.


---
Diffs of the changes:  (+21 -0)

Index: llvm/include/Support/FileUtilities.h
diff -u llvm/include/Support/FileUtilities.h:1.9 llvm/include/Support/FileUtilities.h:1.10
--- llvm/include/Support/FileUtilities.h:1.9	Sun Nov 23 23:28:39 2003
+++ llvm/include/Support/FileUtilities.h	Mon Dec 29 15:35:04 2003
@@ -102,6 +102,27 @@
 ///
 bool MakeFileReadable (const std::string & Filename);
 
+
+/// FDHandle - Simple handle class to make sure a file descriptor gets closed
+/// when the object is destroyed.
+///
+class FDHandle {
+  int FD;
+  FDHandle(const FDHandle &);      // DO NOT IMPLEMENT
+  void operator=(const FDHandle&); // DO NOT IMPLEMENT
+public:
+  FDHandle() : FD(-1) {}
+  FDHandle(int fd) : FD(fd) {}
+  ~FDHandle();
+
+  operator int() const { return FD; }
+
+  FDHandle &operator=(int fd);
+
+  /// take - Take ownership of the file descriptor away from the FDHandle
+  /// object, so that the file is not closed when the FDHandle is destroyed.
+  int take();
+};
 } // End llvm namespace
 
 #endif





More information about the llvm-commits mailing list