Backporting FilePiece leaked scoped_FILE, but only into the test.

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@3665 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
heafield 2010-10-27 04:04:23 +00:00
parent 34e7c43114
commit 64cfacd1bd
2 changed files with 23 additions and 0 deletions

View File

@ -9,4 +9,8 @@ scoped_fd::~scoped_fd() {
if (fd_ != -1 && close(fd_)) err(1, "Could not close file %i", fd_);
}
scoped_FILE::~scoped_FILE() {
if (file_ && fclose(file_)) err(1, "Could not close file");
}
} // namespace util

View File

@ -4,6 +4,7 @@
/* Other scoped objects in the style of scoped_ptr. */
#include <cstddef>
#include <cstdio>
namespace util {
@ -61,6 +62,24 @@ class scoped_fd {
scoped_fd &operator=(const scoped_fd &);
};
class scoped_FILE {
public:
explicit scoped_FILE(std::FILE *file = NULL) : file_(file) {}
~scoped_FILE();
std::FILE *get() { return file_; }
const std::FILE *get() const { return file_; }
void reset(std::FILE *to = NULL) {
scoped_FILE other(file_);
file_ = to;
}
private:
std::FILE *file_;
};
} // namespace util
#endif // UTIL_SCOPED__