diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-10-22T10·48+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-10-22T10·48+0000 |
commit | 4a8948b7a60e751dd809f279f1baa434ea09a4d3 (patch) | |
tree | 3c8475fe2280f2e48654f287c46edc580bf4382c /src/libnix/references.cc | |
parent | c62433751d5fce8c25a802989c50fee993f39c2d (diff) |
* Some wrapper classes to ensure that file descriptors / directory
handles are closed when they go out of scope.
Diffstat (limited to 'src/libnix/references.cc')
-rw-r--r-- | src/libnix/references.cc | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/libnix/references.cc b/src/libnix/references.cc index be432665b884..ab743f76d2d3 100644 --- a/src/libnix/references.cc +++ b/src/libnix/references.cc @@ -36,7 +36,7 @@ void checkPath(const string & path, throw SysError(format("getting attributes of path `%1%'") % path); if (S_ISDIR(st.st_mode)) { - DIR * dir = opendir(path.c_str()); + AutoCloseDir dir = opendir(path.c_str()); struct dirent * dirent; while (errno = 0, dirent = readdir(dir)) { @@ -45,15 +45,13 @@ void checkPath(const string & path, search(name, ids, seen); checkPath(path + "/" + name, ids, seen); } - - closedir(dir); /* !!! close on exception */ } else if (S_ISREG(st.st_mode)) { debug(format("checking `%1%'") % path); - int fd = open(path.c_str(), O_RDONLY); + AutoCloseFD fd = open(path.c_str(), O_RDONLY); if (fd == -1) throw SysError(format("opening file `%1%'") % path); unsigned char * buf = new unsigned char[st.st_size]; @@ -63,8 +61,6 @@ void checkPath(const string & path, search(string((char *) buf, st.st_size), ids, seen); delete buf; /* !!! autodelete */ - - close(fd); /* !!! close on exception */ } else if (S_ISLNK(st.st_mode)) { |