diff options
author | Max Kellermann <max@duempel.org> | 2015-03-03 17:03:21 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-03-03 17:14:30 +0100 |
commit | 40a587bbaff38bb0b60313c24b94e2ecd53b181c (patch) | |
tree | d72c9db82e0db482ebe054119460b506433e9d05 /src/fs/io/FileReader.cxx | |
parent | 818d729d8b60a682e267ac408c710f5851389d79 (diff) | |
download | mpd-40a587bbaff38bb0b60313c24b94e2ecd53b181c.tar.gz mpd-40a587bbaff38bb0b60313c24b94e2ecd53b181c.tar.xz mpd-40a587bbaff38bb0b60313c24b94e2ecd53b181c.zip |
system/FileDescriptor: new wrapper class for a file descriptor
Diffstat (limited to '')
-rw-r--r-- | src/fs/io/FileReader.cxx | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/src/fs/io/FileReader.cxx b/src/fs/io/FileReader.cxx index e4198b71a..474431ef8 100644 --- a/src/fs/io/FileReader.cxx +++ b/src/fs/io/FileReader.cxx @@ -75,17 +75,11 @@ FileReader::Close() #else -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> - FileReader::FileReader(Path _path, Error &error) - :path(_path), - fd(OpenFile(path, - O_RDONLY, - 0)) + :path(_path) { - if (fd < 0) + fd.OpenReadOnly(path.c_str()); + if (!fd.IsDefined()) error.FormatErrno("Failed to open %s", path.c_str()); } @@ -94,7 +88,7 @@ FileReader::Read(void *data, size_t size, Error &error) { assert(IsDefined()); - ssize_t nbytes = read(fd, data, size); + ssize_t nbytes = fd.Read(data, size); if (nbytes < 0) { error.FormatErrno("Failed to read from %s", path.c_str()); nbytes = 0; @@ -108,7 +102,7 @@ FileReader::Seek(off_t offset, Error &error) { assert(IsDefined()); - auto result = lseek(fd, offset, SEEK_SET); + auto result = fd.Seek(offset); const bool success = result >= 0; if (!success) error.SetErrno("Failed to seek"); @@ -121,8 +115,7 @@ FileReader::Close() { assert(IsDefined()); - close(fd); - fd = -1; + fd.Close(); } #endif |