diff options
author | Chris Lattner <sabre@nondot.org> | 2003-12-29 21:35:05 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-12-29 21:35:05 +0000 |
commit | 2d6481cc2a168c4a867f8046119607f72552ef31 (patch) | |
tree | 36f57f499b30326aab5c8aef51b8275d167b3011 /include/llvm/Support/FileUtilities.h | |
parent | 872ccce0a801930aa370f8d161ceb9d6b1a3bdae (diff) |
Factor FDHandle out of the bytecode reader into the FileUtilities.h support
routines.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10642 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/FileUtilities.h')
-rw-r--r-- | include/llvm/Support/FileUtilities.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/llvm/Support/FileUtilities.h b/include/llvm/Support/FileUtilities.h index 4c02605400..a6a1dc2456 100644 --- a/include/llvm/Support/FileUtilities.h +++ b/include/llvm/Support/FileUtilities.h @@ -102,6 +102,27 @@ bool MakeFileExecutable (const std::string & Filename); /// 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 |