48 #include <QtCore/qdebug.h> 50 #ifndef QT_NO_FSFILEENGINE 52 #if !defined(Q_OS_WINCE) 55 #if defined(Q_OS_UNIX) 56 #include "private/qcore_unix_p.h" 61 # include <private/qcore_mac_p.h> 68 # define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) 71 # define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR) 74 # define S_ISFIFO(x) false 77 # define S_ISSOCK(x) false 79 # ifndef INVALID_FILE_ATTRIBUTES 80 # define INVALID_FILE_ATTRIBUTES (DWORD (-1)) 119 #if !defined(Q_OS_WINCE) 126 #if defined (Q_OS_SYMBIAN) 128 #if !defined(QT_SYMBIAN_USE_NATIVE_FILEMAP) 129 fileHandleForMaps = -1;
176 if (
d->closeFileHandle) {
181 }
while (ret == EOF &&
errno == EINTR);
182 }
else if (
d->fd != -1) {
186 }
while (ret == -1 &&
errno == EINTR);
190 for (
int i = 0; i < keys.
count(); ++i)
210 if (
d->fileEntry.isEmpty()) {
211 qWarning(
"QFSFileEngine::open: No file name specified");
224 d->openMode = openMode;
225 d->lastFlushFailed =
false;
230 return d->nativeOpen(openMode);
262 d->openMode = openMode;
263 d->lastFlushFailed =
false;
265 d->fileEntry.clear();
269 return d->openFh(openMode, fh);
285 ret = QT_FSEEK(fh, 0, SEEK_END);
286 }
while (ret != 0 &&
errno == EINTR);
331 d->openMode = openMode;
332 d->lastFlushFailed =
false;
334 d->fileEntry.clear();
339 return d->openFd(openMode, fd);
357 ret = QT_LSEEK(fd, 0, SEEK_END);
358 }
while (ret == -1 &&
errno == EINTR);
381 return d->nativeClose();
392 && !symbianFile.SubSessionHandle()
393 #ifndef QT_SYMBIAN_USE_NATIVE_FILEMAP 394 && fileHandleForMaps == -1
401 bool flushed = !fh || (!lastFlushFailed && q->flush());
405 #if defined(Q_OS_SYMBIAN) && !defined(QT_SYMBIAN_USE_NATIVE_FILEMAP) 407 if (fileHandleForMaps >= 0) {
409 fileHandleForMaps = -1;
414 if (closeFileHandle) {
418 if (symbianFile.SubSessionHandle()) {
425 ret = fclose(fh) != 0 ? -1 : 0;
430 }
while (ret == -1 &&
errno == EINTR);
440 if (!flushed || !closed) {
462 return d->nativeFlush();
477 int ret = fflush(fh);
479 lastFlushFailed = (ret != 0);
496 return d->nativeSize();
503 qint64 QFSFileEnginePrivate::sizeFdFh()
const 512 return metaData.size();
522 return d->nativePos();
531 return qint64(QT_FTELL(fh));
532 return QT_LSEEK(fd, 0, SEEK_CUR);
541 return d->nativeSeek(pos);
557 if (pos < 0 || pos !=
qint64(QT_OFF_T(pos)))
564 ret = QT_FSEEK(fh, QT_OFF_T(pos), SEEK_SET);
565 }
while (ret != 0 &&
errno == EINTR);
573 if (QT_LSEEK(fd, QT_OFF_T(pos), SEEK_SET) == -1) {
574 qWarning() <<
"QFile::at: Cannot set file position" <<
pos;
588 return d->nativeHandle();
606 return d->nativeRead(data, maxlen);
616 if (len < 0 || len !=
qint64(
size_t(len))) {
630 result = fread(data + readBytes, 1,
size_t(len - readBytes), fh);
632 if (retry && eof && result == 0) {
636 QT_FSEEK(fh, QT_FTELL(fh), SEEK_SET);
641 }
while (!eof && (result == 0 ?
errno == EINTR : readBytes < len));
643 }
else if (fd != -1) {
652 result =
QT_READ(fd, data + readBytes,
size_t(len - readBytes));
653 }
while ((result == -1 &&
errno == EINTR)
654 || (result > 0 && (readBytes += result) < len));
656 eof = !(result == -1);
659 if (!eof && readBytes == 0) {
682 return d->nativeReadLine(data, maxlen);
692 return q->QAbstractFileEngine::readLine(data, maxlen);
696 bool seq = q->isSequential();
699 oldPos = QT_FTELL(fh);
705 if (!fgets(data,
int(maxlen + 1), fh)) {
716 qint64 lineLength = QT_FTELL(fh) - oldPos;
717 return lineLength > 0 ? lineLength :
qstrlen(data);
735 return d->nativeWrite(data, len);
745 if (len < 0 || len !=
qint64(
size_t(len))) {
757 result = fwrite(data + writtenBytes, 1,
size_t(len - writtenBytes), fh);
758 writtenBytes += result;
759 }
while (result == 0 ?
errno == EINTR : writtenBytes < len);
761 }
else if (fd != -1) {
770 result =
QT_WRITE(fd, data + writtenBytes,
size_t(len - writtenBytes));
771 }
while ((result == -1 &&
errno == EINTR)
772 || (result > 0 && (writtenBytes += result) < len));
775 if (len && writtenBytes == 0) {
783 #ifndef QT_NO_FILESYSTEMITERATOR 815 if (
d->is_sequential == 0)
816 d->is_sequential =
d->nativeIsSequential() ? 1 : 2;
817 return d->is_sequential == 1;
824 bool QFSFileEnginePrivate::isSequentialFdFh()
const 827 return metaData.isSequential();
845 return (returnValue->
address != 0);
1021 #endif // QT_NO_FSFILEENGINE
void setError(QFile::FileError error, const QString &str)
Sets the error type to error, and the error string to errorString.
QString qt_error_string(int errorCode)
#define QT_END_NAMESPACE
This macro expands to.
LastIOCommand lastIOCommand
virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const
Requests that a list of all the files matching the filters list based on the filterNames in the file ...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
qint64 writeFdFh(const char *data, qint64 len)
The QString class provides a Unicode character string.
QFile::MemoryMapFlags flags
#define INVALID_FILE_ATTRIBUTES
bool isSequential() const
Reimplemented Function
void setFileName(const QString &file)
Reimplemented Function
QIODevice::OpenMode openMode
bool supportsExtension(Extension extension) const
Reimplemented Function
provides an extended output argument to QAbstractFileEngine's extension support.
bool flush()
Reimplemented Function
QFSFileEngine()
Constructs a QFSFileEngine.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const
Extension
This enum describes the types of extensions that the file engine can support.
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
bool open(QIODevice::OpenMode openMode)
Reimplemented Function
provides an extended input argument to QAbstractFileEngine's extension support.
Q_CORE_EXPORT void qWarning(const char *,...)
The QAbstractFileEngine class provides an abstraction for accessing the filesystem.
bool seek(qint64)
Reimplemented Function
static const char * data(const QByteArray &arr)
bool openFd(QIODevice::OpenMode flags, int fd)
Opens the file descriptor fd to the file engine, using the open mode flags.
qint64 pos() const
Reimplemented Function
bool unmap(uchar *ptr)
Unmaps the memory address.
Iterator * endEntryList()
Iterator * beginEntryList(QDir::Filters filters, const QStringList &filterNames)
qint64 size() const
Reimplemented Function
qint64 readLine(char *data, qint64 maxlen)
Reimplemented Function
qint64 read(char *data, qint64 maxlen)
Reimplemented Function
static const char *const filters[3]
uint qstrlen(const char *str)
qint64 write(const char *data, qint64 len)
Reimplemented Function
int handle() const
Reimplemented Function
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines...
qint64 readLineFdFh(char *data, qint64 maxlen)
~QFSFileEngine()
Destructs the QFSFileEngine.
bool openFh(QIODevice::OpenMode flags, FILE *fh)
Opens the file handle fh using the open mode flags.
bool extension(Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0)
Reimplemented Function
bool close()
Reimplemented Function
The QList class is a template class that provides lists.
qint64 readFdFh(char *data, qint64 maxlen)
The QFSFileEngine class implements Qt's default file engine.