Fixed EOF bug for seek 0 from end
This commit is contained in:
parent
03ccac4d1f
commit
4f5244237a
@ -54,24 +54,25 @@ std::streamsize sc::io::memstreambuf::xsputn(const char* /*s*/, std::streamsize
|
||||
std::streambuf::pos_type sc::io::memstreambuf::seekoff(std::streambuf::off_type off,
|
||||
std::ios_base::seekdir dir,
|
||||
std::ios_base::openmode which) {
|
||||
uint64_t pos {0};
|
||||
if (which & std::ios::in) { // reading
|
||||
switch (dir) {
|
||||
case std::ios::beg:
|
||||
if (off < 0 || static_cast<size_t>(off) > _size) return EOF;
|
||||
setg(_mem, _mem + off, _mem + _size);
|
||||
pos = off;
|
||||
break;
|
||||
case std::ios::cur: {
|
||||
int64_t pos = gptr() - _mem + off;
|
||||
if (pos < 0 || static_cast<size_t>(pos) > _size) return EOF;
|
||||
setg(_mem, gptr() + off, _mem + _size);
|
||||
int64_t spos = gptr() - _mem + off;
|
||||
if (spos < 0 || static_cast<size_t>(spos) > _size) return EOF;
|
||||
pos = static_cast<uint64_t>(spos);
|
||||
break;
|
||||
}
|
||||
case std::ios::end:
|
||||
if (off > 0 || static_cast<size_t>(off) < -_size) return EOF;
|
||||
setg(_mem, _mem + _size + off - 1, _mem + _size);
|
||||
if (off > 0 || static_cast<std::streambuf::off_type>(_size) < -off) return EOF;
|
||||
pos = _size + off - 1;
|
||||
break;
|
||||
}
|
||||
return gptr() - _mem;
|
||||
setg(_mem, _mem + pos, _mem + _size);
|
||||
}
|
||||
if (which & std::ios::out) { // writing
|
||||
switch (dir) { // TODO
|
||||
@ -82,9 +83,8 @@ std::streambuf::pos_type sc::io::memstreambuf::seekoff(std::streambuf::off_type
|
||||
case std::ios::end:
|
||||
break;
|
||||
}
|
||||
return pptr() - _mem;
|
||||
}
|
||||
return EOF;
|
||||
return pos;
|
||||
}
|
||||
|
||||
std::streambuf::pos_type sc::io::memstreambuf::seekpos(std::streambuf::pos_type pos,
|
||||
|
Loading…
x
Reference in New Issue
Block a user