Merge "Add the Release function for TemporaryFiles"
This commit is contained in:
commit
e9b3a75e6f
|
@ -26,6 +26,10 @@ class TemporaryFile {
|
|||
TemporaryFile();
|
||||
~TemporaryFile();
|
||||
|
||||
// Release the ownership of fd, caller is reponsible for closing the
|
||||
// fd or stream properly.
|
||||
int release();
|
||||
|
||||
int fd;
|
||||
char path[1024];
|
||||
|
||||
|
|
|
@ -85,10 +85,18 @@ TemporaryFile::TemporaryFile() {
|
|||
}
|
||||
|
||||
TemporaryFile::~TemporaryFile() {
|
||||
close(fd);
|
||||
if (fd != -1) {
|
||||
close(fd);
|
||||
}
|
||||
unlink(path);
|
||||
}
|
||||
|
||||
int TemporaryFile::release() {
|
||||
int result = fd;
|
||||
fd = -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
void TemporaryFile::init(const std::string& tmp_dir) {
|
||||
snprintf(path, sizeof(path), "%s%cTemporaryFile-XXXXXX", tmp_dir.c_str(),
|
||||
OS_PATH_SEPARATOR);
|
||||
|
|
Loading…
Reference in New Issue