1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 22:01:15 +02:00

* Some wrapper classes to ensure that file descriptors / directory

handles are closed when they go out of scope.
This commit is contained in:
Eelco Dolstra 2003-10-22 10:48:22 +00:00
parent c62433751d
commit 4a8948b7a6
6 changed files with 123 additions and 56 deletions

View file

@ -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 */