mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 22:14:57 +03:00
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:
parent
34e7c43114
commit
64cfacd1bd
@ -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
|
||||
|
@ -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__
|
||||
|
Loading…
Reference in New Issue
Block a user