mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
fix VirtualFile::read_file() for text files
This commit is contained in:
parent
3b3937270f
commit
834ff90f7c
@ -74,7 +74,7 @@ read_file(const Filename &file, bool do_uncompress,
|
|||||||
}
|
}
|
||||||
|
|
||||||
off_t file_size = get_file_size(file, in);
|
off_t file_size = get_file_size(file, in);
|
||||||
if (file_size != 0) {
|
if (file_size > 0) {
|
||||||
result.reserve((size_t)file_size);
|
result.reserve((size_t)file_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,17 +127,25 @@ open_read_file(const Filename &file) const {
|
|||||||
// the size.
|
// the size.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
off_t VirtualFileMountSystem::
|
off_t VirtualFileMountSystem::
|
||||||
get_file_size(const Filename &, istream *stream) const {
|
get_file_size(const Filename &file, istream *stream) const {
|
||||||
// First, save the original stream position.
|
// First, save the original stream position.
|
||||||
streampos orig = stream->tellg();
|
streampos orig = stream->tellg();
|
||||||
|
|
||||||
// Seek to the end and get the stream position there.
|
// Seek to the end and get the stream position there.
|
||||||
stream->seekg(0, ios::end);
|
stream->seekg(0, ios::end);
|
||||||
|
if (stream->fail()) {
|
||||||
|
// Seeking not supported.
|
||||||
|
stream->clear();
|
||||||
|
return get_file_size(file);
|
||||||
|
}
|
||||||
streampos size = stream->tellg();
|
streampos size = stream->tellg();
|
||||||
|
|
||||||
// Then return to the original point.
|
// Then return to the original point.
|
||||||
stream->seekg(orig, ios::beg);
|
stream->seekg(orig, ios::beg);
|
||||||
|
|
||||||
|
// Make sure there are no error flags set as a result of the seek.
|
||||||
|
stream->clear();
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user