fs/io/FileOutputStream: add static method Create()

This commit is contained in:
Max Kellermann 2015-01-14 19:43:19 +01:00
parent 6e8ea2a2cb
commit eaf0662b75
3 changed files with 15 additions and 4 deletions

View File

@ -22,6 +22,18 @@
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
FileOutputStream *
FileOutputStream::Create(Path path, Error &error)
{
FileOutputStream *f = new FileOutputStream(path, error);
if (!f->IsDefined()) {
delete f;
f = nullptr;
}
return f;
}
#ifdef WIN32 #ifdef WIN32
FileOutputStream::FileOutputStream(Path _path, Error &error) FileOutputStream::FileOutputStream(Path _path, Error &error)

View File

@ -58,6 +58,7 @@ public:
Cancel(); Cancel();
} }
static FileOutputStream *Create(Path path, Error &error);
bool IsDefined() const { bool IsDefined() const {
#ifdef WIN32 #ifdef WIN32

View File

@ -167,11 +167,9 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error)
{ {
/* create the output file */ /* create the output file */
file = new FileOutputStream(path, error); file = FileOutputStream::Create(path, error);
if (!file->IsDefined()) { if (file == nullptr)
delete file;
return false; return false;
}
/* open the encoder */ /* open the encoder */