Clean up the FileStream code: Remove non-working Is_Eos() and make Seek() and Skip() return int.

This commit is contained in:
sirlemonhead 2020-05-16 20:41:45 +01:00 committed by Christoph Oelckers
parent 6f64967d00
commit 17be2617cf
4 changed files with 19 additions and 39 deletions

View file

@ -50,11 +50,10 @@ class FileStream
kSeekEnd = 2 kSeekEnd = 2
}; };
bool Seek(int32_t offset, SeekDirection = kSeekStart); int32_t Seek(int32_t offset, SeekDirection = kSeekStart);
bool Skip(int32_t offset); int32_t Skip(int32_t offset);
int32_t GetPosition(); int32_t GetPosition();
bool Is_Eos();
private: private:
FileReader file; FileReader file;

View file

@ -85,7 +85,7 @@ uint8_t FileStream::ReadByte()
return file.ReadInt8(); return file.ReadInt8();
} }
bool FileStream::Seek(int32_t offset, SeekDirection direction) int32_t FileStream::Seek(int32_t offset, SeekDirection direction)
{ {
int32_t nStatus = -1; int32_t nStatus = -1;
if (kSeekStart == direction) { if (kSeekStart == direction) {
@ -94,28 +94,18 @@ bool FileStream::Seek(int32_t offset, SeekDirection direction)
else if (kSeekCurrent == direction) { else if (kSeekCurrent == direction) {
nStatus = file.Seek(offset, FileReader::SeekCur); nStatus = file.Seek(offset, FileReader::SeekCur);
} }
else if (kSeekEnd == direction) {
nStatus = klseek(file, offset, SEEK_END);
}
// TODO - end seek return nStatus;
if (nStatus < 0)
{
// todo
return false;
}
return true;
} }
bool FileStream::Skip(int32_t offset) int32_t FileStream::Skip(int32_t offset)
{ {
return Seek(offset, kSeekCurrent); return Seek(offset, kSeekCurrent);
} }
bool FileStream::Is_Eos()
{
// TODO:
return false;
}
int32_t FileStream::GetPosition() int32_t FileStream::GetPosition()
{ {
return file.Tell(); return file.Tell();

View file

@ -104,38 +104,30 @@ uint8_t FileStream::ReadByte()
return value; return value;
} }
bool FileStream::Seek(int32_t offset, SeekDirection direction) int32_t FileStream::Seek(int32_t offset, SeekDirection direction)
{ {
int32_t nStatus = -1; int32_t nStatus = -1;
if (kSeekStart == direction)
if (kSeekStart == direction) { {
nStatus = klseek(file, offset, SEEK_SET); nStatus = klseek(file, offset, SEEK_SET);
} }
else if (kSeekCurrent == direction) { else if (kSeekCurrent == direction)
{
nStatus = klseek(file, offset, SEEK_CUR); nStatus = klseek(file, offset, SEEK_CUR);
} }
else if (kSeekEnd == direction)
// TODO - end seek
if (nStatus < 0)
{ {
// todo nStatus = klseek(file, offset, SEEK_END);
return false;
} }
return true; return nStatus;
} }
bool FileStream::Skip(int32_t offset) int32_t FileStream::Skip(int32_t offset)
{ {
return Seek(offset, kSeekCurrent); return Seek(offset, kSeekCurrent);
} }
bool FileStream::Is_Eos()
{
// TODO:
return false;
}
int32_t FileStream::GetPosition() int32_t FileStream::GetPosition()
{ {
return ktell(file); return ktell(file);

View file

@ -51,11 +51,10 @@ class FileStream
kSeekEnd = 2 kSeekEnd = 2
}; };
bool Seek(int32_t offset, SeekDirection = kSeekStart); int32_t Seek(int32_t offset, SeekDirection = kSeekStart);
bool Skip(int32_t offset); int32_t Skip(int32_t offset);
int32_t GetPosition(); int32_t GetPosition();
bool Is_Eos();
private: private:
buildvfs_kfd file; buildvfs_kfd file;