1 //===- lib/Debugger/FDHandle.h - File Descriptor Handle ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a family of utility functions which are useful for doing
11 // various things with files.
13 //===----------------------------------------------------------------------===//
15 #ifndef LIB_DEBUGGER_FDHANDLE_H
16 #define LIB_DEBUGGER_FDHANDLE_H
18 #include "llvm/System/Path.h"
22 /// FDHandle - Simple handle class to make sure a file descriptor gets closed
23 /// when the object is destroyed. This handle acts similarly to an
24 /// std::auto_ptr, in that the copy constructor and assignment operators
25 /// transfer ownership of the handle. This means that FDHandle's do not have
31 FDHandle() : FD(-1) {}
32 FDHandle(int fd) : FD(fd) {}
33 FDHandle(FDHandle &RHS) : FD(RHS.FD) {
34 RHS.FD = -1; // Transfer ownership
39 /// get - Get the current file descriptor, without releasing ownership of it.
40 int get() const { return FD; }
41 operator int() const { return FD; }
43 FDHandle &operator=(int fd) throw();
45 FDHandle &operator=(FDHandle &RHS) {
47 RHS.FD = -1; // Transfer ownership
51 /// release - Take ownership of the file descriptor away from the FDHandle
52 /// object, so that the file is not closed when the FDHandle is destroyed.
60 } // End llvm namespace