about summary refs log tree commit diff
path: root/src/libnix/util.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnix/util.hh')
-rw-r--r--src/libnix/util.hh37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/libnix/util.hh b/src/libnix/util.hh
index 016289176be8..02a9b7fcb885 100644
--- a/src/libnix/util.hh
+++ b/src/libnix/util.hh
@@ -6,6 +6,8 @@
 #include <set>
 #include <sstream>
 
+#include <sys/types.h>
+#include <dirent.h>
 #include <unistd.h>
 
 #include <boost/format.hpp>
@@ -113,4 +115,39 @@ void readFull(int fd, unsigned char * buf, size_t count);
 void writeFull(int fd, const unsigned char * buf, size_t count);
 
 
+/* Automatic cleanup of resources. */
+
+class AutoDelete
+{
+    string path;
+    bool del;
+public:
+    AutoDelete(const string & p);
+    ~AutoDelete();
+    void cancel();
+};
+
+class AutoCloseFD
+{
+    int fd;
+public:
+    AutoCloseFD();
+    AutoCloseFD(int fd);
+    ~AutoCloseFD();
+    void operator =(int fd);
+    operator int();
+};
+
+class AutoCloseDir
+{
+    DIR * dir;
+public:
+    AutoCloseDir();
+    AutoCloseDir(DIR * dir);
+    ~AutoCloseDir();
+    void operator =(DIR * dir);
+    operator DIR *();
+};
+
+
 #endif /* !__UTIL_H */