mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 00:06:44 -04:00
more error checking
This commit is contained in:
parent
466704c470
commit
c91586a66f
@ -225,36 +225,38 @@ public:
|
|||||||
INLINE void close(void) {
|
INLINE void close(void) {
|
||||||
if (_fhandle != (PRFileDesc *)NULL) { PR_Close(_fhandle); _fhandle = (PRFileDesc *)NULL; }
|
if (_fhandle != (PRFileDesc *)NULL) { PR_Close(_fhandle); _fhandle = (PRFileDesc *)NULL; }
|
||||||
}
|
}
|
||||||
INLINE bool empty(void){
|
INLINE bool empty(void){ return (PR_Available(_fhandle) <= 0); }
|
||||||
return (PR_Available(_fhandle) <= 0);
|
|
||||||
}
|
INLINE int readin(string &block, int numBytes) {
|
||||||
INLINE int readin(string &block, int numBytes) {
|
|
||||||
//Don't try and read less than nothing
|
//Don't try and read less than nothing
|
||||||
|
if (_fhandle == (PRFileDesc *)NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
nassertr(numBytes >= 0, 0);
|
nassertr(numBytes >= 0, 0);
|
||||||
int numRead;
|
|
||||||
char* temp = new char[numBytes];
|
char* temp = new char[numBytes];
|
||||||
if (_fhandle != (PRFileDesc *)NULL){
|
int numRead = PR_Read(_fhandle, temp, numBytes);
|
||||||
numRead = PR_Read(_fhandle, temp, numBytes);
|
if(numRead<=0) {
|
||||||
if(numRead<=0) {
|
|
||||||
cerr << "PR_Read() in libnspr failed!\n";
|
cerr << "PR_Read() in libnspr failed!\n";
|
||||||
|
delete temp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
block.assign(temp, numRead);
|
block.assign(temp, numRead);
|
||||||
delete temp;
|
delete temp;
|
||||||
return numRead;
|
return numRead;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
INLINE int writeout(const string &block) {
|
INLINE int writeout(const string &block) {
|
||||||
//Make sure there is something to write out
|
nassertr(block.size() > 0, 0); //Make sure there is something to write out
|
||||||
nassertr(block.size() > 0, 0);
|
nassertr(block.data() != NULL, 0);
|
||||||
if (_fhandle != (PRFileDesc *)NULL) {
|
|
||||||
|
if (_fhandle == (PRFileDesc *)NULL)
|
||||||
|
return 0;
|
||||||
return PR_Write(_fhandle, (void*)block.data(), block.size());
|
return PR_Write(_fhandle, (void*)block.data(), block.size());
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
string _filename;
|
private:
|
||||||
|
string _filename;
|
||||||
PRFileDesc* _fhandle;
|
PRFileDesc* _fhandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user