aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc46
-rw-r--r--src/libutil/util.hh15
2 files changed, 8 insertions, 53 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 0e1849df0..961c14e3a 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -234,11 +234,11 @@ DirEntries readDirectory(const Path & path)
DirEntries entries;
entries.reserve(64);
- AutoCloseDir dir = opendir(path.c_str());
+ AutoCloseDir dir(opendir(path.c_str()));
if (!dir) throw SysError(format("opening directory ‘%1%’") % path);
struct dirent * dirent;
- while (errno = 0, dirent = readdir(dir)) { /* sic */
+ while (errno = 0, dirent = readdir(dir.get())) { /* sic */
checkInterrupt();
string name = dirent->d_name;
if (name == "." || name == "..") continue;
@@ -645,48 +645,6 @@ void Pipe::create()
//////////////////////////////////////////////////////////////////////
-AutoCloseDir::AutoCloseDir()
-{
- dir = 0;
-}
-
-
-AutoCloseDir::AutoCloseDir(DIR * dir)
-{
- this->dir = dir;
-}
-
-
-AutoCloseDir::~AutoCloseDir()
-{
- close();
-}
-
-
-void AutoCloseDir::operator =(DIR * dir)
-{
- this->dir = dir;
-}
-
-
-AutoCloseDir::operator DIR *()
-{
- return dir;
-}
-
-
-void AutoCloseDir::close()
-{
- if (dir) {
- closedir(dir);
- dir = 0;
- }
-}
-
-
-//////////////////////////////////////////////////////////////////////
-
-
Pid::Pid()
: pid(-1), separatePG(false), killSignal(SIGKILL)
{
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index d42099781..679c3a1b6 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -180,18 +180,15 @@ public:
};
-class AutoCloseDir
+struct DIRDeleter
{
- DIR * dir;
-public:
- AutoCloseDir();
- AutoCloseDir(DIR * dir);
- ~AutoCloseDir();
- void operator =(DIR * dir);
- operator DIR *();
- void close();
+ void operator()(DIR * dir) const {
+ closedir(dir);
+ }
};
+typedef std::unique_ptr<DIR, DIRDeleter> AutoCloseDir;
+
class Pid
{