diff options
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 13 | ||||
-rw-r--r-- | src/libutil/util.hh | 3 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 0af6ee149bae..611567c12b1b 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -234,8 +234,8 @@ Path createTempDir() void writeStringToFile(const Path & path, const string & s) { - AutoCloseFD fd = open(path.c_str(), - O_CREAT | O_EXCL | O_WRONLY, 0666); + AutoCloseFD fd(open(path.c_str(), + O_CREAT | O_EXCL | O_WRONLY, 0666)); if (fd == -1) throw SysError(format("creating file `%1%'") % path); writeFull(fd, (unsigned char *) s.c_str(), s.size()); @@ -375,6 +375,12 @@ AutoCloseFD::AutoCloseFD(int fd) } +AutoCloseFD::AutoCloseFD(const AutoCloseFD & fd) +{ + abort(); +} + + AutoCloseFD::~AutoCloseFD() { try { @@ -392,7 +398,7 @@ void AutoCloseFD::operator =(int fd) } -AutoCloseFD::operator int() +AutoCloseFD::operator int() const { return fd; } @@ -401,6 +407,7 @@ AutoCloseFD::operator int() void AutoCloseFD::close() { if (fd != -1) { + debug(format("closing fd %1%") % fd); if (::close(fd) == -1) /* This should never happen. */ throw SysError("closing file descriptor"); diff --git a/src/libutil/util.hh b/src/libutil/util.hh index d947c34252a7..104e3f2651b4 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -179,9 +179,10 @@ class AutoCloseFD public: AutoCloseFD(); AutoCloseFD(int fd); + AutoCloseFD(const AutoCloseFD & fd); ~AutoCloseFD(); void operator =(int fd); - operator int(); + operator int() const; void close(); bool isOpen(); int borrow(); |