aboutsummaryrefslogtreecommitdiffstats
path: root/src/input/plugins/FileInputPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-10-02 18:38:33 +0200
committerMax Kellermann <max@duempel.org>2014-10-02 20:44:03 +0200
commit0d38bd9b3bf9b978c3e9a08324ff8ea764a530bd (patch)
treeccadf4b65e17565a5db9a27e3046d4a49a0700a5 /src/input/plugins/FileInputPlugin.cxx
parent2f02e49b9f353d8c0e75711308f88e98e1a6a97c (diff)
downloadmpd-0d38bd9b3bf9b978c3e9a08324ff8ea764a530bd.tar.gz
mpd-0d38bd9b3bf9b978c3e9a08324ff8ea764a530bd.tar.xz
mpd-0d38bd9b3bf9b978c3e9a08324ff8ea764a530bd.zip
input/file: export function OpenFileInputStream()
Diffstat (limited to '')
-rw-r--r--src/input/plugins/FileInputPlugin.cxx39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/input/plugins/FileInputPlugin.cxx b/src/input/plugins/FileInputPlugin.cxx
index e12439cd3..1f9cf6edd 100644
--- a/src/input/plugins/FileInputPlugin.cxx
+++ b/src/input/plugins/FileInputPlugin.cxx
@@ -23,7 +23,8 @@
#include "../InputPlugin.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
-#include "fs/Traits.hxx"
+#include "fs/FileSystem.hxx"
+#include "fs/Path.hxx"
#include "system/fd_util.h"
#include "open.h"
@@ -60,31 +61,29 @@ public:
bool Seek(offset_type offset, Error &error) override;
};
-static InputStream *
-input_file_open(const char *filename,
- Mutex &mutex, Cond &cond,
- Error &error)
+InputStream *
+OpenFileInputStream(Path path,
+ Mutex &mutex, Cond &cond,
+ Error &error)
{
- if (!PathTraitsFS::IsAbsolute(filename))
- return nullptr;
-
- const int fd = open_cloexec(filename, O_RDONLY|O_BINARY, 0);
+ const int fd = OpenFile(path, O_RDONLY|O_BINARY, 0);
if (fd < 0) {
if (errno != ENOTDIR)
error.FormatErrno("Failed to open \"%s\"",
- filename);
+ path.c_str());
return nullptr;
}
struct stat st;
if (fstat(fd, &st) < 0) {
- error.FormatErrno("Failed to stat \"%s\"", filename);
+ error.FormatErrno("Failed to stat \"%s\"", path.c_str());
close(fd);
return nullptr;
}
if (!S_ISREG(st.st_mode)) {
- error.Format(file_domain, "Not a regular file: %s", filename);
+ error.Format(file_domain, "Not a regular file: %s",
+ path.c_str());
close(fd);
return nullptr;
}
@@ -93,7 +92,21 @@ input_file_open(const char *filename,
posix_fadvise(fd, (off_t)0, st.st_size, POSIX_FADV_SEQUENTIAL);
#endif
- return new FileInputStream(filename, fd, st.st_size, mutex, cond);
+ return new FileInputStream(path.c_str(), fd, st.st_size, mutex, cond);
+}
+
+static InputStream *
+input_file_open(const char *filename,
+ Mutex &mutex, Cond &cond,
+ Error &error)
+{
+ if (!PathTraitsFS::IsAbsolute(filename))
+ return nullptr;
+
+ /* TODO: the parameter is UTF-8, not filesystem charset */
+ const Path path = Path::FromFS(filename);
+
+ return OpenFileInputStream(path, mutex, cond, error);
}
bool