aboutsummaryrefslogtreecommitdiffstats
path: root/src/input/plugins
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-05-22 10:10:16 +0200
committerMax Kellermann <max@duempel.org>2014-05-22 13:52:00 +0200
commit07b93dcf8084bcae92fa1f33652723ca9c990db2 (patch)
tree5cfa3d13c14d68b70d54ade24169b84a7f614b8e /src/input/plugins
parent374c6a27db790eb637feaeb9bd27ed82897d7953 (diff)
downloadmpd-07b93dcf8084bcae92fa1f33652723ca9c990db2.tar.gz
mpd-07b93dcf8084bcae92fa1f33652723ca9c990db2.tar.xz
mpd-07b93dcf8084bcae92fa1f33652723ca9c990db2.zip
InputStream: make Seek() always absolute
Remove the "whence" parameter that is not actually necessary, and only complicates the InputStream implementations.
Diffstat (limited to '')
-rw-r--r--src/input/plugins/CdioParanoiaInputPlugin.cxx17
-rw-r--r--src/input/plugins/CurlInputPlugin.cxx27
-rw-r--r--src/input/plugins/FfmpegInputPlugin.cxx6
-rw-r--r--src/input/plugins/FileInputPlugin.cxx8
-rw-r--r--src/input/plugins/NfsInputPlugin.cxx6
-rw-r--r--src/input/plugins/RewindInputPlugin.cxx9
-rw-r--r--src/input/plugins/SmbclientInputPlugin.cxx7
7 files changed, 21 insertions, 59 deletions
diff --git a/src/input/plugins/CdioParanoiaInputPlugin.cxx b/src/input/plugins/CdioParanoiaInputPlugin.cxx
index 534084e0d..6f1ea976a 100644
--- a/src/input/plugins/CdioParanoiaInputPlugin.cxx
+++ b/src/input/plugins/CdioParanoiaInputPlugin.cxx
@@ -99,7 +99,7 @@ class CdioParanoiaInputStream final : public InputStream {
/* virtual methods from InputStream */
bool IsEOF() override;
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
static constexpr Domain cdio_domain("cdio");
@@ -272,21 +272,8 @@ input_cdio_open(const char *uri,
}
bool
-CdioParanoiaInputStream::Seek(InputPlugin::offset_type new_offset,
- int whence, Error &error)
+CdioParanoiaInputStream::Seek(offset_type new_offset, Error &error)
{
- /* calculate absolute offset */
- switch (whence) {
- case SEEK_SET:
- break;
- case SEEK_CUR:
- new_offset += offset;
- break;
- case SEEK_END:
- new_offset += size;
- break;
- }
-
if (new_offset < 0 || new_offset > size) {
error.Format(cdio_domain, "Invalid offset to seek %ld (%ld)",
(long int)new_offset, (long int)size);
diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx
index dc26e0aa2..e464a3ce0 100644
--- a/src/input/plugins/CurlInputPlugin.cxx
+++ b/src/input/plugins/CurlInputPlugin.cxx
@@ -175,7 +175,7 @@ struct CurlInputStream final : public InputStream {
}
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
class CurlMulti;
@@ -887,12 +887,11 @@ CurlInputStream::InitEasy(Error &error)
}
inline bool
-CurlInputStream::Seek(InputPlugin::offset_type new_offset, int whence,
- Error &error)
+CurlInputStream::Seek(offset_type new_offset, Error &error)
{
assert(IsReady());
- if (whence == SEEK_SET && new_offset == offset)
+ if (new_offset == offset)
/* no-op */
return true;
@@ -901,26 +900,6 @@ CurlInputStream::Seek(InputPlugin::offset_type new_offset, int whence,
/* calculate the absolute offset */
- switch (whence) {
- case SEEK_SET:
- break;
-
- case SEEK_CUR:
- new_offset += offset;
- break;
-
- case SEEK_END:
- if (size < 0)
- /* stream size is not known */
- return false;
-
- new_offset += size;
- break;
-
- default:
- return false;
- }
-
if (new_offset < 0)
return false;
diff --git a/src/input/plugins/FfmpegInputPlugin.cxx b/src/input/plugins/FfmpegInputPlugin.cxx
index 9ae07dbef..6e0260aee 100644
--- a/src/input/plugins/FfmpegInputPlugin.cxx
+++ b/src/input/plugins/FfmpegInputPlugin.cxx
@@ -60,7 +60,7 @@ struct FfmpegInputStream final : public InputStream {
/* virtual methods from InputStream */
bool IsEOF() override;
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
static constexpr Domain ffmpeg_domain("ffmpeg");
@@ -134,9 +134,9 @@ FfmpegInputStream::IsEOF()
}
bool
-FfmpegInputStream::Seek(offset_type new_offset, int whence, Error &error)
+FfmpegInputStream::Seek(offset_type new_offset, Error &error)
{
- int64_t ret = avio_seek(h, new_offset, whence);
+ int64_t ret = avio_seek(h, new_offset, SEEK_SET);
if (ret >= 0) {
eof = false;
diff --git a/src/input/plugins/FileInputPlugin.cxx b/src/input/plugins/FileInputPlugin.cxx
index 1035973b6..60c316567 100644
--- a/src/input/plugins/FileInputPlugin.cxx
+++ b/src/input/plugins/FileInputPlugin.cxx
@@ -56,7 +56,7 @@ struct FileInputStream final : public InputStream {
}
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
static InputStream *
@@ -99,11 +99,9 @@ input_file_open(const char *filename,
}
bool
-FileInputStream::Seek(InputPlugin::offset_type new_offset, int whence,
- Error &error)
+FileInputStream::Seek(offset_type new_offset, Error &error)
{
- new_offset = (InputPlugin::offset_type)lseek(fd, (off_t)new_offset,
- whence);
+ new_offset = (offset_type)lseek(fd, (off_t)new_offset, SEEK_SET);
if (new_offset < 0) {
error.SetErrno("Failed to seek");
return false;
diff --git a/src/input/plugins/NfsInputPlugin.cxx b/src/input/plugins/NfsInputPlugin.cxx
index b73389662..c90f00257 100644
--- a/src/input/plugins/NfsInputPlugin.cxx
+++ b/src/input/plugins/NfsInputPlugin.cxx
@@ -61,7 +61,7 @@ public:
}
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
size_t
@@ -77,10 +77,10 @@ NfsInputStream::Read(void *ptr, size_t read_size, Error &error)
}
bool
-NfsInputStream::Seek(offset_type new_offset, int whence, Error &error)
+NfsInputStream::Seek(offset_type new_offset, Error &error)
{
uint64_t current_offset;
- int result = nfs_lseek(ctx, fh, new_offset, whence,
+ int result = nfs_lseek(ctx, fh, new_offset, SEEK_SET,
&current_offset);
if (result < 0) {
error.SetErrno(-result, "smbc_lseek() failed");
diff --git a/src/input/plugins/RewindInputPlugin.cxx b/src/input/plugins/RewindInputPlugin.cxx
index c18799c64..95f604044 100644
--- a/src/input/plugins/RewindInputPlugin.cxx
+++ b/src/input/plugins/RewindInputPlugin.cxx
@@ -64,7 +64,7 @@ public:
}
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
private:
/**
@@ -117,13 +117,12 @@ RewindInputStream::Read(void *ptr, size_t read_size, Error &error)
}
bool
-RewindInputStream::Seek(offset_type new_offset, int whence,
+RewindInputStream::Seek(offset_type new_offset,
Error &error)
{
assert(IsReady());
- if (whence == SEEK_SET && tail > 0 &&
- new_offset <= (offset_type)tail) {
+ if (tail > 0 && new_offset <= (offset_type)tail) {
/* buffered seek */
assert(!ReadingFromBuffer() ||
@@ -139,7 +138,7 @@ RewindInputStream::Seek(offset_type new_offset, int whence,
buffered range now */
tail = 0;
- return ProxyInputStream::Seek(new_offset, whence, error);
+ return ProxyInputStream::Seek(new_offset, error);
}
}
diff --git a/src/input/plugins/SmbclientInputPlugin.cxx b/src/input/plugins/SmbclientInputPlugin.cxx
index aa1ba0381..79987180f 100644
--- a/src/input/plugins/SmbclientInputPlugin.cxx
+++ b/src/input/plugins/SmbclientInputPlugin.cxx
@@ -57,7 +57,7 @@ public:
}
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
/*
@@ -136,11 +136,10 @@ SmbclientInputStream::Read(void *ptr, size_t read_size, Error &error)
}
bool
-SmbclientInputStream::Seek(InputStream::offset_type new_offset,
- int whence, Error &error)
+SmbclientInputStream::Seek(offset_type new_offset, Error &error)
{
smbclient_mutex.lock();
- off_t result = smbc_lseek(fd, new_offset, whence);
+ off_t result = smbc_lseek(fd, new_offset, SEEK_SET);
smbclient_mutex.unlock();
if (result < 0) {
error.SetErrno("smbc_lseek() failed");