05.11.2011 - stable version, 0.1.0, self-test program, work at GCC 2.95 - 4.5, VC 2010, MinGW, Linux, Windows, QNX
This commit is contained in:
27
pifile.cpp
27
pifile.cpp
@@ -23,18 +23,32 @@ PIString PIFile::readLine() {
|
||||
|
||||
|
||||
llong PIFile::readAll(void * data) {
|
||||
llong cp = pos(), s = size();
|
||||
llong cp = pos(), s = size(), i = -1;
|
||||
stream.seekg(0);
|
||||
stream.read((char * )data, s);
|
||||
if (s < 0) {
|
||||
while (!stream.eof())
|
||||
stream.read(&(((char*)data)[++i]), 1);
|
||||
} else
|
||||
stream.read((char * )data, s);
|
||||
seek(cp);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIFile::readAll() {
|
||||
llong s = size();
|
||||
if (s < 0) return PIByteArray();
|
||||
PIByteArray a(s);
|
||||
PIByteArray PIFile::readAll(bool forceRead) {
|
||||
llong cp = pos(), s = size();
|
||||
char c;
|
||||
PIByteArray a;
|
||||
if (s < 0) {
|
||||
if (!forceRead) return a;
|
||||
while (!stream.eof()) {
|
||||
stream.read(&c, 1);
|
||||
a.push_back(c);
|
||||
}
|
||||
seek(cp);
|
||||
return a;
|
||||
}
|
||||
a.resize(s);
|
||||
s = readAll(a.data());
|
||||
if (s >= 0) a.resize(s);
|
||||
return a;
|
||||
@@ -47,6 +61,7 @@ llong PIFile::size() {
|
||||
stream.seekg(0, fstream::end);
|
||||
s = stream.tellg();
|
||||
stream.seekg(cp, fstream::beg);
|
||||
stream.clear();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user