diff options
author | Max Kellermann <max@duempel.org> | 2015-12-16 11:05:33 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-12-18 01:08:16 +0100 |
commit | e6e7d6dbd654b9936b04f27b8153fb4ed945b9d3 (patch) | |
tree | ae4f965fd7a24ce01aad50117a5776610c861af6 /src/input | |
parent | fe60c52c70705b721bee7fbd6e3aae076a3b99c9 (diff) |
fs/io/Reader: use C++ exceptions instead of class Error
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/plugins/FileInputPlugin.cxx | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/input/plugins/FileInputPlugin.cxx b/src/input/plugins/FileInputPlugin.cxx index aa4676470..65fc830dd 100644 --- a/src/input/plugins/FileInputPlugin.cxx +++ b/src/input/plugins/FileInputPlugin.cxx @@ -61,14 +61,10 @@ InputStream * OpenFileInputStream(Path path, Mutex &mutex, Cond &cond, Error &error) -{ - FileReader reader(path, error); - if (!reader.IsDefined()) - return nullptr; +try { + FileReader reader(path); - FileInfo info; - if (!reader.GetFileInfo(info, error)) - return nullptr; + const FileInfo info = reader.GetFileInfo(); if (!info.IsRegular()) { error.Format(file_domain, "Not a regular file: %s", @@ -84,6 +80,9 @@ OpenFileInputStream(Path path, return new FileInputStream(path.ToUTF8().c_str(), std::move(reader), info.GetSize(), mutex, cond); +} catch (const std::exception &e) { + error.Set(e); + return nullptr; } static InputStream * @@ -98,23 +97,24 @@ input_file_open(gcc_unused const char *filename, bool FileInputStream::Seek(offset_type new_offset, Error &error) -{ - if (!reader.Seek((off_t)new_offset, error)) - return false; - +try { + reader.Seek((off_t)new_offset); offset = new_offset; return true; +} catch (const std::exception &e) { + error.Set(e); + return false; } size_t FileInputStream::Read(void *ptr, size_t read_size, Error &error) -{ - ssize_t nbytes = reader.Read(ptr, read_size, error); - if (nbytes < 0) - return 0; - +try { + size_t nbytes = reader.Read(ptr, read_size); offset += nbytes; - return (size_t)nbytes; + return nbytes; +} catch (const std::exception &e) { + error.Set(e); + return 0; } const InputPlugin input_plugin_file = { |