[Alephmodular-devel] ifstream gotcha...
Status: Pre-Alpha
Brought to you by:
brefin
|
From: Br'fin <br...@ma...> - 2003-02-07 04:28:43
|
So, I've begun trying to work with the file system.
The first real pass at it, I've replaced fileref from portable_files=20
with ifstream* and iostream=95 values. Kind of annoying all the spots=20
that use a local int16 instead of outright using fileref to begin with.
Anyhow, got hit with one gotcha. It also came back to haunt me around=20
the time I was sorting out replay spooling.
static FileError read_from_file(
IFileRef file_id,
int32 offset,
void *data,
int32 length)
{
assert(file_id !=3D NULL);
#if DEBUG
int32 file_length;
file_id->seekg(0l, std::ios::end);
file_length =3D file_id->tellg();
assert(offset+length <=3D file_length);
#endif
file_id->seekg(offset, std::ios::beg);
if (file_id->good())
{
file_id->read(static_cast<char*>(data), length);
=09
// Explictily return noErr because of a quirk where =
performing
// a read on the last n bits of a file that would =
exactly hit the
// eof may very well trigger it. But our read went off =
ok!
file_id->clear();
return noErr;
}
=09
return ((file_id->eof())?errHitFileEOF:!(file_id->good()));
}
And of course there are elements of shapes and sounds which don't even=20=
use portable_files yet.
-Jeremy Parsons=
|