summaryrefslogtreecommitdiff
path: root/lib/Debugger/FDHandle.cpp
blob: c24bcb87c07b83c3ad264f83d4e3a5fe4ce64329 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//===- lib/Debugger/FDHandle.cpp - File Descriptor Handle -----------------===//
// 
//                     The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
// 
//===----------------------------------------------------------------------===//
//
// This file implements a class for ensuring that Unix file handles get closed.
//
//===----------------------------------------------------------------------===//

#include "FDHandle.h"
#include <unistd.h>

using namespace llvm;

//===----------------------------------------------------------------------===//
// FDHandle class implementation
//

FDHandle::~FDHandle() throw() {
  if (FD != -1) 
    ::close(FD);
}

FDHandle &FDHandle::operator=(int fd) throw() {
  if (FD != -1) 
    ::close(FD);
  FD = fd;
  return *this;
}