projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Cyrillic fonts from qMax <qwiglydee@gmail.com>
[supertux.git]
/
src
/
physfs
/
physfs_stream.cpp
diff --git
a/src/physfs/physfs_stream.cpp
b/src/physfs/physfs_stream.cpp
index
acb2670
..
28d92c5
100644
(file)
--- a/
src/physfs/physfs_stream.cpp
+++ b/
src/physfs/physfs_stream.cpp
@@
-28,6
+28,11
@@
IFileStreambuf::IFileStreambuf(const std::string& filename)
{
IFileStreambuf::IFileStreambuf(const std::string& filename)
{
+ // check this as PHYSFS seems to be buggy and still returns a
+ // valid pointer in this case
+ if(filename == "") {
+ throw std::runtime_error("Couldn't open file: empty filename");
+ }
file = PHYSFS_openRead(filename.c_str());
if(file == 0) {
std::stringstream msg;
file = PHYSFS_openRead(filename.c_str());
if(file == 0) {
std::stringstream msg;
@@
-48,8
+53,8
@@
IFileStreambuf::underflow()
if(PHYSFS_eof(file)) {
return traits_type::eof();
}
if(PHYSFS_eof(file)) {
return traits_type::eof();
}
-
- PHYSFS_sint64 bytesread =
(size_t)
PHYSFS_read(file, buf, 1, sizeof(buf));
+
+ PHYSFS_sint64 bytesread = PHYSFS_read(file, buf, 1, sizeof(buf));
if(bytesread <= 0) {
return traits_type::eof();
}
if(bytesread <= 0) {
return traits_type::eof();
}
@@
-76,7
+81,7
@@
IFileStreambuf::seekoff(off_type off, std::ios_base::seekdir dir,
{
off_type pos = off;
PHYSFS_sint64 ptell = PHYSFS_tell(file);
{
off_type pos = off;
PHYSFS_sint64 ptell = PHYSFS_tell(file);
-
+
switch(dir) {
case std::ios_base::beg:
break;
switch(dir) {
case std::ios_base::beg:
break;
@@
-110,7
+115,7
@@
OFileStreambuf::OFileStreambuf(const std::string& filename)
<< PHYSFS_getLastError();
throw std::runtime_error(msg.str());
}
<< PHYSFS_getLastError();
throw std::runtime_error(msg.str());
}
-
+
setp(buf, buf+sizeof(buf));
}
setp(buf, buf+sizeof(buf));
}
@@
-123,6
+128,8
@@
OFileStreambuf::~OFileStreambuf()
int
OFileStreambuf::overflow(int c)
{
int
OFileStreambuf::overflow(int c)
{
+ char c2 = (char)c;
+
if(pbase() == pptr())
return 0;
if(pbase() == pptr())
return 0;
@@
-130,9
+137,9
@@
OFileStreambuf::overflow(int c)
PHYSFS_sint64 res = PHYSFS_write(file, pbase(), 1, size);
if(res <= 0)
return traits_type::eof();
PHYSFS_sint64 res = PHYSFS_write(file, pbase(), 1, size);
if(res <= 0)
return traits_type::eof();
-
+
if(c != traits_type::eof()) {
if(c != traits_type::eof()) {
- PHYSFS_sint64 res = PHYSFS_write(file, &c, 1, 1);
+ PHYSFS_sint64 res = PHYSFS_write(file, &c
2
, 1, 1);
if(res <= 0)
return traits_type::eof();
}
if(res <= 0)
return traits_type::eof();
}
@@
-170,4
+177,3
@@
OFileStream::~OFileStream()
{
delete rdbuf();
}
{
delete rdbuf();
}
-