summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianhao Chai <cth451@gmail.com>2021-08-21 21:46:35 -0500
committerMichele Calgaro <michele.calgaro@yahoo.it>2021-08-28 20:09:53 +0900
commit3904afa1ff696c64e13cf4c9c2b0b355bab8ec36 (patch)
treed25f9aac71f26e0571c17ed5b9f5a65b39edf64e
parent2abab8e1675a48b080084b643dde7b91cf7ca8a9 (diff)
downloadakode-3904afa1.tar.gz
akode-3904afa1.zip
file abstraction: actually follow lseek semantics
Signed-off-by: Tianhao Chai <cth451@aosc.io> (cherry picked from commit 0b60970d5a332a2af569f26fd3b8fb5cff34e036)
-rw-r--r--akode/lib/file.h2
-rw-r--r--akode/lib/localfile.cpp8
-rw-r--r--akode/lib/localfile.h2
-rw-r--r--akode/lib/mmapfile.cpp8
-rw-r--r--akode/lib/mmapfile.h2
5 files changed, 11 insertions, 11 deletions
diff --git a/akode/lib/file.h b/akode/lib/file.h
index 11a4fef..3685bcc 100644
--- a/akode/lib/file.h
+++ b/akode/lib/file.h
@@ -76,7 +76,7 @@ public:
* Seeks to the position.
* Behaves semantically as lseek.
*/
- virtual bool seek(long to, int whence = SEEK_SET) = 0;
+ virtual ssize_t seek(long to, int whence = SEEK_SET) = 0;
/*!
* Returns current position in file, or negative if unknown.
*/
diff --git a/akode/lib/localfile.cpp b/akode/lib/localfile.cpp
index ff92760..35ce2f3 100644
--- a/akode/lib/localfile.cpp
+++ b/akode/lib/localfile.cpp
@@ -115,11 +115,11 @@ long LocalFile::write(const char* ptr, long num) {
return n;
}
-bool LocalFile::seek(long to, int whence) {
- if(_fd == -1) return false;
- int s = ::lseek(_fd, to, whence);
+ssize_t LocalFile::seek(long to, int whence) {
+ if(_fd == -1) return -1;
+ ssize_t s = ::lseek(_fd, to, whence);
if (s >= 0) pos = s;
- return (s >= 0);
+ return s;
}
long LocalFile::position() const {
diff --git a/akode/lib/localfile.h b/akode/lib/localfile.h
index 7f7c2c2..9003e43 100644
--- a/akode/lib/localfile.h
+++ b/akode/lib/localfile.h
@@ -50,7 +50,7 @@ public:
long read(char* ptr, long num);
long write(const char* ptr, long num);
- bool seek(long to, int whence = SEEK_SET);
+ ssize_t seek(long to, int whence = SEEK_SET);
long position() const;
long length() const;
diff --git a/akode/lib/mmapfile.cpp b/akode/lib/mmapfile.cpp
index 4c45603..ec45f98 100644
--- a/akode/lib/mmapfile.cpp
+++ b/akode/lib/mmapfile.cpp
@@ -94,7 +94,7 @@ long MMapFile::write(const char*, long) {
return false;
}
-bool MMapFile::seek(long to, int whence) {
+ssize_t MMapFile::seek(long to, int whence) {
if(!handle) return false;
long newpos = 0;
@@ -109,12 +109,12 @@ bool MMapFile::seek(long to, int whence) {
newpos = len + to;
break;
default:
- return false;
+ return length();
}
if (newpos > len || newpos < 0)
- return false;
+ return -1;
pos = newpos;
- return true;
+ return newpos;
}
long MMapFile::position() const {
diff --git a/akode/lib/mmapfile.h b/akode/lib/mmapfile.h
index 80c5913..c2de99f 100644
--- a/akode/lib/mmapfile.h
+++ b/akode/lib/mmapfile.h
@@ -47,7 +47,7 @@ public:
long read(char* ptr, long num);
long write(const char*, long);
- bool seek(long to, int whence = SEEK_SET);
+ ssize_t seek(long to, int whence = SEEK_SET);
long position() const;
long length() const;