1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 21:41:48 +02:00

* Refactoring.

This commit is contained in:
Eelco Dolstra 2004-06-15 13:49:42 +00:00
parent 1bc6afefac
commit 0b70231b9d
3 changed files with 57 additions and 83 deletions

View file

@ -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()
{

View file

@ -181,6 +181,15 @@ public:
~AutoCloseFD();
void operator =(int fd);
operator int();
void close();
bool isOpen();
};
class Pipe
{
public:
AutoCloseFD readSide, writeSide;
void create();
};
class AutoCloseDir