Skip to content
Snippets Groups Projects
Commit a0c1d7e8 authored by Andrea Bulgarelli's avatar Andrea Bulgarelli
Browse files

added File::fsize() and a parameter to File::open

parent 2fc79095
No related branches found
No related tags found
No related merge requests found
......@@ -115,6 +115,9 @@ public:
/// Count the number of string lines into a text file.
long getNumberOfStringLines();
/// The dimension of the file
dword fsize();
static dword byte_read;
static dword char_read;
......
......@@ -46,6 +46,8 @@ public:
return 0;
};
virtual dword setpos(dword offset) throw(PacketExceptionIO*);
protected:
File* file;
......
......@@ -36,6 +36,8 @@ public:
virtual void close() throw(PacketExceptionIO*);
///first parameter: filename
///second parameter: fopen modes: w, r, a (optional)
virtual bool open(char** parameters) throw(PacketExceptionIO*);
virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*);
......
......@@ -345,3 +345,18 @@ bool File::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*)
return true;
}
dword File::fsize(){
if(closed)
return 0;
long prev=ftell(fp);
if(prev == -1L)
return 0;
fseek(fp, 0L, SEEK_END);
long sz=ftell(fp);
if(sz == -1L)
return 0;
fseek(fp,prev,SEEK_SET); //go back to where we were
return sz;
}
......@@ -74,3 +74,7 @@ char* InputFile::readString() throw(PacketExceptionIO*)
eof = file->isEOF();
return c;
}
dword InputFile::setpos(dword offset) throw(PacketExceptionIO*) {
return file->setpos(offset);
}
......@@ -44,7 +44,12 @@ void OutputFile::close() throw(PacketExceptionIO*)
bool OutputFile::open(char** parameters) throw(PacketExceptionIO*)
{
if(parameters[1] != 0) {
file->open(parameters[0], parameters[1]);
}
else {
file->open(parameters[0], "w");
}
filename = parameters[0];
isclosed = false;
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment