git-svn-id: svn://db.shs.com.ru/pip@236 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -155,22 +155,23 @@ bool PIFile::openDevice() {
|
||||
}
|
||||
}
|
||||
fd = _fopen_call_(p.data(), strType(mode_).data());
|
||||
opened_ = (fd != 0);
|
||||
if (opened_) {
|
||||
bool opened = (fd != 0);
|
||||
if (opened) {
|
||||
fdi = fileno(fd);
|
||||
#ifndef WINDOWS
|
||||
fcntl(fdi, F_SETFL, O_NONBLOCK);
|
||||
#endif
|
||||
seekToBegin();
|
||||
_fseek_call_(fd, 0, SEEK_SET);
|
||||
clearerr(fd);
|
||||
}
|
||||
//piCout << "open file" << fd << opened_;
|
||||
return opened_;
|
||||
return opened;
|
||||
}
|
||||
|
||||
|
||||
bool PIFile::closeDevice() {
|
||||
//piCout << "close file" << fd << opened_;
|
||||
if (!opened_ || fd == 0) return true;
|
||||
if (isClosed() || fd == 0) return true;
|
||||
bool cs = (fclose(fd) == 0);
|
||||
if (cs) fd = 0;
|
||||
fdi = -1;
|
||||
@@ -181,7 +182,7 @@ bool PIFile::closeDevice() {
|
||||
|
||||
PIString PIFile::readLine() {
|
||||
PIByteArray str;
|
||||
if (!opened_) return str;
|
||||
if (isClosed()) return str;
|
||||
int cc;
|
||||
while (!isEnd()) {
|
||||
cc = fgetc(fd);
|
||||
@@ -231,7 +232,7 @@ PIByteArray PIFile::readAll(bool forceRead) {
|
||||
|
||||
|
||||
llong PIFile::size() const {
|
||||
if (!opened_) return -1;
|
||||
if (isClosed()) return -1;
|
||||
llong s, cp = pos();
|
||||
_fseek_call_(fd, 0, SEEK_END); clearerr(fd);
|
||||
s = pos();
|
||||
@@ -298,33 +299,33 @@ PIString PIFile::strType(const PIIODevice::DeviceMode type) {
|
||||
|
||||
|
||||
void PIFile::flush() {
|
||||
if (opened_) fflush(fd);
|
||||
if (isOpened()) fflush(fd);
|
||||
}
|
||||
|
||||
|
||||
void PIFile::seek(llong position) {
|
||||
if (!opened_) return;
|
||||
if (isClosed()) return;
|
||||
_fseek_call_(fd, position, SEEK_SET);
|
||||
clearerr(fd);
|
||||
}
|
||||
|
||||
|
||||
void PIFile::seekToBegin() {
|
||||
if (!opened_) return;
|
||||
if (isClosed()) return;
|
||||
_fseek_call_(fd, 0, SEEK_SET);
|
||||
clearerr(fd);
|
||||
}
|
||||
|
||||
|
||||
void PIFile::seekToEnd() {
|
||||
if (!opened_) return;
|
||||
if (isClosed()) return;
|
||||
_fseek_call_(fd, 0, SEEK_END);
|
||||
clearerr(fd);
|
||||
}
|
||||
|
||||
|
||||
void PIFile::seekToLine(llong line) {
|
||||
if (!opened_) return;
|
||||
if (isClosed()) return;
|
||||
seekToBegin();
|
||||
piForTimes(line) readLine();
|
||||
clearerr(fd);
|
||||
@@ -338,18 +339,18 @@ char PIFile::readChar() {
|
||||
|
||||
void PIFile::setPath(const PIString & path) {
|
||||
PIIODevice::setPath(path);
|
||||
if (opened_) openDevice();
|
||||
if (isOpened()) openDevice();
|
||||
}
|
||||
|
||||
|
||||
llong PIFile::pos() const {
|
||||
if (!opened_) return -1;
|
||||
if (isClosed()) return -1;
|
||||
return _ftell_call_(fd);
|
||||
}
|
||||
|
||||
|
||||
bool PIFile::isEnd() const {
|
||||
if (!opened_) return true;
|
||||
if (isClosed()) return true;
|
||||
return (feof(fd) || ferror(fd));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user