Reid Spencer | 4618957 | 2004-12-23 21:16:46 +0000 | [diff] [blame] | 1 | //===- lib/Debugger/FDHandle.cpp - File Descriptor Handle -----------------===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | 55cf0a6 | 2004-12-22 10:24:55 +0000 | [diff] [blame] | 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. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | 55cf0a6 | 2004-12-22 10:24:55 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Reid Spencer | 4618957 | 2004-12-23 21:16:46 +0000 | [diff] [blame] | 10 | // This file implements a class for ensuring that Unix file handles get closed. |
Reid Spencer | 55cf0a6 | 2004-12-22 10:24:55 +0000 | [diff] [blame] | 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() { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 24 | if (FD != -1) |
Reid Spencer | 55cf0a6 | 2004-12-22 10:24:55 +0000 | [diff] [blame] | 25 | ::close(FD); |
| 26 | } |
| 27 | |
| 28 | FDHandle &FDHandle::operator=(int fd) throw() { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 29 | if (FD != -1) |
Reid Spencer | 55cf0a6 | 2004-12-22 10:24:55 +0000 | [diff] [blame] | 30 | ::close(FD); |
| 31 | FD = fd; |
| 32 | return *this; |
| 33 | } |