summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianhao Chai <cth451@gmail.com>2021-08-21 21:46:35 -0500
committerliushuyu <liushuyu011@gmail.com>2021-08-24 15:49:49 -0600
commit0b60970d5a332a2af569f26fd3b8fb5cff34e036 (patch)
tree9ad17addeec352524b8df6a715562cc0c789366f
parente8ad2c11ae93d0207465515d91960713bc241f2e (diff)
downloadakode-0b60970d5a332a2af569f26fd3b8fb5cff34e036.tar.gz
akode-0b60970d5a332a2af569f26fd3b8fb5cff34e036.zip
file abstraction: actually follow lseek semantics
Signed-off-by: Tianhao Chai <cth451@aosc.io>
-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;