?? qfsfileengine.cpp
字號:
return flushed && closed; } if (d->fd == -1) return false; int ret; if (d->closeFileHandle) { do { ret = QT_CLOSE(d->fd); } while (ret == -1 && errno == EINTR); } else { ret = 0; } d->fd = -1; if (ret == -1) { setError(QFile::UnspecifiedError, qt_error_string(errno)); return false; } return true;}/*! \reimp*/bool QFSFileEngine::flush(){ Q_D(QFSFileEngine);#ifdef Q_OS_UNIX if (d->is_readonly) return true;#endif d->ungetchBuffer.clear(); if (d->lastFlushFailed) return false; if (!d->fh) { // There's no write buffer when using an fd. return d->fd != -1; }#ifdef Q_OS_WIN QT_FPOS_T pos; int gotPos = QT_FGETPOS(d->fh, &pos);#endif int ret = fflush(d->fh); d->lastFlushFailed = (ret != 0);#ifdef Q_OS_WIN if (gotPos == 0) { int ret; do { ret = QT_FSETPOS(d->fh, &pos); } while (ret == -1 && errno == EINTR); }#endif d->lastIOCommand = QFSFileEnginePrivate::IOFlushCommand; if (ret != 0) { setError(errno == ENOSPC ? QFile::ResourceError : QFile::WriteError, qt_error_string(errno)); return false; } return true;}/*! \reimp*/qint64 QFSFileEngine::read(char *data, qint64 len){ Q_D(QFSFileEngine); if (d->fh) { if (d->lastIOCommand != QFSFileEnginePrivate::IOReadCommand) { flush(); d->lastIOCommand = QFSFileEnginePrivate::IOReadCommand; } if (feof(d->fh)) return 0; size_t readBytes = 0;#ifdef Q_OS_UNIX if (d->sequential) { int oldFlags = fcntl(fileno(d->fh), F_GETFL); for (int i = 0; i < 2; ++i) { // Make the underlying file descriptor non-blocking int v = 1; if ((oldFlags & O_NONBLOCK) == 0) fcntl(fileno(d->fh), F_SETFL, oldFlags | O_NONBLOCK, &v, sizeof(v)); size_t read = 0; do { read = fread(data + readBytes, 1, size_t(len - readBytes), d->fh); } while (read == 0 && !feof(d->fh) && errno == EINTR); if (read > 0) { readBytes += read; break; } else { if (readBytes) break; readBytes = read; } // Restore the blocking state of the underlying socket if ((oldFlags & O_NONBLOCK) == 0) { int v = 1; fcntl(fileno(d->fh), F_SETFL, oldFlags, &v, sizeof(v)); if (readBytes == 0) { int readByte = 0; do { readByte = fgetc(d->fh); } while (readByte == -1 && errno == EINTR); if (readByte != -1) { *data = uchar(readByte); readBytes += 1; } else { break; } } } } if ((oldFlags & O_NONBLOCK) == 0) { int v = 1; fcntl(fileno(d->fh), F_SETFL, oldFlags, &v, sizeof(v)); } } else#endif do { readBytes = fread(data, 1, size_t(len), d->fh); } while (readBytes == 0 && !feof(d->fh) && errno == EINTR); qint64 ret = qint64(readBytes); if (ret == 0) { setError(QFile::ReadError, qt_error_string(int(errno))); if (!feof(d->fh)) ret = -1; } return ret; } qint64 ret = 0; if (!d->ungetchBuffer.isEmpty()) { qint64 l = d->ungetchBuffer.size(); while(ret < l) { *data = d->ungetchBuffer.at(l - ret - 1); data++; ret++; } d->ungetchBuffer.resize(l - ret); len -= ret; } if(len && ret != len) { int result; qint64 read = 0; do { qint64 bytesToRead = len - read;#ifdef Q_OS_WIN // Reading on Windows fails with ERROR_NO_SYSTEM_RESOURCES // when the chunks are too large, so we limit the block // size to 32MB. const qint64 MaxBlockSize = 32 * 1024 * 1024; bytesToRead = qMin(bytesToRead, MaxBlockSize);#endif do { result = QT_READ(d->fd, data + read, int(bytesToRead)); } while (result == -1 && errno == EINTR); if (result > 0) read += result; } while (result > 0 && read < len); if (read > 0) { ret += read; } else { if (!ret) ret = -1; setError(QFile::ReadError, qt_error_string(errno)); } } return ret;}/*! \reimp*/qint64 QFSFileEngine::readLine(char *data, qint64 maxlen){ Q_D(QFSFileEngine); if (!d->fh) return QAbstractFileEngine::readLine(data, maxlen); if (d->lastIOCommand != QFSFileEnginePrivate::IOReadCommand) { flush(); d->lastIOCommand = QFSFileEnginePrivate::IOReadCommand; } if (feof(d->fh)) return 0; // QIODevice::readLine() passes maxlen - 1 to QFile::readLineData() // because it has made space for the '\0' at the end of data. But fgets // does the same, so we'd get two '\0' at the end - passing maxlen + 1 // solves this. if (!fgets(data, int(maxlen + 1), d->fh)) { setError(QFile::ReadError, qt_error_string(int(errno))); return 0; } return qstrlen(data);}/*! \reimp*/qint64 QFSFileEngine::write(const char *data, qint64 len){ Q_D(QFSFileEngine); if (d->fh) { if (d->lastIOCommand != QFSFileEnginePrivate::IOWriteCommand) { flush(); d->lastIOCommand = QFSFileEnginePrivate::IOWriteCommand; } } qint64 result; qint64 written = 0;#ifdef Q_OS_WIN qint64 posbefore; if (!d->sequential) { posbefore = pos(); if (posbefore == -1) { setError(QFile::WriteError, qt_error_string(errno)); return qint64(-1); } }#endif do { qint64 bytesToWrite = len - written;#ifdef Q_OS_WIN // Writing on Windows fails with ERROR_NO_SYSTEM_RESOURCES // when the chunks are too large, so we limit the block size // to 32MB. const qint64 MaxChunkSize = 32 * 1024 * 1024; bytesToWrite = qMin<qint64>(bytesToWrite, MaxChunkSize);#endif if (d->fh) { do { result = qint64(fwrite(data + written, 1, size_t(bytesToWrite), d->fh)); } while (result == 0 && errno == EINTR); if (bytesToWrite > 0 && result == 0) result = -1; } else { do { result = QT_WRITE(d->fd, data + written, bytesToWrite); } while (result == -1 && errno == EINTR); } if (result > 0) written += qint64(result); } while (written < len && ((result > 0 || (result == 0 && errno == EINTR))));#ifdef Q_OS_WIN if (!d->sequential) { qint64 currentpos = pos(); if (currentpos == -1) { result = -1; } else { written = currentpos - posbefore; } }#endif if (result > 0) return written; setError(errno == ENOSPC ? QFile::ResourceError : QFile::WriteError, qt_error_string(errno)); return qint64(result);}/*! \reimp*/qint64 QFSFileEngine::pos() const{ Q_D(const QFSFileEngine); if (d->fh) return qint64(QT_FTELL(d->fh)); return QT_LSEEK(d->fd, 0, SEEK_CUR);}/*! \reimp*/int QFSFileEngine::handle() const{ Q_D(const QFSFileEngine); return d->fd;}/*! \internal*/QAbstractFileEngine::Iterator *QFSFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames){ Q_UNUSED(filters); Q_UNUSED(filterNames); return 0;}/*! \internal*/QAbstractFileEngine::Iterator *QFSFileEngine::endEntryList(){ return 0;}/*! \reimp*/bool QFSFileEngine::seek(qint64 pos){ Q_D(QFSFileEngine); if (d->lastIOCommand != QFSFileEnginePrivate::IOFlushCommand && !flush()) return false; if (d->fh) { int ret; do { ret = QT_FSEEK(d->fh, QT_OFF_T(pos), SEEK_SET); } while (ret == -1 && errno == EINTR); if (ret == -1) { setError(QFile::ReadError, qt_error_string(int(errno))); return false; } return true; } if(QT_LSEEK(d->fd, pos, SEEK_SET) == -1) { qWarning("QFile::at: Cannot set file position %lld", pos); setError(QFile::PositionError, qt_error_string(errno)); return false; } d->ungetchBuffer.clear(); return true;}/*! \reimp*/bool QFSFileEngine::isSequential() const{ Q_D(const QFSFileEngine); return d->sequential;}/*! \reimp*/bool QFSFileEngine::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output){ Q_UNUSED(extension); Q_UNUSED(option); Q_UNUSED(output); return false;}/*! \reimp*/bool QFSFileEngine::supportsExtension(Extension extension) const{ Q_UNUSED(extension); return false;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -