Added DTSC::File error checking
This commit is contained in:
parent
ca1ec8707a
commit
071cba94f9
2 changed files with 9 additions and 0 deletions
|
@ -575,11 +575,19 @@ DTSC::File & DTSC::File::operator =(const File & rhs){
|
||||||
memcpy(buffer, rhs.buffer, 4);
|
memcpy(buffer, rhs.buffer, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DTSC::File::operator bool() const{
|
||||||
|
return F;
|
||||||
|
}
|
||||||
|
|
||||||
/// Open a filename for DTSC reading/writing.
|
/// Open a filename for DTSC reading/writing.
|
||||||
/// If create is true and file does not exist, attempt to create.
|
/// If create is true and file does not exist, attempt to create.
|
||||||
DTSC::File::File(std::string filename, bool create){
|
DTSC::File::File(std::string filename, bool create){
|
||||||
if (create){
|
if (create){
|
||||||
F = fopen(filename.c_str(), "w+b");
|
F = fopen(filename.c_str(), "w+b");
|
||||||
|
if(!F){
|
||||||
|
std::cerr << "Could not create file" << filename << ": " << strerror(errno) << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
//write an empty header
|
//write an empty header
|
||||||
fseek(F, 0, SEEK_SET);
|
fseek(F, 0, SEEK_SET);
|
||||||
fwrite(DTSC::Magic_Header, 4, 1, F);
|
fwrite(DTSC::Magic_Header, 4, 1, F);
|
||||||
|
|
|
@ -60,6 +60,7 @@ namespace DTSC {
|
||||||
File(const File & rhs);
|
File(const File & rhs);
|
||||||
File(std::string filename, bool create = false);
|
File(std::string filename, bool create = false);
|
||||||
File & operator = (const File & rhs);
|
File & operator = (const File & rhs);
|
||||||
|
operator bool() const;
|
||||||
~File();
|
~File();
|
||||||
JSON::Value & getMeta();
|
JSON::Value & getMeta();
|
||||||
long long int getLastReadPos();
|
long long int getLastReadPos();
|
||||||
|
|
Loading…
Add table
Reference in a new issue