Small adjustments

This commit is contained in:
topjohnwu 2019-11-21 06:17:28 -05:00
parent d26d804cc2
commit d3b5cf82d8
2 changed files with 8 additions and 12 deletions

View File

@ -4,7 +4,7 @@
#include <stdio.h>
#include <memory>
#include <utils.h>
// #include <utils.h>
class stream;
@ -49,7 +49,7 @@ class seekable_stream : public stream {
protected:
size_t _pos = 0;
off_t new_pos(off_t off, int whence);
off_t seek_pos(off_t off, int whence);
virtual size_t end_pos() = 0;
};

View File

@ -1,3 +1,4 @@
#include <utils.h>
#include <logging.h>
#include <stream.h>
@ -68,22 +69,17 @@ void filter_stream::set_base(FILE *f) {
fp = f;
}
off_t seekable_stream::new_pos(off_t off, int whence) {
off_t new_pos;
off_t seekable_stream::seek_pos(off_t off, int whence) {
switch (whence) {
case SEEK_CUR:
new_pos = _pos + off;
break;
return _pos + off;
case SEEK_END:
new_pos = end_pos() + off;
break;
return end_pos() + off;
case SEEK_SET:
new_pos = off;
break;
return off;
default:
return -1;
}
return new_pos;
}
byte_stream::byte_stream(uint8_t *&buf, size_t &len) : _buf(buf), _len(len) {
@ -106,7 +102,7 @@ int byte_stream::write(const void *buf, size_t len) {
}
off_t byte_stream::seek(off_t off, int whence) {
off_t np = new_pos(off, whence);
off_t np = seek_pos(off, whence);
if (np < 0)
return -1;
resize(np, true);