diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-06-15T13·49+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-06-15T13·49+0000 |
commit | 0b70231b9d9f2dfa5a9447fcd01fdb5c8f1fa0ea (patch) | |
tree | 5c37a0080ddd82f409a2695a2bf830608b706d40 /src/libutil/util.cc | |
parent | 1bc6afefac7af8d4c917e898d6670d9b9d7f29f1 (diff) |
* Refactoring.
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r-- | src/libutil/util.cc | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 399233983d62..676404ecfca6 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -365,11 +365,16 @@ AutoCloseFD::AutoCloseFD(int fd) AutoCloseFD::~AutoCloseFD() { - if (fd != -1) close(fd); + try { + close(); + } catch (Error & e) { + printMsg(lvlError, format("error (ignored): %1%") % e.msg()); + } } void AutoCloseFD::operator =(int fd) { + if (this->fd != fd) close(); this->fd = fd; } @@ -378,6 +383,30 @@ AutoCloseFD::operator int() return fd; } +void AutoCloseFD::close() +{ + if (fd != -1) { + if (::close(fd) == -1) + /* This should never happen. */ + throw SysError("closing file descriptor"); + fd = -1; + } +} + +bool AutoCloseFD::isOpen() +{ + return fd != -1; +} + + +void Pipe::create() +{ + int fds[2]; + if (pipe(fds) != 0) throw SysError("creating pipe"); + readSide = fds[0]; + writeSide = fds[1]; +} + AutoCloseDir::AutoCloseDir() { |