TimerPool fixoutManipulator
git-svn-id: svn://db.shs.com.ru/pip@72 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -110,11 +110,13 @@ PIString PIFile::FileInfo::dir() const {
|
||||
|
||||
|
||||
PIFile::PIFile(): PIIODevice() {
|
||||
fdi = -1;
|
||||
setPrecision(5);
|
||||
}
|
||||
|
||||
|
||||
PIFile::PIFile(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(path, mode) {
|
||||
fdi = -1;
|
||||
setPrecision(5);
|
||||
if (!path.isEmpty())
|
||||
openDevice();
|
||||
@@ -122,6 +124,7 @@ PIFile::PIFile(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(p
|
||||
|
||||
|
||||
PIFile::PIFile(const PIFile & other) {
|
||||
fdi = -1;
|
||||
setPrecision(other.prec_);
|
||||
setPath(other.path());
|
||||
mode_ = other.mode_;
|
||||
@@ -139,12 +142,15 @@ bool PIFile::openDevice() {
|
||||
if (fd != 0) fclose(fd);
|
||||
}
|
||||
}
|
||||
fd = fopen(p.data(), strType(mode_).data());
|
||||
fd = fopen64(p.data(), strType(mode_).data());
|
||||
opened_ = (fd != 0);
|
||||
if (opened_) {
|
||||
fdi = fileno(fd);
|
||||
#ifndef WINDOWS
|
||||
if (opened_) fcntl(fileno(fd), F_SETFL, O_NONBLOCK);
|
||||
fcntl(fdi, F_SETFL, O_NONBLOCK);
|
||||
#endif
|
||||
seekToBegin();
|
||||
}
|
||||
//piCout << "open file" << fd << opened_;
|
||||
return opened_;
|
||||
}
|
||||
@@ -155,6 +161,7 @@ bool PIFile::closeDevice() {
|
||||
if (!opened_ || fd == 0) return true;
|
||||
bool cs = (fclose(fd) == 0);
|
||||
if (cs) fd = 0;
|
||||
fdi = -1;
|
||||
//piCout << "closed file" << fd << opened_;
|
||||
return cs;
|
||||
}
|
||||
@@ -210,9 +217,9 @@ PIByteArray PIFile::readAll(bool forceRead) {
|
||||
llong PIFile::size() const {
|
||||
if (!opened_) return -1;
|
||||
llong s, cp = pos();
|
||||
fseek(fd, 0, SEEK_END); clearerr(fd);
|
||||
lseek64(fdi, 0, SEEK_END); clearerr(fd);
|
||||
s = pos();
|
||||
fseek(fd, cp, SEEK_SET); clearerr(fd);
|
||||
lseek64(fdi, cp, SEEK_SET); clearerr(fd);
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -237,7 +244,7 @@ void PIFile::resize(llong new_size, uchar fill_) {
|
||||
|
||||
|
||||
bool PIFile::isExists(const PIString & path) {
|
||||
FILE * f = fopen(PIString(path).data(), "r");
|
||||
FILE * f = fopen64(PIString(path).data(), "r");
|
||||
bool ok = (f != 0);
|
||||
if (ok) fclose(f);
|
||||
return ok;
|
||||
@@ -264,6 +271,109 @@ PIString PIFile::strType(const PIIODevice::DeviceMode type) {
|
||||
}
|
||||
|
||||
|
||||
void PIFile::flush() {
|
||||
if (opened_) fflush(fd);
|
||||
}
|
||||
|
||||
|
||||
void PIFile::seek(llong position) {
|
||||
if (!opened_) return;
|
||||
lseek64(fdi, position, SEEK_SET);
|
||||
clearerr(fd);
|
||||
}
|
||||
|
||||
|
||||
void PIFile::seekToBegin() {
|
||||
if (!opened_) return;
|
||||
lseek64(fdi, 0, SEEK_SET);
|
||||
clearerr(fd);
|
||||
}
|
||||
|
||||
|
||||
void PIFile::seekToEnd() {
|
||||
if (!opened_) return;
|
||||
lseek64(fdi, 0, SEEK_END);
|
||||
clearerr(fd);
|
||||
}
|
||||
|
||||
|
||||
void PIFile::seekToLine(llong line) {
|
||||
if (!opened_) return;
|
||||
seekToBegin();
|
||||
piForTimes(line) readLine();
|
||||
clearerr(fd);
|
||||
}
|
||||
|
||||
|
||||
char PIFile::readChar() {
|
||||
return (char)fgetc(fd);
|
||||
}
|
||||
|
||||
|
||||
void PIFile::setPath(const PIString & path) {
|
||||
PIIODevice::setPath(path);
|
||||
if (opened_) openDevice();
|
||||
}
|
||||
|
||||
|
||||
llong PIFile::pos() const {
|
||||
if (!opened_) return -1;
|
||||
return ftell(fd);
|
||||
}
|
||||
|
||||
|
||||
bool PIFile::isEnd() const {
|
||||
if (!opened_) return true;
|
||||
return (feof(fd) || ferror(fd));
|
||||
}
|
||||
|
||||
|
||||
void PIFile::setPrecision(int prec) {
|
||||
prec_ = prec;
|
||||
if (prec_ >= 0) prec_str = "." + PIString::fromNumber(prec_);
|
||||
else prec_str = "";
|
||||
}
|
||||
|
||||
|
||||
int PIFile::read(void * read_to, int max_size) {
|
||||
if (!canRead() || fd == 0) return -1;
|
||||
return fread(read_to, 1, max_size, fd);
|
||||
}
|
||||
|
||||
|
||||
int PIFile::write(const void * data, int max_size) {
|
||||
if (!canWrite() || fd == 0) return -1;
|
||||
return fwrite(data, 1, max_size, fd);
|
||||
}
|
||||
|
||||
|
||||
PIFile & PIFile::writeToBinLog(ushort id, const void * data, int size) {
|
||||
if (!isWriteable() || fd == 0) return *this;
|
||||
writeBinary(id).writeBinary((ushort)size);
|
||||
write(data, size);
|
||||
flush();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void PIFile::clear() {
|
||||
close();
|
||||
fd = fopen(path().data(), "w");
|
||||
if (fd != 0) fclose(fd);
|
||||
fd = 0;
|
||||
opened_ = false;
|
||||
open();
|
||||
}
|
||||
|
||||
|
||||
void PIFile::remove() {
|
||||
close();
|
||||
std::remove(path().data());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
|
||||
FileInfo ret;
|
||||
if (path.isEmpty()) return ret;
|
||||
|
||||
Reference in New Issue
Block a user