From eaf0662b75e8e074dbfe950aa9f408e4ad806bcc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 14 Jan 2015 19:43:19 +0100 Subject: fs/io/FileOutputStream: add static method Create() --- src/fs/io/FileOutputStream.cxx | 12 ++++++++++++ src/fs/io/FileOutputStream.hxx | 1 + src/output/plugins/RecorderOutputPlugin.cxx | 6 ++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/fs/io/FileOutputStream.cxx b/src/fs/io/FileOutputStream.cxx index 7a6416557..11b5b2351 100644 --- a/src/fs/io/FileOutputStream.cxx +++ b/src/fs/io/FileOutputStream.cxx @@ -22,6 +22,18 @@ #include "fs/FileSystem.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 FileOutputStream::FileOutputStream(Path _path, Error &error) diff --git a/src/fs/io/FileOutputStream.hxx b/src/fs/io/FileOutputStream.hxx index 03d062134..f66554ec9 100644 --- a/src/fs/io/FileOutputStream.hxx +++ b/src/fs/io/FileOutputStream.hxx @@ -58,6 +58,7 @@ public: Cancel(); } + static FileOutputStream *Create(Path path, Error &error); bool IsDefined() const { #ifdef WIN32 diff --git a/src/output/plugins/RecorderOutputPlugin.cxx b/src/output/plugins/RecorderOutputPlugin.cxx index f6508e33c..22915e39f 100644 --- a/src/output/plugins/RecorderOutputPlugin.cxx +++ b/src/output/plugins/RecorderOutputPlugin.cxx @@ -167,11 +167,9 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error) { /* create the output file */ - file = new FileOutputStream(path, error); - if (!file->IsDefined()) { - delete file; + file = FileOutputStream::Create(path, error); + if (file == nullptr) return false; - } /* open the encoder */ -- cgit v1.2.3