PIFile::skip() method and PIFile::isEnd() fix for read-only
This commit is contained in:
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0)
|
||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||
project(pip)
|
||||
set(pip_MAJOR 2)
|
||||
set(pip_MINOR 24)
|
||||
set(pip_REVISION 1)
|
||||
set(pip_MINOR 25)
|
||||
set(pip_REVISION 0)
|
||||
set(pip_SUFFIX )
|
||||
set(pip_COMPANY SHS)
|
||||
set(pip_DOMAIN org.SHS)
|
||||
|
||||
@@ -136,16 +136,12 @@ PIString PIFile::FileInfo::dir() const {
|
||||
|
||||
|
||||
PIFile::PIFile(): PIIODevice() {
|
||||
PRIVATE->fd = 0;
|
||||
fdi = -1;
|
||||
setPrecision(5);
|
||||
_init();
|
||||
}
|
||||
|
||||
|
||||
PIFile::PIFile(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(path, mode) {
|
||||
PRIVATE->fd = 0;
|
||||
fdi = -1;
|
||||
setPrecision(5);
|
||||
_init();
|
||||
if (!path.isEmpty())
|
||||
open();
|
||||
}
|
||||
@@ -180,6 +176,10 @@ bool PIFile::openDevice() {
|
||||
#ifndef WINDOWS
|
||||
fcntl(fdi, F_SETFL, O_NONBLOCK);
|
||||
#endif
|
||||
if (mode_ == PIIODevice::ReadOnly) {
|
||||
_fseek_call_(PRIVATE->fd, 0, SEEK_END);
|
||||
_size = _ftell_call_(PRIVATE->fd);
|
||||
}
|
||||
_fseek_call_(PRIVATE->fd, 0, SEEK_SET);
|
||||
clearerr(PRIVATE->fd);
|
||||
}
|
||||
@@ -194,6 +194,7 @@ bool PIFile::closeDevice() {
|
||||
bool cs = (fclose(PRIVATE->fd) == 0);
|
||||
if (cs) PRIVATE->fd = 0;
|
||||
fdi = -1;
|
||||
_size = -1;
|
||||
//piCout << "closed file" << PRIVATE->fd << opened_;
|
||||
return cs;
|
||||
}
|
||||
@@ -337,6 +338,14 @@ PIString PIFile::strType(const PIIODevice::DeviceMode type) {
|
||||
}
|
||||
|
||||
|
||||
void PIFile::_init() {
|
||||
PRIVATE->fd = 0;
|
||||
fdi = -1;
|
||||
_size = -1;
|
||||
setPrecision(5);
|
||||
}
|
||||
|
||||
|
||||
void PIFile::flush() {
|
||||
if (isOpened()) fflush(PRIVATE->fd);
|
||||
}
|
||||
@@ -372,6 +381,12 @@ void PIFile::seekToLine(llong line) {
|
||||
}
|
||||
|
||||
|
||||
void PIFile::skip(llong bytes) {
|
||||
if (isClosed() || (bytes == 0)) return;
|
||||
_fseek_call_(PRIVATE->fd, bytes, SEEK_CUR);
|
||||
}
|
||||
|
||||
|
||||
char PIFile::readChar() {
|
||||
return (char)fgetc(PRIVATE->fd);
|
||||
}
|
||||
@@ -391,7 +406,12 @@ llong PIFile::pos() const {
|
||||
|
||||
bool PIFile::isEnd() const {
|
||||
if (isClosed()) return true;
|
||||
return (feof(PRIVATE->fd) || ferror(PRIVATE->fd));
|
||||
bool ret = (feof(PRIVATE->fd) || ferror(PRIVATE->fd));
|
||||
if (!ret && (_size >= 0)) {
|
||||
if (pos() > _size)
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -107,6 +107,9 @@ public:
|
||||
|
||||
//! Move read/write position to text line number "line"
|
||||
void seekToLine(llong line);
|
||||
|
||||
//! Skip "bytes" bytes (move position next to "bytes" bytes)
|
||||
void skip(llong bytes);
|
||||
|
||||
//! Read one char and return it
|
||||
char readChar();
|
||||
@@ -295,9 +298,11 @@ protected:
|
||||
|
||||
private:
|
||||
PIString strType(const PIIODevice::DeviceMode type);
|
||||
void _init();
|
||||
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
int ret, prec_, fdi;
|
||||
llong _size;
|
||||
PIString prec_str;
|
||||
|
||||
};
|
||||
|
||||
@@ -358,10 +358,6 @@ void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
.removeAll(' ')
|
||||
.toUpperCase()
|
||||
+ "_H";
|
||||
bool inc_h, inc_cpp;
|
||||
inc_h = streams || texts;
|
||||
inc_cpp = !inc_h && getters;
|
||||
|
||||
PISet<PIString> inc_files;
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities)
|
||||
if (e->name.find("::") < 0 && !e->name.startsWith("_PI"))
|
||||
|
||||
Reference in New Issue
Block a user