For PR495:
[oota-llvm.git] / lib / Debugger / FDHandle.cpp
1 //===- lib/Debugger/FDHandle.cpp - File Descriptor Handle -----------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements a class for ensuring that Unix file handles get closed.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "FDHandle.h"
15 #include <unistd.h>
16
17 using namespace llvm;
18
19 //===----------------------------------------------------------------------===//
20 // FDHandle class implementation
21 //
22
23 FDHandle::~FDHandle() throw() {
24   if (FD != -1)
25     ::close(FD);
26 }
27
28 FDHandle &FDHandle::operator=(int fd) throw() {
29   if (FD != -1)
30     ::close(FD);
31   FD = fd;
32   return *this;
33 }